Skip to content

docs: document force-push handoff pattern when pre-tool hook blocks #532

Closed

Description

@admarble

Summary

.claude/hooks/pre-tool.sh:106-111 blocks all force pushes with HOOK_BLOCKED: Force push. No existing guidance in CLAUDE.md or .claude/skills/_shared/ tells agents how to proceed when a legitimate force push is required (e.g., after a clean rebase). CLAUDE_HOOKS_DISABLED=true inside a Bash command doesn't work because the hook reads the env var before Bash executes, at the harness level.

Self-referential evidence: The initial gh issue create for this very issue was blocked by the hook, because the regex at line 108 (git push.*(--force| -f($| ))) has no anchoring and matched the literal strings in the issue body. Creating the issue required writing the body to a file first.

Motivation

During a session with two legitimate force pushes (cleaning contamination off a PR after rebase), I rediscovered the same workaround twice — hand the exact command to the user prefixed with ! so they run it in-session. Documenting this pattern saves every future agent the same friction and discourages CLAUDE_HOOKS_DISABLED=true false starts.

Acceptance Criteria

  • AC-1: Add a short section to CLAUDE.md (or a new .claude/skills/_shared/references/force-push.md referenced from CLAUDE.md) describing the pattern: "when a force push is required, present the command prefixed with ! for the user to execute in-session"
  • AC-2: Include a note that agents must not attempt to bypass the hook; the block is intentional (force-pushing to main/shared branches is destructive)
  • AC-3: Reference pre-tool.sh:106-111 so future readers can locate the block definition
  • AC-4: Prefer --force-with-lease over raw force in the documented example
  • AC-5: (Optional) Consider whether the hook regex at line 108 should avoid matching inside quoted gh issue/pr bodies — same pattern that trips on secrets/credentials at line 75

Additional context

  • Low priority — agents can rediscover, but documenting saves time
  • Related hook: force-push block is one of several catastrophic blocks in pre-tool.sh lines 68-161
  • AC-5 is a nice-to-have bonus since it's a known hook ergonomics pattern already

Complexity

simple

Activity

  1. added
    documentation
    on Apr 17, 2026
  2. admarble commented on Apr 17, 2026

    @admarble
    ContributorAuthor

    → PROCEED — Document force-push handoff pattern when pre-tool.sh blocks

    Workflow: spec → exec → qa · 5 ACs

    npx sequant run 532
    

    Pure docs update (CLAUDE.md or _shared/references/force-push.md). -q omitted — single-file paragraph addition.

  3. admarble commented on Apr 23, 2026

    @admarble
    ContributorAuthor

    → PROCEED — Single-paragraph docs add. Current assess rule skips spec for docs-labeled issues.

    Workflow: exec → qa · 5 ACs

    ```
    npx sequant run 532 --phases exec,qa
    ```

    ⚠ If #533 lands first, spec phase would be included per new default

  4. admarble commented on Apr 26, 2026

    @admarble
    ContributorAuthor

    → PROCEED — Force-push handoff docs, 5 ACs

    Workflow: spec → exec → qa

    npx sequant run 532
    

    Per #533 merge (243221f), spec phase is now default ON for docs issues — supersedes prior assess (Apr 23). No -q: single-paragraph addition.

  5. added a commit that references this issue on Apr 29, 2026
  6. admarble commented on May 2, 2026

    @admarble
    ContributorAuthor

    Supersedes 3 prior assessments (most recent: 2026-04-26)

    Spec — Implementation Plan

    Complexity: Simple-fix (docs-only) · Scope: ✅ Single new ref doc + 1-line CLAUDE.md pointer · Workflow: spec → exec → qa (no -q)

    Acceptance Criteria with verification

    • AC-1: .claude/skills/_shared/references/force-push.md documents the !-prefix handoff pattern + CLAUDE.md points to it. (Manual review)
    • AC-2: Ref doc states bypass attempts (CLAUDE_HOOKS_DISABLED=true inside Bash) don't work — env-var read happens at harness level. (Manual review)
    • AC-3: Ref doc cites pre-tool.sh:106-111. (Manual review)
    • AC-4: Example uses --force-with-lease, not raw --force. (Manual review)
    • AC-5: (Optional, deferred to follow-up) Hook regex anchoring at pre-tool.sh:108 to avoid matching inside quoted issue/PR bodies. Out of scope for this docs-only PR.

    Implementation outline

    1. New ref doc (.claude/skills/_shared/references/force-push.md, ~30-40 lines): pattern, why bypass fails, line-reference, --force-with-lease example, when force push is legitimate.
    2. CLAUDE.md pointer (1 line under a new "Hooks" section).
    3. Follow-up issue for AC-5 (separate hook + regression test PR).

    Design Review (simple-fix scope)

    Q1 — Where: .claude/skills/_shared/references/ (existing pattern, alongside prompt-templates.md and subagent-types.md). CLAUDE.md gets a pointer — every agent reads it.

    Q3 — Pattern: Same shape as existing reference docs in _shared/references/ — short, scannable, code-example-led. No new abstractions.

    Key decisions

    • Ref doc + pointer over inline-in-CLAUDE.md: keeps CLAUDE.md scannable; matches the existing _shared/references/ pattern. Issue body itself proposes this structure.
    • Defer AC-5: changing the hook regex needs regression tests for 4 force-push variants — that's a hook PR, not docs. Issue tags AC-5 as "(Optional)" / "nice-to-have bonus." Will file a follow-up.

    Conflict risk

    None — no active worktrees, no overlap with recently-merged PRs (#555 / #554 touched assess-related files only).

    Open questions

    • AC-5 deferred per Open Questions (above). User can flip to "include AC-5 in this PR" if they prefer scope expansion.
  7. admarble commented on May 3, 2026

    @admarble
    ContributorAuthor

    Exec — Implementation Complete

    Branch: feature/532-docs-document-force-push-handoff-pattern-when-
    PR: #563 · Commit: f6fbf1e

    AC Coverage

    AC Status Evidence
    AC-1: Document handoff pattern ✅ Met New .claude/skills/_shared/references/force-push.md + CLAUDE.md pointer
    AC-2: Bypass attempts won't work ✅ Met "Why bypass attempts fail" section explains env-var read order
    AC-3: Reference pre-tool.sh:106-111 ✅ Met Cited in intro + Reference section
    AC-4: --force-with-lease example ✅ Met Used in code block + dedicated paragraph on rationale
    AC-5: (Optional) Regex anchoring 🔄 Deferred Follow-up — hook + regression tests, separate PR

    Files Changed

    • .claude/skills/_shared/references/force-push.md (new, 38 lines)
    • CLAUDE.md (+4 lines under new "Hooks" section)

    Checks

    • npm run lint — passes (0 warnings)
    • npm run build — passes (tsc clean)
    • npm test — skipped (docs-only, no source code touched)

    Quality Plan Alignment

    N/A — no quality plan in spec comment (simple-fix tier).

    Live exercise of the documented pattern

    The commit + PR + comment flow exercised the documented workaround multiple times:

    1. Commit message contained the literal command strings → blocked by force-push regex. Workaround applied: write to file, commit with -F.
    2. PR body contained the same → applied same file workaround.
    3. This very issue comment was initially blocked by a different regex — line 248's commit check tripped on the same self-referential pattern (the comment body references the commands documented).

    Both regexes have the same root cause as AC-5: non-anchored matching on tool-input strings. AC-5 covers the force-push regex; this exec also surfaced that line 248 has the identical bug. Filing the AC-5 follow-up will be valuable — recommend expanding its scope to cover both regexes.

    Self-Evaluation

    • Worked as expected: Mostly — the hook collisions on the meta-content were friction but the documented workaround held up across all three.
    • Test coverage confidence: N/A (docs-only).
    • Weakest part: The "Why bypass attempts fail" explanation is best-effort. If a future agent confirms the env-var read happens differently, the doc should be corrected.
    • Honest assessment: No regressions possible — pure additive docs. AC-5 deferral aligned with spec; recommend expanding its scope to also cover the line-248 collision discovered during this exec.
  8. admarble commented on May 3, 2026

    @admarble
    ContributorAuthor

    QA Review for Issue #532

    Branch: feature/532-docs-document-force-push-handoff-pattern-when-
    PR: #563 · Commit: f6fbf1e

    AC Coverage

    AC Status Evidence
    AC-1: Document handoff pattern MET New .claude/skills/_shared/references/force-push.md + CLAUDE.md pointer
    AC-2: Bypass attempts won't work MET "Why bypass attempts fail" section — env-var read at harness level
    AC-3: Reference pre-tool.sh:106-111 MET Cited in intro and Reference section
    AC-4: --force-with-lease example MET Code example + rationale paragraph
    AC-5: (Optional) Regex anchoring N/A (deferred) Per spec — separate hook + regression test PR

    Coverage: 4/4 mandatory ACs MET. AC-5 deferred (allowed).

    Quality Metrics

    Metric Value
    Files changed 2
    Lines added +42
    Type issues 0
    Deleted tests 0
    Lint ✅
    Build (tsc) ✅
    CI (typecheck, validate-skills, validate-plugin) ✅

    Code Review

    Strengths:

    • Concise, scannable doc (~38 lines)
    • Concrete --force-with-lease example, not just prescription
    • "Why bypass attempts fail" pre-empts the CLAUDE_HOOKS_DISABLED=true wrong-turn
    • Legitimate vs. not-legitimate table prevents misreading as "force pushes are fine"
    • Self-referential regex caveat honestly names the known bug
    • CLAUDE.md pointer names the symptom string (HOOK_BLOCKED: Force push) so search hits it

    Issues: None.

    Suggestions:

    • Live exec also surfaced that pre-tool.sh:248 (the no-changes-guard regex) has the same class of bug — non-anchored match on tool-input strings, tripping on quoted body content. Recommend expanding the AC-5 follow-up to cover both regexes.

    Risk Assessment

    • Likely failure mode: A future agent ignores the doc and tries the bypass anyway. Mitigation: doc explicitly says it won't work and explains why. Beyond that, the hook itself remains the enforcement (intentional).
    • Not tested: N/A — docs-only. The doc was field-tested during exec via three real self-referential hook collisions; the documented workaround held up each time.

    Verdict: READY_FOR_MERGE

    All mandatory ACs satisfied. Diff is +42 lines docs-only, lint/build/typecheck green. Doc was exercised against the live hook during exec.

    Next Steps

    1. Wait for remaining CI to complete.
    2. Merge.
    3. File AC-5 follow-up with expanded scope (force-push + no-changes-guard regexes).
  9. added 2 commits that reference this issue on May 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions