Claude Code commit guards never fire: $TOOL_INPUT is unset
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 65/100
Línea de trabajo
Lee .claude/settings.json y la referencia de Claude Code hooks enlazada en el issue; el issue incluye reproducciones de los guards que fallan y del cambio propuesto en el análisis de stdin. Comprueba cómo se comportan los guards con las formas de bypass indicadas, incluidas git -C . commit y git commit -am con un secret sin stage. El trabajo estará terminado cuando los guards bloqueen los casos descritos con archivos en stage y un check de CI cubra los casos de bypass del issue.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- Go
- Estrellas
- 75
- Forks
- 2
- Merge medio
- 16 d 4 h
- PR fusionados (30 d)
- 1
Preparar el entorno
- Incluye un Dockerfile o un archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de nylas/cli
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 92/100
-
`XOAUTH2` / `OAUTHBEARER` supportQuizá libre de nuevo @qasim-nylas la tomó hace 152 días y no hay ningún pull request abierto. Abiertobug enhancement
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
cloudflare/terraform-provider-cloudflare#7423 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
router-for-me/CLIProxyAPI#6746 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
ViewData can pair the in-flight proposal with the prepared flag of another proposalPosiblemente ocupada @HagarMeir la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
hyperledger/SmartBFT#710 ·
Los mantenedores suelen responder en 1 día
-
[Tool] flac-mirrorAbiertohas-license has-readme new-tool ready-to-approve repo-verified
Dificultad 1/5 Menos de una hora Aptitud para principiantes 85/100
shanselman/TinyToolTown#863 · 2 comentarios ·
Los mantenedores suelen responder en 5 días