{"slug": "zsh-help-complete-tab-complete-any-cli-s-options-from-its-help", "title": "Zsh-help-complete – Tab-complete any CLI's options from its –help", "summary": "A new zsh plugin called zsh-help-complete adds Tab completion for command-line options to any CLI tool that lacks its own completion definition, by running the tool's `--help` output and suggesting the listed options. Because `--help` is only a convention, the plugin by default prompts before running any program for the first time, re-prompts when the file's mtime, size or inode change (flagged `CHANGED`), reads the first 256 KB of scripts to confirm they handle `--help` or pass arguments through, and never runs a denylist including `rm`, `dd`, `mkfs`, `shred`, `shutdown`, `reboot`, `kill` and `fdisk`. It closes stdin and enforces a 5-second timeout, tries only `--help` by default (not `-h` or `-help`), and offers an optional sandbox via `zstyle ':zhc:*' sandbox yes`.", "body_md": "Tab completion of options for **every** command that has no completion\ndefinition of its own. Pressing Tab on a word starting with `-` reads the\ncommand's help output and suggests its options; if there are no\nsuggestions, zsh falls back to its normal behavior (file/directory completion).\n\nWarning\n\n**To read a command's options, this plugin runs the command** (`tool --help`,\n`tool sub --help`). `--help` is a convention, not a guarantee: a program that\ndoesn't handle it may do its normal job instead. By default the plugin\n**asks you before running any program for the first time**, and again if the\nprogram changed since you allowed it. Read [Safety](#safety) before turning\nthat off.\n\n``` bash\n$ claude --sys<Tab>\n--system-prompt   --system-prompt-snapshot\n$ ./script.py --verb<Tab>\n$ ./script.py --verbose\n```\n\nWorks for commands in `PATH`, for executables given by path (`./script.py`)\nand through aliases, and for subcommands: `tool sub --<Tab>` reads\n`tool sub --help`.\n\n``` bash\n$ claude mcp add --tra<Tab>\n$ claude mcp add --transport\n```\n\nSubcommand names and option values are completed too:\n\n``` bash\n$ mytool <Tab>\nbuild   -- Compile the project\ndeploy  -- Deploy it\n$ mytool deploy --env <Tab>\nproduction  staging\n```\n\n- **Scripts that don't parse their arguments.**`./cleanup.sh --<Tab>` runs`cleanup.sh --help` . A script that never looks at its arguments ignores`--help` and** does its job** . Many small shell scripts are like that.\n- **Scripts that dispatch subcommands by hand.** A`manage.sh` with`case \"$1\" in deploy) ...` that lists`deploy` in its usage text would run**`manage.sh deploy`** for`./manage.sh deploy --<Tab>` , if it ignores`--help` .\n- **Short help flags.**`-h` isn't \"help\" everywhere (host, human-readable,\nhalt), and`-help` may be read as`-h -e -l -p` .\n- **Untrusted directories.** In a fresh clone or a downloads folder,`./x --<Tab>` runs code you haven't read.\n- **Side effects of `--help` itself.** Some tools create config files, check\nfor updates or make network requests before printing help.\n\n- \n**It asks first (default).** The first time a program would be run, the\nplugin asks below the command line:\n\n```\nzsh-help-complete: run \"mytool --help\" (/usr/local/bin/mytool) to read its options?  [y]es  [o]nce  [n]ot now  ne[v]er\n```\n\n `y` allows it from now on,`o` for this shell only,`v` never.`n` or any\nother key (including a second Tab pressed out of habit) runs nothing and\ndoesn't ask again in this shell. The full path is shown so you can see\nwhich file would run. An answer covers the program and its subcommands.\n- \n**It asks again when the program changed.** An answer is kept together with\nthe file's mtime, size and inode. If the file changed since you allowed it\n(an update, or someone replaced it), you are asked again and the question\nsays`CHANGED` .\n- \n**It checks scripts before running them.** The first 256 KB of the file\nis read:\n  - Shell scripts are run only if they show signs of handling `--help` (`--help` ,`usage` ,`getopts` ) or just pass their arguments on\n(`exec ... \"$@\"` ). Their subcommands are never run:`manage.sh deploy --` uses`manage.sh --help` .\n  - Scripts given by path (`./x` ) in other languages need an argument parser\n(`argparse` ,`click` ,`typer` ,`docopt` ,`commander` ,`yargs` , ...) or\nsigns of handling`--help` .\n  - Compiled programs and installed (`PATH` ) scripts in other languages are\nrun as before.\n- Shell scripts are run only if they show signs of handling \n- \n**Only `--help` by default.**`-h` ,`-hh` ,`-help` are tried only for\ncommands you configure (see[Settings](#settings) ).\n- \n**A denylist.**`rm` ,`dd` ,`mkfs` ,`shred` ,`shutdown` ,`reboot` ,`kill` ,`fdisk` and similar are never run. Entries may name a subcommand:`'mytool deploy'` .\n- \n**stdin is closed and there's a timeout** (5 s), so a program can't wait for\ninput or freeze the shell. A timeout doesn't undo anything a program\nalready did, though.\n- \n**An optional sandbox.** With`zstyle ':zhc:*' sandbox yes` the help call\nruns read-only and without network: under[bubblewrap](https://github.com/containers/bubblewrap) (`bwrap` ) on Linux,`sandbox-exec` on macOS. If neither is available, nothing is run.\n- \n**Help is run once per program version.** The output is cached; nothing is\nrun on later Tabs until the program changes.\n\n```\nzhc allow mytool ./build.sh   # allow without being asked\nzhc deny  sometool            # never run it\nzhc forget mytool             # ask again next time\nzhc list                      # show the answers\nzhc clear-cache               # remove the cached help output\n```\n\nAnswers are kept in `~/.config/zsh-help-complete/decisions`\n(`$XDG_CONFIG_HOME` is respected).\n\nOnly words starting with `-` ask. Subcommand names and option values\n(`tool <Tab>`, `tool --env <Tab>`) use the help only of programs you\nallowed before; for any other program, Tab just completes files as usual,\nwithout asking or running anything.\n\nIf you trust everything you complete, `zstyle ':zhc:*' ask no` turns the\nquestion off. Then the script check, denylist, timeout and `--help`-only\ndefault are the only protection, so consider also\n`zstyle ':zhc:*' allow-paths no`, which runs only commands found in `PATH`.\n\nzsh's built-in `_gnu_generic` runs `--help` too, but:\n\n- When `--help` output contains bracketed lines such as`--system-prompt[-file],` , it fails completely with`_arguments:comparguments:327: invalid option definition` , or such a line\nsilently swallows the real option of the same name (`--system-prompt` ).\nThis plugin removes those lines from the help text before it is parsed,\nwhile keeping GNU style optional values like`--color[=WHEN]` .\n- A command that doesn't understand `--help` and hangs will freeze the shell.\nHere`--help` runs with a timeout and with stdin closed (needs GNU`timeout` ; on macOS run`brew install coreutils` to get`gtimeout` ).\n- It never asks, and it has no denylist or script check.\n\nA word right after the command (up to three levels: `tool run fast --`) is\ntreated as a subcommand when the command's help output lists it at the start\nof an indented line, as in\n\n```\nCommands:\n  build    Compile the project\n  run, r   Run it\n```\n\nThen `tool build --<Tab>` completes the options of `tool build --help`. Other\nwords (`mv file.txt --`) are ordinary arguments and the command's own help is\nused. Each subcommand has its own cache. Words after an option\n(`tool --verbose build --`) are not checked for subcommands. Shell scripts'\nsubcommands are never run (see [Safety](#safety)).\n\n`tool <Tab>` lists the subcommands from the help output, with their\ndescriptions, followed by files. Sections like `Commands:`,\n`Available Commands:` (Go/cobra), `Commands:` with `update|upgrade` aliases\n(Node/commander) and argparse's `{serve,build}` are read; wrapped description\nlines are not mistaken for names. This needs the program to be allowed\nalready (see [Safety](#safety)).\n\nOptions that take a value are recognized in the forms `--tag TAG`,\n`--tag=TAG`, `--env {a,b}`, `--color <WHEN>` and `--name string` (Go), so\n`tool --tag v1 --<Tab>` skips the value. Then:\n\n- listed choices are offered: argparse `{staging,production}` , clap`[possible values: auto, always, never]` , commander`(choices: \"fast\", \"careful\")` , also when they continue on the next line;\n- values named like `DIR` complete directories,`FILE` or`PATH` files;\n- other values (`TAG` ) complete nothing, so you don't get a misleading file\nlist.\n\nCommands with their own `_foo` completion (git, docker, ...) keep it. Only\nwhen that completion finds nothing for a word starting with `-` does the\nplugin step in and read the options from the help output (asking first, as\nalways). For example, zsh 5.9's `_mv` declares `--backup=` as taking a\nseparate argument, so `mv --backup --<Tab>` normally suggests nothing; with\nthis plugin it lists mv's options. This works through a `_zhc_fallback`\ncompleter that the plugin inserts after `_complete` in the `completer` style.\nIf you set that style after loading the plugin, add `_zhc_fallback` after\n`_complete` yourself:\n\n```\nzstyle ':completion:*' completer _expand _complete _zhc_fallback _ignored\n./install.sh            # with oh-my-zsh: symlinks into custom/plugins\n```\n\nThen add `zsh-help-complete` to `plugins=( ... )` in `.zshrc` and run\n`exec zsh`. Without oh-my-zsh, `install.sh` appends a `source` line to the end\nof `.zshrc` (it must come after `compinit`).\n\nPlugin managers (load it after `compinit`):\n\n```\nzinit light tanaydin/zsh-help-complete       # zinit\nantidote bundle tanaydin/zsh-help-complete   # antidote (or add to .zsh_plugins.txt)\n```\n\nManually:\n\n```\ngit clone https://github.com/tanaydin/zsh-help-complete ~/.zsh/zsh-help-complete\necho \"source ~/.zsh/zsh-help-complete/zsh-help-complete.plugin.zsh\" >> ~/.zshrc\n```\n\nThe context is `:zhc:cmd:<command name>`: `:zhc:*` applies to every command,\n`:zhc:cmd:mytool` to one.\n\n```\nzstyle ':zhc:*' ask no                          # don't ask before the first run (see Safety)\nzstyle ':zhc:*' decisions-file ~/.config/zsh-help-complete/decisions  # (default)\nzstyle ':zhc:*' script-check no                 # run scripts even without signs of --help handling\nzstyle ':zhc:*' sandbox yes                     # run help read-only, without network\nzstyle ':zhc:*' help-options --help             # help flags to try (default: only --help)\nzstyle ':zhc:cmd:mytool' help-options --help -hh  # also try -hh for mytool\nzstyle ':zhc:*' timeout 5                       # seconds allowed per help call\nzstyle ':zhc:*' denylist rm dd mkfs shutdown    # replaces the default list\nzstyle ':zhc:*' denylist rm 'mytool deploy'     # entries may name a subcommand\nzstyle ':zhc:*' allow-paths no                  # never run executables given by path\nzstyle ':zhc:*' subcommands no                  # no subcommand names; \"tool sub --\" uses \"tool --help\"\nzstyle ':zhc:*' fallback no                     # leave commands with their own completion alone\nzstyle ':zhc:*' ignore '--foo*'                 # option patterns to drop (default none)\nzstyle ':zhc:*' cache no                        # don't keep help output in files\nzstyle ':zhc:*' cache-dir ~/.cache/zsh-help-complete  # where it is kept (default)\nzstyle ':zhc:*' enabled no                      # disable\n```\n\nWith several help flags, each is tried in turn and the output with the most option lines wins. If one times out, the remaining flags are skipped.\n\nThe help output is kept in files under `~/.cache/zsh-help-complete`\n(`$XDG_CACHE_HOME` is respected), so each command is run only once, not once\nper shell. A file is used only while the executable is unchanged (same\nmtime, size and inode; symlinks are followed) and the `help-options` and\n`timeout` settings are the same, so an updated tool is re-read on the next\nTab, without restarting the shell. A help call that timed out is not kept.\n\nThe GIF above is recorded with [vhs](https://github.com/charmbracelet/vhs)\n(needs `vhs` and `ttyd`): run `vhs assets/demo.tape` from the repo root.\n\n```\nzsh -f tests/run.zsh\n```\n\nDrives a real interactive zsh via `zpty`. Using fake commands, it checks the\nfirst-run question (each answer, remembered answers, asking again when the\nprogram changed, `zhc allow`, non-option words never asking), the sandbox\n(when `bwrap` or `sandbox-exec` works), option values (choices in three\nformats, directories, files, skipping a value), subcommand names (aliases,\nwrapped descriptions, nesting, argparse), the script check (shell scripts without signs\nof `--help` handling, scripts by path, shell script subcommands not being\nrun, argparse subcommands), malformed help lines (including one sharing a\nname with a real option), `--color[=WHEN]`, completing an option after\nanother, executables given by path, help flags, subcommands (nested,\nunlisted words, denylisted subcommands), the styles, stepping in when a\ncommand's own completion finds nothing (and staying out when it works),\nre-reading an updated tool in the same shell, the file cache, a hanging\n`--help`, the denylist, and the fallback to file completion.", "url": "https://wpnews.pro/news/zsh-help-complete-tab-complete-any-cli-s-options-from-its-help", "canonical_source": "https://github.com/tanaydin/zsh-help-complete", "published_at": "2026-11-30 06:51:31+00:00", "updated_at": "2026-11-30 07:15:45.674337+00:00", "lang": "en", "topics": ["developer-tools"], "entities": ["zsh-help-complete", "zsh"], "also_reported_by": [], "takeaway": "zsh-help-complete completes options for any CLI by running `tool --help`, but it prompts before first execution, re-asks when the file's mtime, size or inode change, and blocks a denylist including rm, dd, mkfs and shutdown.", "recommendation": null, "alternates": {"html": "https://wpnews.pro/news/zsh-help-complete-tab-complete-any-cli-s-options-from-its-help", "markdown": "https://wpnews.pro/news/zsh-help-complete-tab-complete-any-cli-s-options-from-its-help.md", "text": "https://wpnews.pro/news/zsh-help-complete-tab-complete-any-cli-s-options-from-its-help.txt", "jsonld": "https://wpnews.pro/news/zsh-help-complete-tab-complete-any-cli-s-options-from-its-help.jsonld"}}