Every tool call the loop is about to run passes through the run’s execution gate, beforeTool,
first (see Concepts). Calls the loop refuses itself never
reach it: arguments it cannot use, an unknown or not-yet-loaded tool, invalid input, or an exhausted
tool-call budget. Inside the API’s gate, plan mode and the check on GitHub writes to repositories
not listed with write refuse a call before anyone is asked to approve it. The gate belongs to the application, never to a
caller: an HTTP request cannot supply one, choose tools, or switch approvals off. The terminal client
uses it to ask before each write. The API uses it for approvals, described here.
Approval rules name tools, by exact name or with * and ? globs. An exact name beats a glob, and
among equal matches the last rule wins. A rule can apply only when certain arguments are present
and non-empty, can make a grant last for a number of seconds (ttl_seconds), or can allow exactly
one call (one_shot).
What does a tool call pass through, in what order, and where can it be refused?Wider than the column here; it scrolls sideways.Drawn from docs/diagrams/governance-stack.mmd, which follows packages/agent/src/run.ts:runAgent (prepare, execute, settle), apps/api/src/routes/chat.ts:chatResponse (the composed beforeTool), apps/api/src/approvals/gate.ts:approvalGate.
On a deployment, the rules come from MCP, where every tool of a hosted MCP server
needs approval unless the server sets "approval": false, and from the built-in github-writes
rule, which allows each GitHub change once. A named agent’s rules apply only to a call no deployment
rule matches. A thread in bypass mode skips the MCP and agent rules but keeps the GitHub rule. Approvals are recorded in thread storage,
so a deployment without it does not offer tools that need one at all.
A waiting call stays inside the gate, so the run pauses without ending and nothing else in the loop
changes.
What happens to a tool call that needs a person's decision?Wider than the column here; it scrolls sideways.Drawn from docs/diagrams/approval-lifecycle.mmd, which follows apps/api/src/approvals/gate.ts:approvalGate, packages/storage/src/approval-store.ts:approvalRepository (grant, request, decide, close, consume), apps/api/src/routes/approvals.ts:approvalsResponse.
Reuse a grant. An approval for the same tool and the same arguments that has not expired is
used again. A one-shot grant is used up atomically, or not at all.
Ask. Otherwise the call joins a pending request for the same tool and arguments, or opens
one, and the stream sends an approval_requiredframe.
Wait. The gate waits until someone decides with POST /v1/approvals/<id>/decide, or until
the rule’s deadline passes (five minutes by default).
Outcome
What happens
Approved
The tool runs.
Approved with edited arguments
The tool runs with the new arguments, validated like the originals.
Denied
The call does not run. The model reads [approval <note or "denied">] tool=<name> rule=<id>.
The deadline passes
The request is closed as denied, with the note timeout. A decision that arrived first still stands.
A one-shot grant was already used by an identical call
The model reads [approval already used] ….
The run is stopped while waiting
The request is closed with the note aborted, and the call is recorded as not run (“Not run: the run was stopped before this call started.”).
Approval storage fails
The run stops, and no tool runs.
Child agents started through delegate are never given a tool that needs approval, so delegation
cannot get around a decision. That includes a tool a named agent’s own approval rules gate.
A named agent’s approval rules only add approvals: one decides a call only when no deployment rule
does, so it can never loosen or replace one, and the built-in rule on GitHub writes always applies.