Skip to content

Claude Code mod: one plan approval when the plugin guard skips the mod's hook (#2007) - #2043

Merged
backnotprop merged 2 commits into
mainfrom
fix/mod-plan-approval-guard
Oct 21, 2026
Merged

backnotprop merged 2 commits into
mainfrom
fix/mod-plan-approval-guard

Conversation

@backnotprop

@backnotprop backnotprop commented Oct 21, 2026 •

Copy link
Copy Markdown
Owner

Fixes #2007

What happened

On Team/Enterprise accounts Claude Code seats its built-in guard cc-plugin-sec-default above the person's plugins, and the guard sends classic.PermissionRequest (and prompt.context) past the mod. The mod's tool.call hook still runs, so the first ExitPlanMode opens the non-blocking review as usual. But the approved second ExitPlanMode is never answered by the mod: the event reaches the plugin's own PermissionRequest command hook (plannotator), which opened a second review server, and Claude Code asked in the terminal as well. The second server was left running.

Fix

  • Mod (controller.ts, plan.ts, launch.ts): when an ExitPlanMode call matches the approval and is passed through, the mod also writes { v: 1, hash, plan, permissionMode?, at } to <data dir>/claude-code-mod/<session>/plan-approvals/<tool use id>.json (folder made owner-only first), and removes it when the call settles. A failed write leaves the call as before.
  • Classic hook (server/mod-plan-approval.ts, wired first in the Claude Code plan path of index.ts): for a main-loop ExitPlanMode PermissionRequest, it takes a record for that session_id whose hash matches the requested plan (the fix(hook): review Claude's plan file, not its stale inline snapshot #1667 plan-file rule, or the inline plan) and whose own plan text hashes to that hash, at most 10 minutes old, from a real plan-approvals folder (lstat, never a symlink) and a file both owned by the hook's user (where process.getuid exists), deletes it (answers once) and prints the same allow the mod gives (updatedInput.plan = approved text, setMode to the reviewer's mode). No server starts.
  • Without the guard the mod answers classic.PermissionRequest first, the command hook never runs, and the record is just written and removed: nothing visible changes for anyone else.

Tests

  • hooks/mod/controller.test.ts: the record is written for the approved call (owner-only folder, exact contents) and removed on settle; nothing recorded for another plan; a failed write keeps the call passing.
  • server/mod-plan-approval.test.ts: the mod's names, path and SHA-256 equal the CLI's; allow once with approved text and mode; the plan file beats a stale inline plan; other plan / session / subagent / tool / event / stale record are left to the classic review; .. session ids; a malformed record beside a good one; a forged record whose plan does not match its hash; a symlinked plan-approvals folder; and the hook as a process: a recorded approval prints the allow and exits with no server, no record still opens the classic review.
  • tests/register.test.ts (engine harness, claude plugin test): the record exists while the approved call runs beneath the mod and is gone after.

Not verified

I could not run a Team/Enterprise Claude Code with the guard seated, so the claim that Claude Code honors the command hook's allow (and dismisses its own dialog) in that setup rests on it being the same classic hook output the non-mod flow already uses. A CLI older than this PR ignores the record, so the double approval stays until the binary is updated. The prompt.context skip (only the Inbox reminder line) is unchanged.

The uid check is not exercised by a test (making a file owned by another user needs root).

Follow-up

uninstall --purge does not remove claude-code-mod/ (it is not in PURGE_OWNED_TOP_LEVEL in packages/server/uninstall.ts), so launch folders and these approval records survive a purge. Not changed here.

The engine harness has one failure that is also on main (the Inbox bundled tool list now includes search); unrelated.

…d's hook (#2007)

On Team/Enterprise accounts Claude Code seats its built-in guard
(cc-plugin-sec-default) above the person's plugins and sends
classic.PermissionRequest past the mod. The approved second ExitPlanMode
then reached the plugin's own PermissionRequest command hook, which opened
a second review server, while Claude Code asked in the terminal too.

While the approved call is in flight the mod now records the approval in
<data dir>/claude-code-mod/<session>/plan-approvals/<tool use id>.json
(owner-only folder) and removes it when the call settles. The classic hook
takes a fresh record for its session whose plan matches and answers the
same allow (approved text, reviewer's mode) without starting a server.
Without the guard the mod answers first and nothing else changes.
@backnotprop
backnotprop merged commit ddddd7c into main Oct 21, 2026
32 checks passed
azaj01 pushed a commit to azaj01/plannotator that referenced this pull request Oct 25, 2026
…p#2159)

The mod's classic.PermissionRequest hook was registered with no matcher, so
under a guard plugin seated above (cc-plugin-sec-default on Team/Enterprise
accounts) Claude Code printed "its classic.PermissionRequest hook was skipped"
at the first permission prompt of any tool. Register it with the matcher
{ tool_name: 'ExitPlanMode' }; the plan approval path is unchanged (backnotprop#2043's
approval record answers a skip there).

Tests: the registration's matcher (bun), and in the engine harness the
approved ExitPlanMode prompt answered by the mod with updatedInput.plan and
setMode while another tool's prompt goes past it; also updates a stale
harness assertion for the Inbox's search action.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant