Skip to content

feat(claude): proactively advise agents on protected branches before they act#622

Merged
NagyVikt merged 1 commit into
mainfrom
agent/claude/proactive-protected-branch-advisory-hook-2026-06-03-23-39
Jun 3, 2026
Merged

feat(claude): proactively advise agents on protected branches before they act#622
NagyVikt merged 1 commit into
mainfrom
agent/claude/proactive-protected-branch-advisory-hook-2026-06-03-23-39

Conversation

@NagyVikt
Copy link
Copy Markdown
Collaborator

@NagyVikt NagyVikt commented Jun 3, 2026

Automated by gx branch finish (PR flow).

…they act

Every gitguardex guard is reactive: skill_guard.py (PreToolUse) and the
pre-commit hook only fire once an agent ATTEMPTS a blocked action, so an
agent on main stages -> commit -> blocked -> tries to branch -> blocked,
bouncing wall to wall. There was no proactive signal of branch state.

Add .claude/hooks/agent_branch_advisor.py, wired into SessionStart and
UserPromptSubmit. On a protected branch (dev/main/master + configured
extras) it injects, via hookSpecificOutput.additionalContext at exit 0, an
advisory naming the branch and the sanctioned `gx branch start` command --
so the agent's first move is to open an isolated worktree.

- Silent on agent/* branches and non-protected branches (zero noise).
- Fail-open: bad stdin, missing/old skill_guard, git error, or GUARDEX_ON=0
  -> no output, exit 0. Always exit 0 (UserPromptSubmit exit 2 rejects the
  prompt -- advise, never block).
- Imports branch/protection predicates from the sibling skill_guard.py so
  the advisory can never disagree with what the guards enforce.
- Added to MANAGED_HOOK_FILES so `gx claude install` distributes it (the
  pre-existing scripts/agent-stalled-report.sh is NOT distributed; the
  advisor deliberately avoids that gap).

Verify: node --test test/claude-install.test.js -> 14/14 (2 new); advisor
runtime silent on agent branch, correct per-event advisory JSON on main,
fail-open on malformed stdin and GUARDEX_ON=0; full suite failing set
unchanged vs main (33 == 33, byte-identical).
@NagyVikt NagyVikt merged commit eecab33 into main Jun 3, 2026
@NagyVikt NagyVikt deleted the agent/claude/proactive-protected-branch-advisory-hook-2026-06-03-23-39 branch June 3, 2026 21:50
NagyVikt added a commit that referenced this pull request Jun 3, 2026
…k hook executable (#623)

PR #622 added agent_branch_advisor.py to the install template but left this
repo's own tracked .claude/settings.json stale -- it shipped the advisory to
other repos via `gx claude install` yet never wired gitguardex's own sessions.
Regenerate settings.json so this repo's agent sessions also get the
SessionStart + UserPromptSubmit advisory.

Also chmod the advisor 0644->0755 to match every sibling managed hook and clear
the `gx claude check` hook-not-executable warning.

Co-authored-by: NagyVikt <nagy.viktordp@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant