Skip to content

Commit bc4f2a5

Browse files
committed
fix: embed pre-commit error details into block reason field
Claude Code hook system only shows the JSON reason field to the agent, stderr output is invisible. Move detailed error info from stderr into the reason so the agent can see exactly what failed and fix it directly.
1 parent a89fe48 commit bc4f2a5

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

hooks/pre-bash-guard.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,13 @@ if echo "$COMMAND_STRIPPED" | grep -qE 'git\s+commit\b'; then
109109
PRECOMMIT_OUTPUT=$(VIBEGUARD_DIR="${VIBEGUARD_DIR:-$(cd "$HOOK_DIR/.." && pwd)}" bash "$PRECOMMIT_SCRIPT" 2>&1) || PRECOMMIT_EXIT=$?
110110
if [[ $PRECOMMIT_EXIT -ne 0 ]]; then
111111
vg_log "pre-bash-guard" "Bash" "block" "pre-commit check failed" "$COMMAND"
112-
echo "$PRECOMMIT_OUTPUT" >&2
112+
# Embed detailed output into reason so Claude Code can see it
113+
# (stderr is not visible to the agent, only the JSON reason field is)
114+
ESCAPED_OUTPUT=$(printf '%s' "$PRECOMMIT_OUTPUT" | python3 -c 'import sys,json; print(json.dumps(sys.stdin.read())[1:-1])')
113115
cat <<BLOCK_EOF
114116
{
115117
"decision": "block",
116-
"reason": "VIBEGUARD Pre-Commit check failed. Please fix the problem according to the error message above and resubmit. The use of environment variables to bypass is prohibited."
118+
"reason": "VIBEGUARD Pre-Commit 检查失败。请根据上方错误信息修复问题后重新提交。禁止使用环境变量绕过。\n\n${ESCAPED_OUTPUT}"
117119
}
118120
BLOCK_EOF
119121
exit 0

0 commit comments

Comments
 (0)