Repository navigation
Description
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.cjsreturns 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,StopandPostToolUse. - No CLI code knows any host's deny protocol, and no
PreToolUsepayload is captured for any host. plugins/aidd-context/skills/08-hook-generate/references/hosts.mddocuments 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.filesholds 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 givesfiles: [].- New export
refuse(reason): prints the host's documented deny for the currentPreToolUseevent, through the mechanism wherereasonreaches 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'swritecategory), 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
- Probe first. Before any adapter code, capture one real write-call
PreToolUsepayload per host in a sandboxed run (throwaway HOME and project, free models, chats deleted) intoscripts/__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. - Adapters:
readEventmapsPreToolUsetofilesfrom those fixtures. Codex reuses the existing patch parser. Each adapter implementsrefuse. - Antigravity: map
PreToolUsein its event map instead of skipping it. - 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 throwsError(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. - Kiro: lands after the Kiro target exists.
- Correct
plugins/aidd-context/skills/08-hook-generate/references/hosts.mdwith a citation per claim, and add Kiro. - No silent drop: a host that still cannot carry
PreToolUsewarns at build and is listed indocs/COMPATIBILITY.md.
Acceptance criteria
- A captured write-call
PreToolUsepayload fixture exists for each host, or the host is a stated limit with the reason. - Per adapter, tests from those fixtures:
readEventreturns the right absolutefiles, including a multi-file patch (Codex, OpenCode and KilopatchText) andfiles: []for a non-write tool. - Per adapter,
refuse(reason)emits the documented deny, and does nothing offPreToolUse. -
translateend-to-end tests show thePreToolUsehook 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.mdmatches the vendor docs, with citations. -
docs/COMPATIBILITY.mdlists any host left withoutPreToolUse, 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) andNotebookEdit(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):
- P: Antigravity path is
toolCall.args.Path. Vendor:TargetFile. - H: Antigravity blocks when the script fails. Undocumented, and a related Google doc says a crash allows.
- H: OpenCode and Kilo block with exit 2. Neither has an exit-code protocol: throwing in the plugin is the only deny.
- H: OpenCode and Kilo get
toolandargson stdin. The hook is an in-process callback: stdin only exists through our generated bridge. - P: OpenCode uses
args.filePathandapply_patch. True for V1 and Kilo. V2 usespathandpatch, and V1 plugins do not run on V2. - H: Copilot has no matcher. It has an anchored regex on
toolName, and Claude-style matchers onPreToolUse. - H: Copilot blocks with exit 2 only. Stdout
permissionDecision: "deny"also works, and any non-zero exit denies. - H: Copilot payload is only
toolNameandtoolArgs. Vendor also definestool_nameandtool_input. - P: Cursor writes arrive with
tool_input.file_path. Only the matcher valueWriteis documented.file_pathis documented only forafterFileEdit. - P: Cursor has
beforeFileEdit. It does not exist in the vendor docs. - P: Codex needs a hand-written
apply_patchmatcher. Codex already aliasesEditandWritetoapply_patch. - H: Codex payload is like Claude's. Codex
tool_inputis{ command: <patch text> }, so paths need patch parsing. - H omits Kiro.
- H lists
askfor Copilot. The Copilot pages do not confirm it.
Vendor sources:
- Claude Code: https://code.claude.com/docs/en/hooks.md, https://code.claude.com/docs/en/tools-reference.md
- Codex: https://developers.openai.com/codex/hooks
- Cursor: https://cursor.com/docs/agent/hooks, https://cursor.com/docs/agent/third-party-hooks
- Copilot: https://docs.github.com/en/copilot/reference/hooks-configuration, https://code.visualstudio.com/docs/copilot/customization/hooks
- OpenCode: https://opencode.ai/docs/plugins/ and the opencode source
- Kilo: https://kilo.ai/docs/automate/extending/plugins
- Antigravity: https://antigravity.google/docs/hooks
- Kiro: https://kiro.dev/docs/hooks/types/, https://kiro.dev/docs/hooks/actions, https://kiro.dev/docs/cli/2x-reference/
Code of Conduct
- I agree to follow this project's Code of Conduct.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsIdeation
Activity
blafourcade commentedon Nov 25, 2026
Antigravity (
agy1.5.17) facts for this issue, probed while relaying its other hook events in #1355:PreToolUsehook answer of{}denies the call. Empty stdout runs the tool, and{"decision":"allow"}runs it.{"decision":"block"}errors withunsupported hook decision: block.{"decision":"deny","reason":...}denies and shows the reason to the model.refuseanswer therefore has to map todenywith the reason on agy, and silent success has to map toallow.plugins/aidd-pm/hooks/spec-lock.cjs(feat(aidd-pm): refuse a write to a locked spec before it happens #1343) callshost.refuse, which no adapter defines yet.blafourcade commentedon Nov 26, 2026
Partly delivered on
next: #1370 adds a neutralhost.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.