Claude Code commit guards never fire: $TOOL_INPUT is unset
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 65/100
Hướng nghiên cứu
Đọc .claude/settings.json và tài liệu tham khảo về Claude Code hooks được liên kết trong issue; issue có các trường hợp tái hiện những guard bị lỗi và thay đổi được đề xuất cho việc phân tích stdin. Kiểm tra cách các guard hoạt động với những cách viết bypass được liệt kê, bao gồm git -C . commit và git commit -am khi có secret chưa được stage. Hoàn tất khi các guard chặn những trường hợp đã stage được mô tả và một lượt kiểm tra CI bao phủ các trường hợp bypass trong issue.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- Go
- Star
- 75
- Fork
- 2
- Merge trung bình
- 16 ngày 4 giờ
- Pull request đã merge (30 ngày)
- 1
Chuẩn bị môi trường
- Có Dockerfile hoặc tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của nylas/cli
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 92/100
-
`XOAUTH2` / `OAUTHBEARER` supportCó thể làm lại được @qasim-nylas đã nhận 152 ngày trước và không có pull request nào đang mở. Đang mởbug enhancement
Issue tương tự
-
receptorctl version: False version mismatch warning when versions differ only by a leading vĐang mởneeds_triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
Maintainer thường phản hồi trong vòng 2 ngày
-
kind/bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
kubernetes-sigs/cluster-api-provider-ibmcloud#3023 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug]: message-level cache_control on chat messages is dropped, so Anthropic prompt caching never triggersCó thể đã có người làm @Atharva-Kanherkar đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 80/100
Maintainer thường phản hồi trong vòng 1 ngày
-
documentation good first issue help wanted
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 90/100
eugenioenko/ttt#1000 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug needs-acceptance wg/developer-experience-ecosystem
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
vllm-project/semantic-router#5249 ·
Maintainer thường phản hồi trong vòng 1 ngày