From claude-commands
Provides procedures for suppressing hook re-fire loops using sentinel files, detecting CR incremental-mode and stale reviews, and handling no-target-PR scenarios.
How this skill is triggered — by the user, by Claude, or both
Slash command
/claude-commands:hook-refire-shortcircuitThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
This skill contains the operational procedures referenced by the mandatory rules in `~/.claude/CLAUDE.md` ("Hook re-fire short-circuit" section). The CLAUDE.md rules are authoritative; this skill provides the implementation detail.
This skill contains the operational procedures referenced by the mandatory rules in ~/.claude/CLAUDE.md ("Hook re-fire short-circuit" section). The CLAUDE.md rules are authoritative; this skill provides the implementation detail.
Sentinel files (~/.tmp/HOOK_<name>) only suppress hook fires when the hook template itself checks for them. Most hooks do NOT check ~/.tmp/. Before creating a sentinel, verify the hook script reads from ~/.tmp/. If it doesn't, the sentinel won't work.
If a UserPromptSubmit hook fires with blank --repo (literal /) and no PR number:
gh pr view --repo / with no populated repo field, flag the harness gap.gh pr view --json number --jq '.number' (no --repo needed inside a repo worktree) as fallback. If nothing, print "No target PR found — exiting." and stop.~/.tmp/./harness: the hook fires on the /harness response itself (self-referential loop). Acknowledge Branch B and stop.Track count in ~/.tmp/HOOK_no_pr_count.json. Cap at 2.
If hook delivers CR CHANGES_REQUESTED on a PR where CR is already APPROVED:
~/.tmp/HOOK_<pr>_stale sentinel/harness immediatelyCheck: gh api .../reviews --jq '[.[] | select(.user.login=="coderabbitai[bot]")] | sort_by(.submitted_at) | last | .state'
If APPROVED → exit silently.
When CR's formal state is COMMENTED but CR posted FINAL VERDICT: APPROVE or READY FOR MERGE (dated after latest formal review) → treat as approval, exit silently.
~/.tmp/HOOK_cr_done_<pr> — if exists, print "PR #N MERGED — sentinel exists, hook suppressed", exit HEARTBEAT_OK. No API calls.echo '{"pr":N,"reviewDecision":"MERGED","suppressed":true}' > ~/.tmp/HOOK_cr_done_<pr>), exit HEARTBEAT_OK./harness from within hook.~/.tmp/HOOK_no_pr_count.json first — if cap reached (>= 2), stop immediately.The CR instruction text is re-injected from the agent's compacted session context, not from a hook script. Hook fires → agent responds → compaction re-embeds pattern → next fire → indefinite cycle. Only /clear breaks it. The no-target-PR hard cap is the durable mitigation.
Problem: If CR posts CHANGES_REQUESTED but never re-reviews after fixes, Branch A fires indefinitely.
commit_sha AND CR posted <!-- Review triggered --> but no new formal review → stuck in incremental mode. Initialize cap at count=1 immediately.commit_sha: null → same treatment.gh api repos/OWNER/REPO/pulls/N --jq '.head.sha' vs gh api .../reviews --jq '... | last | .commit_sha'CAP_FILE="$HOME/.tmp/HOOK_branchA_${PR}.json"
COUNT=$(jq -r '.count // 0' "$CAP_FILE" 2>/dev/null || echo 0)
jq --argjson c $((COUNT + 1)) -n '{count: $c}' > "$CAP_FILE"
@coderabbitai approve.If CR's formal review predates current PR head AND you already posted @coderabbitai all good?, exit silently.
Before waiting for CR response: gh api repos/OWNER/REPO/issues/PR/comments --jq '.[] | select(.user.login=="coderabbitai[bot]" and (.body | contains("Reviews paused"))) | .id'. If returns ID → post @coderabbitai resume first.
The hook's STEP 1-4 assumes CR will post a new formal review as loop-exit gate. Sometimes CR acknowledges with <!-- Review triggered --> without posting formal review. In this state: reviewDecision frozen, gh api .../reviews returns stale review, hook re-executes same Branch A.
Resolution:
commit_sha<!-- Review triggered -->)# Get latest CR review ID:
gh api repos/OWNER/REPO/pulls/N/reviews \
--jq '[.[] | select(.user.login=="coderabbitai[bot]")] | sort_by(.submitted_at) | last | {id, state}'
# Dismiss (replace REVIEW_ID):
gh api repos/OWNER/REPO/pulls/N/reviews/REVIEW_ID/dismissals \
--method PUT -f message="Stale CR verdict — dismissing for fresh re-review" -f event=DISMISS
npx claudepluginhub jleechanorg/claude-commands --plugin claude-commandsDevelops Claude Code hooks to run shell commands or LLM prompts on events like PreToolUse for automations, guardrails, quality checks, and pre-push tests.
Manages Claude Code repository hooks for adding, configuring, troubleshooting, enabling/disabling, and enforcing rules. Delegates to docs-management for official documentation.
Configures Claude Code hooks for lifecycle events like PreToolUse, SessionStart, and automation use cases such as formatting enforcement and permission control.