Secret-in-commit hooks never run: Claude Code doesn't set $TOOL_INPUT

Offen Anfängerfreundlich
#124 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
1/5
Geschätzter Aufwand
Unter einer Stunde
Anfängerfreundlichkeit
92/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
shell
Bereich
devtools

Rechercherichtung

Lies .claude/settings.json und die drei Hook-Befehle (zwei PreToolUse, ein PostToolUse), die derzeit echo "$TOOL_INPUT" in grep pipen. Laut der Claude Code hooks reference trifft das Tool-Input über stdin ein, also entferne die Pipe und lass grep stdin direkt lesen, und sende die Blocknachricht an stderr, damit Claude Code sie als Ablehnungsgrund meldet. Fertig, wenn jeder Hook mit Code 2 endet und einen gestagten .env oder einen git commit-Aufruf blockiert, verifiziert, indem dem Hook das JSON zugeführt wird, das Claude Code sendet.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

The two PreToolUse hooks in .claude/settings.json that stop a commit containing a sensitive file or a possible secret, and the PostToolUse security scan, all start with echo "$TOOL_INPUT" | grep -q 'git commit'. Claude Code passes the tool call to a hook as JSON on stdin and does not set $TOOL_INPUT (the hooks reference lists the variables it does set), so the grep never matches and none of the three checks runs.

I checked with Claude Code 2.1.292 that TOOL_INPUT is empty inside a hook. Then, in a repo with .env staged and fed the JSON Claude Code sends for git commit -m wip, both PreToolUse hooks exit 0 and the commit would go ahead.

The fix is to drop echo "$TOOL_INPUT" | so grep reads stdin. Sending the message to stderr also makes it the reason Claude Code gives for the block:

"command": "if grep -q 'git commit'; then git diff --cached --name-only | grep -E '\\.(env|pem|key|p12)$' && echo >&2 '⛔ BLOCKED: Sensitive file in commit' && exit 2 || exit 0; fi"

With that change and the same staged .env, the first hook exits 2 with "Sensitive file in commit" and the second exits 2 with "Possible secret in commit". The same one-line change applies to the PostToolUse scan.

Found this while testing Claude Code guards for Paveo. Happy to open a PR with the fix.

Vorherrschende Sprache
Go
Sterne
76
Forks
3
Ø Merge
14 T. 15 Std.
Gemergte PRs (30 T.)
3

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus nylas/cli

Alle Issues in nylas/cli

Ähnliche Issues

Weitere Issues zu Go

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.