feat: add shell completions (bash, zsh, fish) that stay in sync with the installed CLI - #86626
Open
5hal1n wants to merge 1 commit into
Open
feat: add shell completions (bash, zsh, fish) that stay in sync with the installed CLI#866265hal1n wants to merge 1 commit into
5hal1n wants to merge 1 commit into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds tab-completion scripts for the
claudeCLI undercompletions/:completions/claude.bash— bash (works with stock macOS bash 3.2, no bash-completion package required)completions/_claude— zshcompletions/claude.fish— fishcompletions/README.md— install instructionsWhy 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 --helpoutput 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
claude <TAB>,claude mcp <TAB>,claude plugin marketplace <TAB>)claude --<TAB>,claude mcp add --<TAB>)--model,--permission-mode,--output-format,--input-format,--effort,--scope,--transport,--setting-sources)--add-dir,--plugin-dir,--settings,--mcp-config,--debug-file)claude install <TAB>→ stable/latest,claude import <TAB>→ codex/gemini)Safety
The scripts only ever execute
claude --help,claude -v, andclaude <subcommand...> --help, and a word typed on the command line is only passed toclaudeif 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:
COMP_WORDS/COMP_CWORDfor subcommands, nested subcommands, flags, enum values, and positionals — all correct_claudeacross the same matrixcomplete -Cend-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