Pre-build a static --help database for CLI commands, so Claude Code can look up accurate flag/option references instantly via a PreToolUse hook.
Claude Code sometimes misuses CLI options — wrong flags, deprecated syntax, nonexistent arguments. Injecting --help output through additionalContext fixes this, but fetching it dynamically every time risks timeouts and wastes tokens. This tool pre-collects help text into plain .txt files for instant, zero-cost lookup.
go install github.com/kwrkb/cli-help-db@latest1. Generate and install the hook
# Linux / macOS
mkdir -p ~/.claude/hooks
cli-help-db hook --lazy > ~/.claude/hooks/auto-help.sh
chmod +x ~/.claude/hooks/auto-help.sh
# Windows (Git Bash / MSYS2)
mkdir -p ~/.claude/hooks
cli-help-db hook --lazy > ~/.claude/hooks/auto-help.sh2. Add to ~/.claude/settings.json
{
"hooks": {
"PreToolUse": [
{
"matcher": "Bash",
"hooks": [
{
"type": "command",
"command": "bash ~/.claude/hooks/auto-help.sh"
}
]
}
]
}
}That's it. With --lazy, the hook automatically collects --help on first use of any command and caches it to ~/.claude/cli-help/ for instant lookup next time. No config file or build step required.
If you want to pre-populate the database so that even the first use has no delay, create a config and run build:
# macOS
mkdir -p ~/Library/Application\ Support/cli-help-db
cp config.example.yaml ~/Library/Application\ Support/cli-help-db/config.yaml
# Linux
mkdir -p ~/.config/cli-help-db
cp config.example.yaml ~/.config/cli-help-db/config.yaml
# Windows (Git Bash / MSYS2)
mkdir -p "$APPDATA/cli-help-db"
cp config.example.yaml "$APPDATA/cli-help-db/config.yaml"Edit the commands list in the config file, then run:
cli-help-db build| Command | Description |
|---|---|
scan |
List all executable commands on $PATH |
build |
Collect --help and build the database |
list |
Show commands stored in the database |
hook |
Generate auto-help.sh hook script |
| Flag | Description |
|---|---|
--force |
Re-collect all commands, ignoring existing database entries |
--all |
Scan all $PATH commands instead of config whitelist |
--dry-run |
Show target commands without actually collecting |
-config <path> |
Override config file path |
By default, build only collects help for commands not already in the database (incremental). Use --force to re-collect everything. Flags can be combined (e.g., build --all --dry-run).
| Flag | Description |
|---|---|
--lazy |
Enable lazy collection: auto-fetch --help for unknown commands on first use |
-config <path> |
Override config file path |
With --lazy, the hook dynamically collects help text for commands not in the database, saves it for future lookups, and injects it in the same request. Subsequent uses read from the static DB with zero latency.
Config file location (resolved via Go's os.UserConfigDir()):
| OS | Path |
|---|---|
| macOS | ~/Library/Application Support/cli-help-db/config.yaml |
| Linux | ~/.config/cli-help-db/config.yaml |
| Windows | %APPDATA%\cli-help-db\config.yaml |
See config.example.yaml for a full example:
commands: # Whitelist of commands to index
- curl
- jq
- docker
output_dir: ~/.claude/cli-help # Default
line_limit: 60 # Max lines per command
timeout: 3s # Per-command timeout
parallelism: 8 # Concurrent workers-
Build phase (
cli-help-db build): For each whitelisted command (or all$PATHcommands with--all), tries--help, falls back to-h, thenman. Output is trimmed to the configured line limit and saved as~/.claude/cli-help/{command}.txt. Already-collected commands are skipped unless--forceis used. -
Runtime phase (hook): When Claude Code invokes the Bash tool, the hook extracts the command name and looks up
{command}.txtin the database. If found, it injects the help text viaadditionalContext— no subprocess execution, no timeout risk.
MIT
CLIコマンドの --help 出力を事前収集し、Claude Code が PreToolUse フック経由で即座に参照できる静的ヘルプデータベースを生成するGoツール。
Claude Code は CLI ツールのオプションを誤ることがある(存在しないフラグ、非推奨の構文など)。additionalContext で --help 情報を注入すれば精度が上がるが、毎回動的に実行するとタイムアウトリスクとトークンコストがかかる。このツールはヘルプテキストをプレーン .txt ファイルとして事前収集し、実行時コストゼロで参照可能にする。
go install github.com/kwrkb/cli-help-db@latest1. フックを生成・インストール
# Linux / macOS
mkdir -p ~/.claude/hooks
cli-help-db hook --lazy > ~/.claude/hooks/auto-help.sh
chmod +x ~/.claude/hooks/auto-help.sh
# Windows (Git Bash / MSYS2)
mkdir -p ~/.claude/hooks
cli-help-db hook --lazy > ~/.claude/hooks/auto-help.sh2. ~/.claude/settings.json に追加
{
"hooks": {
"PreToolUse": [
{
"matcher": "Bash",
"hooks": [
{
"type": "command",
"command": "bash ~/.claude/hooks/auto-help.sh"
}
]
}
]
}
}これだけで完了。--lazy により、コマンド初回使用時に --help を自動取得し ~/.claude/cli-help/ にキャッシュする。2回目以降は即座に参照。設定ファイルや事前ビルドは不要。
初回使用時の遅延も避けたい場合は、設定ファイルを作成して build を実行:
# macOS
mkdir -p ~/Library/Application\ Support/cli-help-db
cp config.example.yaml ~/Library/Application\ Support/cli-help-db/config.yaml
# Linux
mkdir -p ~/.config/cli-help-db
cp config.example.yaml ~/.config/cli-help-db/config.yaml
# Windows (Git Bash / MSYS2)
mkdir -p "$APPDATA/cli-help-db"
cp config.example.yaml "$APPDATA/cli-help-db/config.yaml"設定ファイルの commands リストを編集してから:
cli-help-db build| コマンド | 説明 |
|---|---|
scan |
$PATH 上の実行可能コマンドを一覧表示 |
build |
--help を収集してデータベースを構築 |
list |
データベース内のコマンド一覧を表示 |
hook |
auto-help.sh フックスクリプトを生成 |
| フラグ | 説明 |
|---|---|
--force |
既存DBを無視して全コマンド再取得 |
--all |
ホワイトリスト無視で $PATH 全コマンドを対象にビルド |
--dry-run |
実際に取得せず対象コマンド一覧を表示 |
-config <path> |
設定ファイルのパスを指定 |
デフォルトでは未取得のコマンドのみ収集する(差分更新)。--force で全再取得。フラグは併用可能(例: build --all --dry-run)。
| フラグ | 説明 |
|---|---|
--lazy |
未知のコマンドを初回使用時に自動取得してDBに保存 |
-config <path> |
設定ファイルのパスを指定 |
--lazy を指定すると、DBにないコマンドの --help を動的に取得し、DBに保存してから同じリクエストで注入する。2回目以降は静的DB参照でゼロレイテンシ。
設定ファイルの場所(Go の os.UserConfigDir() で解決):
| OS | パス |
|---|---|
| macOS | ~/Library/Application Support/cli-help-db/config.yaml |
| Linux | ~/.config/cli-help-db/config.yaml |
| Windows | %APPDATA%\cli-help-db\config.yaml |
完全な例は config.example.yaml を参照:
commands: # 対象コマンドのホワイトリスト
- curl
- jq
- docker
output_dir: ~/.claude/cli-help # デフォルト出力先
line_limit: 60 # 1コマンドあたりの最大行数
timeout: 3s # コマンド実行タイムアウト
parallelism: 8 # 並列ワーカー数-
ビルド時 (
cli-help-db build): ホワイトリストの各コマンド(--all指定時は$PATH全コマンド)に対して--help→-h→manの順で試行。出力を行数制限でトリミングし、~/.claude/cli-help/{command}.txtとして保存。--force指定がない場合、既存のコマンドはスキップする。 -
実行時 (フック): Claude Code が Bash ツールを呼ぶと、フックがコマンド名を抽出し
{command}.txtを参照。ファイルがあればadditionalContextとしてヘルプテキストを注入する。サブプロセス実行なし、タイムアウトリスクなし。
MIT