Repository navigation
Description
Finding
pre-tool.sh's conventional-commit validator mis-parses one commit-message form: git commit -F - <<'EOF' … EOF (message on stdin via heredoc). When the subject contains # — i.e. the repo's own type(#N): … convention — everything from # onward is dropped before validation, and the hook blocks a valid message.
Reproduced 2026-09-15 by feeding the hook its stdin JSON directly (CLAUDE_PROJECT_DIR set, one file staged so the no-changes guard passes):
| Form | Subject | Result |
|---|---|---|
A. git commit -q -F - <<'EOF' … fix(#497): … |
has # |
HOOK_BLOCKED — Got: fix( followed by whitespace |
B. same, fix(codex): … |
no # |
exit 0 |
C. git commit -m "$(cat <<'EOF' … EOF)" … fix(#497): … |
has # |
exit 0 |
D. git commit -m "fix(#497): …" -m "body" |
has # |
exit 0 |
E. git commit -F /tmp/msg.txt (file contains fix(#497): …) |
has # |
exit 0 |
So the $(cat <<EOF) idiom that #981's segment parser special-cases is fine; the bare -F - + heredoc path is not treated as data and gets the code-side #-comment stripping (#763 class). The Got: text — fix( plus a run of spaces — is consistent with the #… tail being blanked rather than removed.
Impact
- Any agent or human that writes
git commit -F - <<'EOF'with an issue-referencing subject is blocked with a misleading message (the shown "Got:" is not what they wrote). - Because a PreToolUse block aborts the whole Bash command, a preceding
git add … && git commit -F - …loses the staging step too; the retry then fails with "No changes to commit" — a second misleading error. Hit twice in one session on PR feat(#497): CodexDriver core — subprocess codex exec --json, SDK-typed parser, three-level outcome evaluator #1062.
Repro
export CLAUDE_PROJECT_DIR=$PWD; touch scratch && git add scratch
printf '%s' $'git commit -q -F - <<\'EOF\'\nfix(#497): subject\n\nbody\nEOF' \
| python3 -c 'import json,sys;print(json.dumps({"tool_name":"Bash","session_id":"x","cwd":"'"$PWD"'","tool_input":{"command":sys.stdin.read()}}))' \
| bash .claude/hooks/pre-tool.sh; echo "exit=$?"
git rm --cached scratch && rm scratchExpected: exit 0. Actual: exit 2, Got: fix(.
Suggested fix
In the segment parser (pre-tool.sh ~L322–460), treat -F - / --file - as "message is the heredoc body of this segment" exactly as the $(cat <<EOF) idiom is treated, so the body is data and # survives. Add forms A–E above to __tests__/pre-tool-hook.integration.test.ts (A is the regression; B–E pin the paths that already work). Mirror to templates/hooks/ and the plugin copy.
Related
#981 (segment extraction — fixed the earlier-quoted-string and unrelated-heredoc paths, not this one) · #763 (comment stripping) · #963 · memory note reference_commit_hook_hash_in_heredoc
Release-graph plan — pre-2.16.0 blockers (2026-09-17)
Graph: pre-2.16.0 release blockers, node 1 of 4 Tier: judgment Wave: 1
Executed by: #1060 gate run 2 (codex) — this issue is the gate's subject; the gate's
PR closes it. Fallback: a Claude run of this same issue if run 2 fails or is NO-GO.
May touch: hooks/pre-tool.sh, .claude/hooks/pre-tool.sh, templates/hooks/pre-tool.sh, __tests__/pre-tool-hook.integration.test.ts, CHANGELOG.md
Root cause (confirmed 2026-09-17)
Not an unhandled path. emit_segments already keeps a -F - heredoc body raw
(pre-tool.sh:537-556). The validator then re-strips it — s = strip_comments($0)
at pre-tool.sh:1273 — and heredoc_first_line reads that stripped copy, so
fix(#497): subject reaches the check as fix( plus blanks.
Prior attempt — salvage the code, discard the test
origin/archive/1064-gate-run1 (gate run 1 of #1060; exec could not commit because of
#1076, since fixed by #1077) threads a raw variable beside s through message_at
and both heredoc_first_line call sites, in all three copies. Verified 2026-09-17
against the matrix below: passes A–D and still blocks a non-conventional message
(no fail-open). Its added test exercises the $(cat <<EOF) path with a # in the
message body — not form A — so it does not gate this bug. Start from that diff;
write the test fresh.
Acceptance Criteria
- AC-1:
git commit -F -with a heredoc subject containing#passes the hook (exit 0) in all three copies, via a form-A integration case — Evidence:npx vitest run __tests__/pre-tool-hook.integration.test.ts -t "1064" 2>&1 | grep -E "Tests +(1[5-9]|[2-9][0-9]+) passed"prints a passed line (5 cases × 3 copies = 15 minimum; zero matches or any failure prints nothing) - AC-2: the same
-F -heredoc path still BLOCKS a non-conventional subject such aswip(exit 2, no fail-open) — Evidence:npx vitest run __tests__/pre-tool-hook.integration.test.ts -t "1064 blocks" 2>&1 | grep -E "Tests +[3-9] passed"prints a passed line (1 case × 3 copies) - AC-3: forms B (
-F -, no#), C (-m "$(cat <<EOF)"with#) and D (-mliteral with#) stay exit 0 as regression pins, one case each — Evidence:npx vitest run __tests__/pre-tool-hook.integration.test.ts -t "1064 pins" 2>&1 | grep -E "Tests +(9|[1-9][0-9]+) passed"prints a passed line (3 cases × 3 copies) - AC-4: the three hook copies are byte-identical — Evidence:
shasum hooks/pre-tool.sh .claude/hooks/pre-tool.sh templates/hooks/pre-tool.sh | awk '{print $1}' | sort -u | wc -lprints 1 - AC-5: the full hook suite passes with no failures — Evidence:
npx vitest run __tests__/pre-tool-hook.integration.test.ts 2>&1 | grep -E "Tests +[0-9]+ passed \("prints a passed line with no failed count - AC-6: the PR body records which
pre-tool.sha Claude Code session with the sequant plugin installed actually runs — the repo's.claude/hooks/copy or~/.claude/plugins/cache/sequant/sequant/<ver>/hooks/— with the command and output that settled it — Evidence:gh pr view --json body -q .body | grep -c "Hook precedence:"prints 1
AC-1 and AC-2 are gate tests: mutation-verify per CLAUDE.md §Testing (delete the raw
threading in one copy → AC-1 fails; make the validator print nothing for -F - → AC-2
fails) and record the Mutation-verified: markers in the PR body.
Test naming contract for the selectors above: the form-A case's name contains 1064,
the negative case's contains 1064 blocks, the three pins' contain 1064 pins.
Repro matrix (paste-able; run from the repo root)
export CLAUDE_PROJECT_DIR=$PWD; touch scratch-1064 && git add scratch-1064
run_case () {
printf '%s' "$2" \
| python3 -c 'import json,sys,os;print(json.dumps({"tool_name":"Bash","session_id":"x","cwd":os.environ["PWD"],"tool_input":{"command":sys.stdin.read()}}))' \
| bash .claude/hooks/pre-tool.sh >/dev/null 2>&1; echo "[$1] exit=$?"
}
run_case "A must be 0" "$(printf 'git commit -q -F - <<'"'"'EOF'"'"'\nfix(#497): subject\n\nbody\nEOF')"
run_case "B must be 0" "$(printf 'git commit -q -F - <<'"'"'EOF'"'"'\nfix(codex): subject\n\nbody\nEOF')"
run_case "C must be 0" "$(printf 'git commit -m "$(cat <<'"'"'EOF'"'"'\nfix(#497): subject\nEOF\n)"')"
run_case "D must be 0" 'git commit -m "fix(#497): subject" -m "body"'
run_case "E must be 2" 'git commit -m "wip"'
git rm --cached -q scratch-1064 && rm -f scratch-1064Today: A=2, B=0, C=0, D=0, E=2. Required: A=0, B=0, C=0, D=0, E=2.
Execution note
In Claude Code sessions the plugin-cache copy of the hook may keep firing until release
(sequant update), so commit with -m + -m, never -F - with a heredoc. Under codex
the worktree's own .claude/hooks copy runs, so the fix is live as soon as it is written.
Activity
fix(#1076): pass the git dir as a codex writable root so phases can c…
admarble commentedon Sep 18, 2026
Complexity: Standard (6 ACs, 2 directories)
AC Quality Check
Five ACs are clear and testable. AC-2 is lint-flagged solely for “such as”; implementation should pin the stated subject
wip(rather than treating it as an open-ended set).Scope Assessment
Non-Goals:⚠️ Non-Goals section not found. Scope remains limited to the commit-message extractor, its three mirrored hook copies, hook integration tests, and required PR evidence.
Verdict:⚠️ SCOPE_WARNING — six ACs and a missing Non-Goals boundary warrant the quality loop, but this is one localized bug fix, not a split candidate.
Acceptance Criteria
AC-1: Form-A
git commit -F -heredoc with#is allowed in all mirrorsVerification: Unit Test
Scenario: Given a staged temp repo and
git commit -q -F - <<'EOF'with subjectfix(#497): subject→ When each hook copy runs → Then exit is 0 (five #1064 cases × three copies: at least 15 assertions).Assumptions: The existing
describe.each(HOOK_COPIES)matrix remains the mirror coverage mechanism.AC-2: The same stdin-heredoc path remains fail-closed for
wipVerification: Unit Test
Scenario: Given the same command shape with subject
wip→ When each copy runs → Then exit is 2 and the diagnostic exposes the true subject.AC-3: Existing working forms B, C, and D remain allowed
Verification: Unit Test
Scenario: Given respectively
-F -without#,-m "$(cat <<EOF)with#, and literal-mwith#→ When hooks run → Then each exits 0 across all copies.AC-4: Hook mirrors stay synchronized
Verification: Integration Test
Scenario: Given the edited three scripts → When their SHA-1 hashes are compared → Then exactly one unique digest is printed.
AC-5: The complete hook integration suite is green
Verification: Unit Test
Scenario: Given the updated suite → When the full pre-tool integration test file runs → Then Vitest reports no failures.
AC-6: The eventual PR records active Claude Code hook precedence
Verification: Integration Test
Scenario: Given a Claude Code session with the Sequant plugin installed → When hook resolution is inspected experimentally → Then the PR body has exactly one
Hook precedence:record with command and output.Assumptions: No PR exists yet; this is a release/PR handoff requirement, not evidence that can be completed during implementation alone.
Implementation Plan
Phase 1: Correct the parser without weakening comment handling
origin/archive/1064-gate-run1approach: retainraw = $0, derives = strip_comments(raw)for anchoring/flag scanning, and pass both throughmessage_at.heredoc_first_line(raw, ...)at both call sites (-m "$(...<<EOF)"and the-F -fallback), while retainingsfor all code-context recognition.hooks/pre-tool.sh,.claude/hooks/pre-tool.sh, andtemplates/hooks/pre-tool.sh; do not change segment extraction, which already preserves-F -heredoc data.Phase 2: Add the regression matrix and verify
describe.each(HOOK_COPIES)bug(hooks): commit validator strips#from agit commit -F -heredoc subject, blocking everytype(#N):message sent via stdin #1064 block beside the fix(hooks): commit-message validator extracts from the whole command, so an earlier quoted string or unrelated heredoc blocks a valid conventional commit #981 extractor tests, using its staged-repo helper. Name the cases so selectors satisfy the contract: one form-A allow case containing1064, one1064 blocksnegative case, and three1064 pinsallow cases.-F -; record both results in the PR body.Hook precedence:section with exact command/output. UpdateCHANGELOG.mdonly if the project’s release policy requires this hook fix to be listed.Design Review
commit_message_fromowns the distinction: sanitized text for shell-code parsing, raw text for the extracted commit-message payload.strip_commentswould reopen fix(hooks):^gh (issue|pr)prefix skip disarms all 5 pre-tool guards for compound commands, and re-breaks on anycdprefix #763-style comment false positives.s; only a heredoc body reached from recognized commit syntax is read raw.Feature Quality Planning
-m "$(cat ...)"with#in a body, not form A.Open Questions
CHANGELOG.mdchange? — Recommendation: follow the repository’s current release policy; the issue says it may touch it, but no AC requires it. Impact: avoid unrelated churn.Recommended Workflow
Phases: spec → testgen → exec → qa
Quality Loop: enabled
Reasoning: AC-1/2/3/5 declare unit-test evidence, so testgen should establish the selector-compatible matrix before implementation. This is non-UI shell behavior; browser testing is not applicable. Scope warning enables the quality loop.
Label Review
Current: bug
Recommended: bug, planned
Reason: This remains a localized bug fix; no UI, security, refactor, or breaking label is supported.
Quality Loop: Will auto-enable due to the scope warning.
admarble commentedon Sep 18, 2026
Test Stubs Generated
#-stripping regression; raw-threading mutationwipmust exit 2 and show the true subjectHook precedence:recordFile status
The intended test target already exists:
__tests__/pre-tool-hook.integration.test.ts. It contains the shareddescribe.each(HOOK_COPIES)staged-repository matrix and the adjacent #981 extractor cases. Per testgen safety rules, no existing file was overwritten.Implementation should add the #1064 matrix block beside #981 with these selector-compatible cases:
1064: Form A, staged repo,git commit -q -F - <<'EOF'and subjectfix(#497): subject; assert exit 0 in every mirror.1064 blocks: same Form A with subjectwip; assert exit 2 and diagnosticGot: wipin every mirror.1064 pins: three allowed forms—-F -without#,-m "$(cat <<EOF)"with#, and literal-mwith#; assert exit 0 in every mirror.This yields five #1064 cases × three hook copies = at least 15 matrix assertions. Keep code-context anchoring/flag scanning comment-sanitized; read raw text only for a recognized heredoc payload.
AC-4 verification stub
AC-5 verification stub
npx vitest run __tests__/pre-tool-hook.integration.test.ts # expected: no failuresAC-6 manual integration handoff
Before creating the PR, inspect active Claude Code hook resolution in a session with the Sequant plugin installed. Put exactly one
Hook precedence:section in the PR body, including the command and unedited output. This cannot be made hermetic in the Vitest suite because no PR/session is available yet.Generated with Sequant testgen.
fix(#1064): preserve heredoc commit subjects (#1088)