connection.onControlRequest("can_use_tool", async (request) => {
return {
type: "control_response",
response: {
subtype: "success",
request_id: request.request_id,
response: { behavior: "allow", updatedInput: request.request.input },
},
};
});
The full control request message, narrowed so that
request.request is typed to the specific subtype S.
A complete SDKControlResponse to send back to the CLI.
Handler for an incoming control request from the CLI.
When Claude Code needs permission to use a tool (subtype "can_use_tool"), it sends a control request. By registering a handler via ClaudeAxonConnection.onControlRequest, you can intercept these requests and provide a custom response — for example, showing a UI prompt to the user and returning their selection.
The handler receives the full SDKControlRequest and must return a complete SDKControlResponse. If no handler is registered for a given subtype, the built-in default behavior is used (e.g. auto-allow for can_use_tool).