Permission is not a policy file and not a remote setting. It is a function in your process, called with everything needed to decide — which is why it can say yes to write under src/ and no everywhere else.
The callback
const agent = api.agents.create({
runtime: "local",
machine: pc,
model: "gemini-3.5-flash",
mode: "ask",
onPermission: async ({ id, tool, category, args, mode }) => {
if (category === "exec") return "deny";
if (tool === "write" && args.path.startsWith("src/")) return "always";
return "once";
},
});def on_permission(request):
# request: {"id", "tool", "category", "args", "mode"}
if request["category"] == "exec":
return "deny"
if request["tool"] == "write" and request["args"].get("path", "").startswith("src/"):
return "always"
return "once"
agent = api.agents.create(
runtime="local",
machine=pc,
model="gemini-3.5-flash",
mode="ask",
on_permission=on_permission,
)idstringThe tool call's identifier. The same one carried by tool_start and tool_end.
toolstringThe tool's name, e.g. write, bash, write_storage.
categorystringOne of the ten. Six tools compute it from their arguments.
argsobjectWhat the model actually asked for — the path, the command, the filter, the key.
modestringThe mode in force at this moment.
The three answers
| Return | Means |
|---|---|
"once" or true | Allow this call. |
"always" | Allow it, and do not ask again — see Persistence for what that covers. |
"deny", false, null or nothing | Refuse. The tool returns « Refused by the user. » and the loop continues. |
It goes back to the model as a failed tool result, and the agent is told not to retry a refused tool but to adapt or explain. So denying is a normal way to steer a run, not a way to break it.
The order things are decided in
read,memoryandtaskare allowed outright. The callback is not called.- In plan mode, everything else is refused outright. The callback is not called.
send,publish,moneygo to the callback — in every mode, every time.- In full mode, everything else is allowed.
- A remembered « always » for this call is honoured.
- In auto,
writeis allowed. - Otherwise the callback is called.
It is announced both ways
onEvent: (e) => {
if (e.type === "permission") console.log("asking", e.tool, e.category, e.args);
if (e.type === "permission_result") console.log("answered", e.decision); // "once" | "always" | "deny"
}def on_event(event):
if event["type"] == "permission":
print("asking", event["tool"], event["category"], event["args"])
if event["type"] == "permission_result":
print("answered", event["decision"]) # "once" | "always" | "deny"The permission event is emitted before your callback is awaited, so an interface can show the prompt while the promise is pending — which is exactly how a human-in-the-loop UI is built: the event paints the dialog, the promise resolves when a button is clicked.
Without a callback
Anything that would be asked is refused, with a message saying it needs approval and that no one can approve it. An agent with no onPermission is therefore close to read-only, whatever its mode.
Subagents go through the same one
A subagent's tools reach the parent's callback, with the parent's mode. Delegating is not a way around a permission — task itself is free precisely because everything inside it is not.