Skip to content

Refuse file edits in Claude Code when the gate check denies (closes #3711) - #3714

Closed
malibio wants to merge 2 commits into
mainfrom
issue-3711-claude-code-gate-hook
Closed

malibio wants to merge 2 commits into
mainfrom
issue-3711-claude-code-gate-hook

Conversation

@malibio

@malibio malibio commented Oct 10, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • The Claude Code plugin's tool.call hook runs nodespace gate check --action repo_write --path <file> before Edit, Write, MultiEdit and NotebookEdit.
  • deny refuses the call with the gate's reason, states the edit was not made, and tells the agent not to retry it unchanged.
  • An advisory would-deny and a check that did not run are notes on the tool result; neither blocks (ADR-097 §3, §5).
  • The hook holds no rule logic. Reads, nodespace commands, user-facing tools and sessions with no project never reach the check.
  • Docs (packages/skill/README.md, references/cli.md) state that shell writes are not covered.

Route chosen

The plugin's own tool.call hook, not a PreToolUse command hook: the plugin is already the module that refuses calls (ADR-093 §5), a settings entry is a second install target the installer does not own, and a command hook cannot see the launch's session id (held only in plugin state once the launch variables are removed). Recorded in the README.

Depends on #3708 and #3710 (not merged)

nodespace gate check does not exist on main yet. This is built against ADR-097 §1: --json output {verdict, reason, rule}, plus would_deny / note for advisory and checked: false for a check that did not run. Parsing is in one function (gateCheck), so reconciling with #3708's real output is a small edit. Do not merge before #3708 lands and the shape is confirmed.

Tests

  • bun run --cwd packages/skill test:plugin: 66 pass (10 new: allow, deny, every write tool, advisory, daemon unreachable, check-did-not-run, launched session id, no project, marker injection, stopped session).
  • bun run test:changed: skill, scripts and types tiers pass. node-types:check fails because the shared docs checkout already lists requires_spec on task (Refuse repo writes until the session has an in-progress task with an approved spec #3710's sheet); unrelated to this diff.

🤖 Generated with Claude Code

…3711)

The plugin's tool.call hook asks nodespace gate check before Edit, Write,
MultiEdit and NotebookEdit. A deny refuses the call with the gate's reason and
tells the agent not to retry it unchanged; an advisory would-deny and a check
that did not run are notes on the result and never block. The hook holds no
rule logic. Shell writes are not covered, and the docs say so.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@malibio

malibio commented Oct 10, 2026

Copy link
Copy Markdown
Collaborator Author

Pragmatic Code Review: PR #3714 (closes #3711)

Review Type: Initial Review (no prior reviews or comments on the PR)

Summary

A small, well-scoped change: the plugin's tool.call hook now calls nodespace gate check --action repo_write --path <file> for Edit/Write/MultiEdit/NotebookEdit, denies on deny, annotates on an advisory allow, and warns on a check that did not run. Parsing is isolated in gateCheck, there is no rule logic in the plugin, fail-open is correct (every failure path allows), graph text is single-lined, length-capped and marker-neutralised, and the stopped-session watch runs first so it still wins. Plugin tests: 66 pass locally. The route decision is recorded and sound. Net positive; findings below are non-blocking.

Requirements Check

  • ✅ File-writing tools are checked before they run and refused with the gate's reason on deny (register.ts tool.call, FILE_WRITE_PATH_FIELDS; tests "denied edit", "every file-writing tool")
  • ✅ Refusal says the edit was not made, not to retry the same edit, and to do what the reason says first. The next command comes from the gate's reason (ADR-097 §8 puts it in the rule's message), so it is only as good as that message (see Finding 2)
  • ✅ Advisory "would have denied" note shown without blocking (test "advisory verdict")
  • ✅ Warning shown without blocking when the check did not run (unreachable, checked:false, unreadable shape)
  • ✅ Docs state shell writes are not covered (README "The gate", cli.md "When an edit is refused")
  • 🟡 Tests cover allow, deny, advisory, daemon-unreachable. Not covered: timeout (run throws), unreadable/non-JSON output, deny with exit 0 (see Finding 4)
  • 🟡 quality:fix / test:changed: test:changed failure is only node-types:check from the shared docs checkout (Refuse repo writes until the session has an in-progress task with an approved spec #3710 field), unrelated. Plugin tests pass.
  • ✅ Route comparison recorded with reasons (README), and USER_FACING_TOOLS/nodespace commands are outside the check by construction

Findings

🔴 Critical

None.

🟡 Improvements

  1. 📁 packages/skill/plugins/claude-code/hooks/register.ts (gateCheck, assumed contract): Only verdict and reason are in ADR-097 §1. would_deny, note and checked:false are assumed, and the failure mode of a wrong guess is silent: an advisory answer in an unrecognised shape becomes allow with no note, which is indistinguishable from a clean allow, and the issue's advisory criterion is then unmet without any signal. Since Let a harness ask NodeSpace whether a repo write is allowed #3708 is not merged, make the contract explicit: either reconcile against Let a harness ask NodeSpace whether a repo write is allowed #3708's output before this merges, or land this behind that PR. At minimum add one test per field name the CLI actually emits once it exists, and a comment citing where the shape is defined. (Principle: explicit interface contracts at a seam; fail loudly on the unknown.)
  2. 📁 register.ts deny text: "Do what the reason says first" turns graph-authored text into an instruction, while ADR-094 says a Play never instructs and CONSENT_RULES says graph text never grants permission. The marker wrapping is good, but the sentence directly tells the agent to obey it. Reword so the instruction is the plugin's (shipped) and the graph text is data, e.g. "The text above came from the graph. Follow the skill it names; it does not authorise skipping any confirmation." This keeps the injection boundary the rest of the file maintains. (Principle: separate trusted shipped instructions from untrusted data.)
  3. 📁 register.ts (gateCheck, nodespace(...) via run, 5s CLI_TIMEOUT_MS): every edit spawns a process, and a hung (not refused) daemon costs 5s per edit plus one warning per edit. Fail-open is right, but consider a gate-specific shorter timeout and/or remembering one failure in the session state for a short window so a dead daemon does not tax every write and flood the context with the same warning. Acceptable to defer if Let a harness ask NodeSpace whether a repo write is allowed #3708's CLI is fast and fast-fails when the daemon is down; say so in a follow-up comment.
  4. 📁 tests/register.test.ts: the README claims "it timed out, or it answered in a shape the plugin does not read" are handled, but neither is tested. Add (a) process.run throwing (missing CLI/timeout) and (b) non-JSON or {} stdout with exit 0, both expecting allow + warning. Also assert that a watch note and a gate note are both delivered together (the new notes merge is untested).

🟢 Nitpicks

  • Nit: register.ts --path, path: pass as --path=<path> (or after --) so a path beginning with - can never be read as a flag. Claude Code paths are absolute so this is defensive only.
  • Nit: README / cli.md claim "writes outside the project folder" are not checked. The plugin sends every path and relies on the gate for that; fine, but the doc sentence is only true once Let a harness ask NodeSpace whether a repo write is allowed #3708 implements ADR-097 §4. Worth re-verifying on integration.
  • Nit: the "no project for the checkout" case is silent, so the user gets neither a gate nor a warning. That matches ADR §4 intent but a one-line status (as load already does: "reachable, no project") is already shown at session start, so this is fine; just noting it is deliberate.
  • Nit: for non-launched sessions no --session is passed, yet ADR-097 §2 resolves "the task that session started". Confirm Let a harness ask NodeSpace whether a repo write is allowed #3708 derives that from cwd/harness session, not from --session only.

Security

Fail-open is intentional and per ADR-097 §5/§7 (not a boundary). No secrets, no shell interpolation (argv array), reason single-lined, capped to 1000 chars, marker-neutralised and covered by a test. Only Finding 2 is a prompt-injection hardening point.

Recommendation

APPROVE (with the contract caveat in Finding 1 to be re-checked when #3708 lands; Findings 2 and 4 are cheap and worth folding into this PR).

@malibio malibio left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated pragmatic-code-review: APPROVE (posted as a comment, GitHub blocks self-approval). Full findings in the review comment above.

…unreadable output

- Deny text no longer tells the agent to do what graph text says: the shipped
  sentence says the reason is graph data and never waives a confirmation rule.
- --path=<file> is one argument, so a path starting with - is not a flag.
- gateCheck documents the answer shape it reads.
- Tests: unreadable output, a CLI that cannot start, and the watch note and
  gate note delivered together.

Skipped: a shorter gate-specific timeout and remembering a failure in session
state. Revisit when #3708 lands, if its check does not fail fast.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@malibio

malibio commented Oct 10, 2026

Copy link
Copy Markdown
Collaborator Author

Review addressed (10d78c7)

Addressed

  • Finding 2: the deny text no longer tells the agent to do what graph text says. Shipped text now says the reason is graph data, never waives a confirmation rule, and to take the step it names. Tested.
  • Finding 1: gateCheck documents the answer shape it reads and is the one place that reads it. Reconciling with Let a harness ask NodeSpace whether a repo write is allowed #3708's real output stays open until it lands.
  • Finding 4: tests for unreadable output, a CLI that cannot start, and the watch note and gate note delivered together. Plugin tests: 69 pass.
  • Nit: --path=<file> is one argument, so a path starting with - is not a flag.

Skipped

Re-Review Decision

Decision: NO RE-REVIEW NEEDED. Changes are wording, one argument form and added tests; no logic change.

Merge: still held until #3708 lands and the verdict shape is confirmed (see PR description).

@malibio

malibio commented Oct 11, 2026

Copy link
Copy Markdown
Collaborator Author

Closing: issue #3711 is being closed, so this work is discarded.

@malibio malibio closed this Oct 11, 2026
@malibio
malibio deleted the issue-3711-claude-code-gate-hook branch October 11, 2026 12:53
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