Skip to content

feat: add shell completions (bash, zsh, fish) that stay in sync with the installed CLI - #86626

Open
5hal1n wants to merge 1 commit into
anthropics:mainfrom
5hal1n:feat/shell-completions
Open

feat: add shell completions (bash, zsh, fish) that stay in sync with the installed CLI#86626
5hal1n wants to merge 1 commit into
anthropics:mainfrom
5hal1n:feat/shell-completions

Conversation

@5hal1n

@5hal1n 5hal1n commented Aug 14, 2026

Copy link
Copy Markdown

Summary

Adds tab-completion scripts for the claude CLI under completions/:

  • completions/claude.bash — bash (works with stock macOS bash 3.2, no bash-completion package required)
  • completions/_claude — zsh
  • completions/claude.fish — fish
  • completions/README.md — install instructions

Why another completions PR?

#4943 proposed static completion scripts, and the main concern raised in its discussion is that hard-coded flag/subcommand lists go stale on every release (the CLI has gained import, auto-mode, auth, ultrareview, and many flags since that PR was opened).

These scripts take a different approach: they parse claude --help output at completion time, so completions always match the installed version of Claude Code — including nested subcommands (claude mcp add, claude plugin marketplace, ...) — with zero maintenance as the CLI evolves. Parsed help output is cached per CLI version (claude -v) under ${XDG_CACHE_HOME:-~/.cache}/claude-code-completions/, so after the first tab press completions are instant, and upgrading the CLI automatically refreshes them.

Related: #57871, #7738.

What you get

  • Subcommand completion with descriptions (claude <TAB>, claude mcp <TAB>, claude plugin marketplace <TAB>)
  • Flag completion with descriptions (claude --<TAB>, claude mcp add --<TAB>)
  • Value completion for enum flags (--model, --permission-mode, --output-format, --input-format, --effort, --scope, --transport, --setting-sources)
  • Directory/file completion for path flags (--add-dir, --plugin-dir, --settings, --mcp-config, --debug-file)
  • Positional value completion (claude install <TAB> → stable/latest, claude import <TAB> → codex/gemini)

Safety

The scripts only ever execute claude --help, claude -v, and claude <subcommand...> --help, and a word typed on the command line is only passed to claude if a previous help output listed it as a subcommand — arbitrary typed words are never executed.

Testing

Verified against Claude Code 2.1.232 on macOS:

  • bash 3.2.57 (stock macOS): simulated COMP_WORDS/COMP_CWORD for subcommands, nested subcommands, flags, enum values, and positionals — all correct
  • zsh 5.9: exercised _claude across the same matrix
  • fish 4.8.1: complete -C end-to-end via the standard autoload path (~/.config/fish/completions/claude.fish), which also shadows the stale static claude completions bundled with recent fish releases

🤖 Generated with Claude Code

https://claude.ai/code/session_01TzRhqVbAX9BETj2juu8U4X

Add tab-completion scripts for the claude CLI under completions/.
Rather than hard-coding flag and subcommand lists, the scripts parse
`claude --help` output at completion time (cached per CLI version),
so completions stay in sync with the installed version of Claude Code,
including nested subcommands like `claude mcp add` and
`claude plugin marketplace`.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TzRhqVbAX9BETj2juu8U4X
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant