Skip to content
BENIBIX Learn

canUseTool Callback

Also known as canUseTool, can_use_tool, Agent SDK approval callback, Claude Agent SDK canUseTool

Your own function that decides a tool call when nothing else has.

Think of it like

It is like a helper who calls you to ask, may I do this?

Example

Mia's web app shows an Approve button when the agent wants to write a file. Her canUseTool callback waits for the click.

Why it matters

It is how a person, or your own rules, stay in charge of what the agent does.

Definition

canUseTool is an Agent SDK option that takes your own function for approving tool calls. Claude Code calls it only when no earlier check decides, so it is the last step. It gets the tool name and its input. It returns allow, perhaps with changed input, or deny with a message Claude reads. Apps use it to show their own approval prompt.

Example code

typescript
canUseTool: async (tool, input) =>
  tool === "Bash" ? { behavior: "deny", message: "No shell" }
                  : { behavior: "allow", updatedInput: input }
Deny shell commands, allow the rest.
canUseTool is the last of six checks.

Common mistake

Allowing a tool by name and expecting the callback to see it. Allowed calls never reach it.

Key takeaways

  1. 1
    The last check. After rules and mode.
  2. 2
    allow or deny. With a reason.
  3. 3
    Can change input. updatedInput.