Repository navigation
Conversation
Wraps the force-push regex (line 120) and all four `git commit` regex sites (security checks, no-changes guard, worktree warning, conventional commits validator) behind the same `^gh (issue|pr) ` exclusion that already guarded the secrets/credentials checks at line 87. Previously, `gh issue create` / `gh pr create` / `gh issue|pr comment` calls whose body text merely *referenced* these tokens (e.g. a doc explaining the hook itself, or a release note) were blocked at the tool-call level. The friction was disproportionate to the protection: the regexes already work against actual destructive commands at the command-string boundary; matching free body content added noise without adding safety. Mirrored the fix across all three hook copies — `templates/hooks/pre-tool.sh`, `hooks/pre-tool.sh`, and `.claude/hooks/pre-tool.sh` — none of which are symlinks, all of which Claude Code may invoke depending on context. Adds `__tests__/pre-tool-hook.integration.test.ts` covering 10 cases: the four primary regression pairs from the issue (allow gh-body / block real-command, for both regexes), plus a START-anchor regression guard (`echo gh issue && git push --force` is still blocked) and a sanity check that the no-changes guard does not fire when changes are staged. AC-4 runs in an isolated tmp git repo so the assertion is independent of the developer's working tree. Follow-up to #532 (which deferred this as AC-5). Closes #564
6 tasks
Addresses two gaps surfaced during QA review (#566): 1. Tests previously exercised only `templates/hooks/pre-tool.sh` (the canonical source). The fix is mirrored to `hooks/pre-tool.sh` and `.claude/hooks/pre-tool.sh`, but neither was directly verified — future regex changes could re-drift in either copy without the suite catching it. Wraps the existing 10 cases in `describe.each(HOOK_COPIES)`, threading the hook path through `runHook()`. Test count grows from 10 to 30 (10 × 3 copies), all passing. Each copy is now a first-class regression target. 2. Inline comment asymmetry: only the force-push block carried the `# Skip for gh issue/pr commands — body text may legitimately reference these tokens (#564)` comment; the four `git commit` blocks (security, no-changes guard, worktree-warn, conventional-commits) didn't. Adds the same comment line above each of the four `git commit` blocks in all three hook copies (12 inserts total). The comment is indented correctly at the security-check site (which is nested inside the `if [[ "${CLAUDE_HOOKS_SECURITY:-true}" != "false" ]]` block). A third gap surfaced during QA — same body-content false-positive surface in the destructive-command, deployment, hard-reset, and gh-workflow regexes (lines 95/101/130/170 of the canonical file) — is filed as a follow-up issue rather than expanding this PR's scope further.
7 tasks
admarble
deleted the
feature/564-bug-pre-tool-sh-regexes-match-inside-quoted-gh-body
branch
May 3, 2026 15:17
admarble
added a commit
that referenced
this pull request
May 6, 2026
…ructive/deployment/reset/workflow commands (#578) * fix(#570): pre-tool.sh regexes skip gh issue/pr body content for destructive/deployment/reset/workflow commands Wraps four additional regex sites in pre-tool.sh with the same `^gh (issue|pr) ` exclusion idiom introduced in #564 / #566: - Destructive system commands site (line ~95) - Deployment commands site (line ~101) - git reset outer guard (inner BLOCK_REASONS accumulator unchanged) - gh workflow run site Applied across all three mirrored hook copies: - templates/hooks/pre-tool.sh - hooks/pre-tool.sh - .claude/hooks/pre-tool.sh Real destructive commands are still blocked at the bash command-string level; only `gh issue|pr create|comment` payloads referencing these tokens in body text are allowed through. Adds 24 parametrized test cases (8 new tests x 3 hook copies) to __tests__/pre-tool-hook.integration.test.ts covering allow-on-gh-body and block-on-real-command for each of the four sites. Closes #570 * test(#570): add verbatim issue-body fixtures to integration test Per feedback_motivating_example_regression — examples quoted verbatim in an issue body are mandatory test fixtures, not paraphrases. The existing AC-1..AC-4 tests covered the spirit of each "Affected regex sites" table row but used reworded fixtures (e.g. "never run rm -rf / on production" vs the issue's verbatim "WARNING: never run `rm -rf /` ..."). This commit adds the EXACT strings from the #570 issue body: - Row 1 destructive: cleanup-doc explainer payload - Row 2 deployment: release-notes payload - Row 3 git reset: tutorial payload (with dirty-repo fixture so the outer guard is actually exercised, not silently skipped via empty BLOCK_REASONS) - Row 4 gh workflow: workflow-doc payload - "Repro pattern" section: gh issue create with `rm -rf /` body Each fixture parametrized over the 3 hook copies via the existing describe.each(HOOK_COPIES) block = 15 net new test runs. Test count: 72 -> 87, all passing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the
pre-tool.shregexes that match inside quotedgh issue/prbody content, blocking tool calls whose payloads merely reference the matched literals (e.g. a doc explaining the hook itself).git commitregex sites (security checks, no-changes guard, worktree warning, conventional-commits validator) behind the same^gh (issue|pr)exclusion that already guarded the secrets/credentials checks at line 87.templates/hooks/pre-tool.sh,hooks/pre-tool.sh,.claude/hooks/pre-tool.sh— none of which are symlinks.__tests__/pre-tool-hook.integration.test.ts(10 cases) spawns the canonical hook with real stdin/exit-code assertions; AC-4 uses an isolated tmp git repo so "no staged changes" is deterministic.AC Coverage
AC-2,AC-2bAC-3blocksgit push --force,AC-3bblocksgit push -f origin mainAC-4blocksgit commit -m 'msg'with no staged changes;AC-4bconfirms anchor is at start of TOOL_INPUT__tests__/pre-tool-hook.integration.test.ts— 10 passing cases (4 primary AC pairs + 4 sub-cases + 1 anchor regression + 1 sanity)[Unreleased] / ### Fixedreferences #564 and #532Scope Note (broader than literal AC text)
The issue's AC-2 names line 248 (no-changes guard) of
.claude/hooks/pre-tool.shspecifically. The samegrep -qE 'git commit'regex appears at four places in the canonicaltemplates/hooks/pre-tool.sh(security-checks/L228, no-changes/L260, worktree-warning/L287, commit-msg-validation/L298). All four share the same root cause and the same body-content false-positive surface, so the exclusion is applied at all four sites.Per the spec comment's Open Questions, this is the recommended interpretation of the issue's intent. The
Non-Goalscarve-out ("Don't widen exclusion beyondgh issue|pr") refers to not adding exclusions for other parent commands, not to under-applying the same exclusion to all instances of the same regex.Live reproduction during /spec
Both bugs reproduced live during planning (read-only
grepinspection of the hook source tripped both regexes), and the heredoc that produced the spec body was itself blocked — it was rewritten via the Write tool instead. Validates the issue without needing synthetic fixtures.Test plan
npm run build— passesnpm run lint— passes (0 warnings)npx vitest run __tests__/pre-tool-hook.integration.test.ts— 10/10 passingbash -nsyntax check on all 3 hook copies — passeshooks/pre-tool.shvstemplates/hooks/pre-tool.sh— identical (mirroring preserved)Known gaps / out of scope
.claude/hooks/pre-tool.shhas drifted fromtemplates/hooks/pre-tool.sh(older byte-count: 17896 vs 18509). This PR fixes the regexes in all three copies but does not re-sync the broader drift — that's a separate hygiene issue.*.integration.test.tsso it runs in the integration project (subprocess-heavy tests).Closes #564