Claude Code commit guards never fire: $TOOL_INPUT is unset
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 65/100
調査の方向性
.claude/settings.json と、issue でリンクされている Claude Code hooks のリファレンスを読みます。issue には、失敗する guard と提案されている stdin の解析変更についての再現例が含まれています。git -C . commit や、ステージされていない secret を含む git commit -am など、記載されているバイパスの表記で guard がどう動作するかを確認します。説明されているステージ済みのケースを guard がブロックし、issue のバイパスケースが CI チェックで網羅されれば完了です。
索引モデルが issue の本文から書いたものです。
説明
The two PreToolUse guards on Bash in .claude/settings.json (sensitive files and secrets in a commit) exit 2 correctly, but they can't fire: they read $TOOL_INPUT, which Claude Code doesn't set. The call arrives as JSON on stdin (hooks reference: "For command hooks, input arrives on stdin"), so grep -q 'git commit' never matches and both exit 0. Their messages also go to stdout; Claude Code shows a blocking hook's stderr, so Claude wouldn't see why.
A fix that keeps your checks and messages:
{ "type": "command", "command": "if jq -r \".tool_input.command // empty\" | grep -q 'git commit'; then git diff --cached --name-only | grep -E '\\.(env|pem|key|p12)$' && echo '⛔ BLOCKED: Sensitive file in commit' >&2 && exit 2 || exit 0; fi" },
{ "type": "command", "command": "if jq -r \".tool_input.command // empty\" | grep -q 'git commit'; then git diff --cached | grep -iE '(api_key|password|secret|token|nyk_v0)' && echo '⛔ BLOCKED: Possible secret in commit' >&2 && exit 2 || exit 0; fi" }
Tested with the JSON Claude Code sends, in a scratch repo with a staged prod.env and a staged api_key = "..." line: today git commit -m wip exits 0 from both guards. With the fix both exit 2, and git status still passes.
With the fix in place, I also ran it against a few spellings agents produce for the same action. Verified: each of these exits 0, so the commit goes ahead: git -C . commit -m wip, and git commit -am wip when the secret is in an unstaged change to a tracked file (the scan reads only what is already staged, and -a stages the rest at commit time).
Would a check like this be useful in CI, one that runs your guards against bypass spellings and fails the build when one gets through?
Found this while testing Claude Code hooks for Paveo, which I build (open source). Happy to open a PR with the fix.
- 主要言語
- Go
- スター
- 75
- フォーク
- 2
- 平均マージ
- 16日 4時間
- マージ済み PR(30日)
- 1
環境構築
- Dockerfile または Docker Compose ファイルあり
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
nylas/cli のほかの issue
-
難易度 1/5 1時間未満 初心者へのやさしさ 92/100
-
`XOAUTH2` / `OAUTHBEARER` support再び着手できるかも @qasim-nylas が 152 日前に担当しましたが、オープン中のプルリクエストはありません。 オープンbug enhancement
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
cloudflare/terraform-provider-cloudflare#7423 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
router-for-me/CLIProxyAPI#6746 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
ViewData can pair the in-flight proposal with the prepared flag of another proposal対応中かも @HagarMeir が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
hyperledger/SmartBFT#710 ·
メンテナーはふだん 1 日以内に返信
-
[Tool] flac-mirrorオープンhas-license has-readme new-tool ready-to-approve repo-verified
難易度 1/5 1時間未満 初心者へのやさしさ 85/100
shanselman/TinyToolTown#863 · コメント 2 件 ·
メンテナーはふだん 5 日以内に返信