ADR 0005doc/{zh,en}/adr/0005-hook-argument-rewrite.md
ADR 0005: Hooks May Rewrite Tool Arguments, Under a Grant
Status: accepted, 2026-11-16 (decision D3 of the hook model).
Status: accepted, 2026-11-16 (decision D3 of the hook model).
Context
Eight of ten reviewed agents let a hook change a tool call's arguments before it runs: pin a path into the workspace, add a safe flag to a command, redact a secret. None has a deterministic rule when several hooks rewrite: Codex takes whichever hook finished last, Claude Code leaves it unspecified, Gemini, OpenCode and Crush take the last writer (review). Claude Code, Codex and Gemini check the rewritten call again; Crush lets a hook's allow skip approval. Until now Orquelo rejected rewrites: guards could only deny, ask or add notes. A rewrite changes what a call does, so it changes the Host contract.
Decision
- Contract.
guardgains the optional interfaceRewriter(Rewrite(cc, intent) → RewriteDecision{args, deny, reason}, JSON-RPCguard/rewrite). A manifest plugin fills it frompre_toolhooks that answerhookSpecificOutput.updatedInput; within one plugin the hooks run on the same input and the last rewrite in manifest order wins. - Grant. Only instances the operator gives
grants: [rewrite]may rewrite. A rewrite from any other instance is ignored and logged (tool.rewrite_ignored). - Order: a chain. Rewriters run one after another, each on the previous one's arguments: the runtime layer in
usesorder (for every instance in the call chain), then the operator layer inpolicy.hooksorder, so the operator has the last word. - Phases of a tool call. The model's arguments are checked against the tool's schema → the rewrite chain → the final arguments are checked against the schema again → the gate phase (
guard/check,pre_toolverdicts) on the final arguments → approval bound to the digest of the final arguments → the call with the final arguments → result guards. - No relaxing. A rewrite never removes a required approval. If the runtime asked a person to approve this call (
approve:<call key>answered) and the arguments then changed, the Host asks again for the final arguments. The tool name cannot change. - Failure. A rewriter that errors, times out, denies, or returns arguments that fail the schema check refuses the call (
policyrefusal naming the instance). It fails closed. - Visibility. The tool result the model sees ends with a note naming the instances that changed the arguments and the final arguments. The ledger keeps the model's arguments as the call's identity, so a replay after a restart matches; the final arguments go to the log (
tool.rewritten) and the result note.
Consequences
- ◆New optional role method, RPC method and grant; existing plugins are unaffected.
- ◆A rewrite runs again when a call is resumed after a restart, so rewriters should be deterministic for the same input.
- ◆Result rewrites follow the same grant and chain rule (
ResultRewriter,guard/rewrite_result,post_toolupdatedToolOutput): they run before result guards, a failing rewriter withholds the result, and the model is told who changed it. Model calls likewise (ModelGuard, before and after). - ◆Hooks in the gate phase see the final arguments; a manifest hook that both rewrites and gates runs twice when it changed the arguments, once per phase, and once when it did not.