Skip to content

feat(cli): let a plugin hook refuse a file write on every host #1342

Backlog

Description

@blafourcade

Problem to solve

A plugin hook cannot refuse a file write on every host the CLI targets. The first consumer is the aidd-pm spec lock: a write to a spec whose state on disk says it is frozen must be refused before it lands, whatever the host (docs/ARCHITECTURE.md now allows this level: refuse by the file's state on disk, never by judging the written content).

Today the CLI only carries PreToolUse as authored:

  • Claude Code, Codex, Cursor and Copilot receive it, but hooks/lib/host.cjs returns no event for it on any host, so every hook parses raw stdin itself.
  • Antigravity skips it with a warning (unmapped event 'PreToolUse' skipped).
  • OpenCode and Kilo drop it silently: the generated bridge only wires SessionStart, Stop and PostToolUse.
  • No CLI code knows any host's deny protocol, and no PreToolUse payload is captured for any host.
  • plugins/aidd-context/skills/08-hook-generate/references/hosts.md documents deny protocols that the vendor docs contradict (14 points, listed below), and omits Kiro.

Proposed solution

Extend the one hook interface every framework hook already speaks (cli/assets/hooks-runtime/host-*.cjs, shipped as hooks/lib/host.cjs), so a hook is written once and refuses a write on every host.

Interface

  • readEvent() returns { event: "PreToolUse", files: [{ path }], cwd, ... } for a call that is about to write. files holds every file the call will touch, as absolute paths, path only (no content fields). A multi-file patch gives several entries. A tool that writes nothing gives files: [].
  • New export refuse(reason): prints the host's documented deny for the current PreToolUse event, through the mechanism where reason reaches the model. It does nothing on any other event. That no-op is part of the contract and is tested, because hooks rely on it.
  • Write tools are recognised by each adapter, not by the hook's matcher. Hook authors omit the matcher (or list neutral intent) and filter on files. The CLI does not translate matchers. Reason: each host names its write tools differently (Write/Edit, apply_patch, create/edit, write_to_file/replace_file_content/multi_replace_file_content, Kiro's write category), and adapter-side recognition keeps one definition per host instead of a matcher map per hook.

Per host, from vendor documentation (nothing run yet)

Host Native event Path before the write Deny with reason to the model Confidence
Claude Code PreToolUse tool_input.file_path exit 2 + stderr, or hookSpecificOutput.permissionDecision: "deny" documented
Codex PreToolUse (hooks inert until trusted) parsed from tool_input.command patch text, *** Add/Update/Delete File: lines, several per call. Edit/Write are aliases of apply_patch exit 2, or permissionDecision: "deny" documented
Cursor preToolUse, .cursor/hooks.json UNDOCUMENTED for Write (only afterFileEdit documents file_path) { permission: "deny", agent_message } partly documented
Copilot CLI preToolUse or Claude-style PreToolUse UNDOCUMENTED for create/edit/apply_patch stdout { permissionDecision: "deny", permissionDecisionReason } partly documented
OpenCode in-process JS plugin: V1 tool.execute.before, V2 ctx.tool.hook("execute.before") V1 args.filePath / patchText, V2 path / patchText throw an Error inside the plugin. No exit-code protocol source only
Kilo tool.execute.before (V1 plugin API) args.filePath / patchText throw an Error source only
Antigravity PreToolUse, .agents/hooks.json toolCall.args.TargetFile stdout { decision: "deny", reason } documented. Crash behaviour and IDE firing UNDOCUMENTED
Kiro Pre Tool Use, .kiro/hooks/*.json UNDOCUMENTED exit 2 + stderr partly documented

Work

  1. Probe first. Before any adapter code, capture one real write-call PreToolUse payload per host in a sandboxed run (throwaway HOME and project, free models, chats deleted) into scripts/__tests__/fixtures/hook-payloads/. This settles every UNDOCUMENTED cell above. A host whose payload or deny cannot be captured becomes a stated limit, never a guessed workaround.
  2. Adapters: readEvent maps PreToolUse to files from those fixtures. Codex reuses the existing patch parser. Each adapter implements refuse.
  3. Antigravity: map PreToolUse in its event map instead of skipping it.
  4. OpenCode and Kilo: the generated bridge plugin wires tool.execute.before. It runs the hook command with the same stdin shape the bridge already produces, and throws Error(reason) when the hook refuses. Establish which OpenCode plugin API the bridge targets today. V2 support may be a stated follow-up if the bridge is V1 only.
  5. Kiro: lands after the Kiro target exists.
  6. Correct plugins/aidd-context/skills/08-hook-generate/references/hosts.md with a citation per claim, and add Kiro.
  7. No silent drop: a host that still cannot carry PreToolUse warns at build and is listed in docs/COMPATIBILITY.md.

Acceptance criteria

  • A captured write-call PreToolUse payload fixture exists for each host, or the host is a stated limit with the reason.
  • Per adapter, tests from those fixtures: readEvent returns the right absolute files, including a multi-file patch (Codex, OpenCode and Kilo patchText) and files: [] for a non-write tool.
  • Per adapter, refuse(reason) emits the documented deny, and does nothing off PreToolUse.
  • translate end-to-end tests show the PreToolUse hook in each host's generated config. Antigravity no longer warns, and the OpenCode and Kilo bridges wire the before-hook.
  • Live proof per host, in a sandbox: a hook refuses a write to a frozen file, the file is unchanged, and the model receives the reason. Each proof records host version and invocation.
  • hosts.md matches the vendor docs, with citations.
  • docs/COMPATIBILITY.md lists any host left without PreToolUse, with the reason.

Out of scope

  • Judging written content: refusal reads the file's state on disk only.
  • MultiEdit (absent from the current Claude Code docs) and NotebookEdit (path field undocumented): stated limits.
  • Copilot in VS Code and the cloud agent: weakly documented, stated as a limit unless the probe covers them.

Content type

Plugin, Other (CLI hook runtime)

Additional context

Contradictions between the vendor docs and hosts.md (H) or our previous internal map (P):

  1. P: Antigravity path is toolCall.args.Path. Vendor: TargetFile.
  2. H: Antigravity blocks when the script fails. Undocumented, and a related Google doc says a crash allows.
  3. H: OpenCode and Kilo block with exit 2. Neither has an exit-code protocol: throwing in the plugin is the only deny.
  4. H: OpenCode and Kilo get tool and args on stdin. The hook is an in-process callback: stdin only exists through our generated bridge.
  5. P: OpenCode uses args.filePath and apply_patch. True for V1 and Kilo. V2 uses path and patch, and V1 plugins do not run on V2.
  6. H: Copilot has no matcher. It has an anchored regex on toolName, and Claude-style matchers on PreToolUse.
  7. H: Copilot blocks with exit 2 only. Stdout permissionDecision: "deny" also works, and any non-zero exit denies.
  8. H: Copilot payload is only toolName and toolArgs. Vendor also defines tool_name and tool_input.
  9. P: Cursor writes arrive with tool_input.file_path. Only the matcher value Write is documented. file_path is documented only for afterFileEdit.
  10. P: Cursor has beforeFileEdit. It does not exist in the vendor docs.
  11. P: Codex needs a hand-written apply_patch matcher. Codex already aliases Edit and Write to apply_patch.
  12. H: Codex payload is like Claude's. Codex tool_input is { command: <patch text> }, so paths need patch parsing.
  13. H omits Kiro.
  14. H lists ask for Copilot. The Copilot pages do not confirm it.

Vendor sources:

Code of Conduct

  • I agree to follow this project's Code of Conduct.

Activity

  1. blafourcade commented on Nov 25, 2026

    @blafourcade
    ContributorAuthor

    Antigravity (agy 1.5.17) facts for this issue, probed while relaying its other hook events in #1355:

    • A PreToolUse hook answer of {} denies the call. Empty stdout runs the tool, and {"decision":"allow"} runs it. {"decision":"block"} errors with unsupported hook decision: block. {"decision":"deny","reason":...} denies and shows the reason to the model.
    • A neutral refuse answer therefore has to map to deny with the reason on agy, and silent success has to map to allow.
    • Whether the model then fixes the cause depends on the model. A task-related deny was acted on 3 of 3 times by gpt-oss-120b-medium, gemini-3.8-flash-low and Sonnet. flash-medium, flash-high and opus-thinking did not act. The acting models leave agy on Nov 30, so this needs a re-probe on the models that remain.
    • plugins/aidd-pm/hooks/spec-lock.cjs (feat(aidd-pm): refuse a write to a locked spec before it happens #1343) calls host.refuse, which no adapter defines yet.
  2. blafourcade commented on Nov 26, 2026

    @blafourcade
    ContributorAuthor

    Partly delivered on next: #1370 adds a neutral host.refuse(reason) on Claude Code, Codex, Copilot, Antigravity and Kiro, mapped from captured payloads, and #1378 brings it to OpenCode and Kilo. Cursor remains: its probe was blocked by the account's usage limit, so no PreToolUse capture exists. Left open for Cursor.

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

    No labels
    No labels

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions