Control tool usage and permissions in the Claude Code SDK
canUseTool
callback, hooks, and settings.json permission rules. For complete API documentation, see the TypeScript SDK reference.
canUseTool
- Dynamic approval for uncovered cases, prompts user for permissionquery()
or change it dynamically during streaming sessions.
Mode | Description | Tool Behavior |
---|---|---|
default | Standard permission behavior | Normal permission checks apply |
plan | Planning mode - no execution | Claude can only use read-only tools; presents a plan before execution (Not currently supported in SDK) |
acceptEdits | Auto-accept file edits | File edits and filesystem operations are automatically approved |
bypassPermissions | Bypass all permission checks | All tools run without permission prompts (use with caution) |
acceptEdits
)bypassPermissions
)bypassPermissions
mode - If active, allows all remaining toolscanUseTool
callback - Handles remaining casesbypassPermissions
modebypassPermissions
mode overrides allow rules and canUseTool
canUseTool
callback is passed as an option when calling the query
function. It receives the tool name and input parameters, and must return a decision- either allow or deny.
canUseTool fires whenever Claude Code would show a permission prompt to a user, e.g. hooks and permission rules do not cover it and it is not in autoaccept mode.
Here’s a complete example showing how to implement interactive tool approval:
canUseTool
handles cases not covered by permission rulessettings.json
provide declarative control with built-in bash command parsing. These rules are evaluated before canUseTool
is called. For more details on settings configuration, see the Claude Code settings documentation.
ToolName(pattern)
Bash(npm:*)
matches any command starting with “npm”Read(./src/**/*.ts)
matches TypeScript files in srcWebFetch
blocks all web fetchesrm -rf
or curl | sh
Bash(git:*)
- Matches any git commandBash(npm run test)
- Matches exact commandBash(npm run test:*)
- Matches npm run test:unit, test:integration, etc.