# Practical ways to use the Claude Agent SDK
โ
Request user approval before dangerous operations with 6 flexible response patterns.
Approval and User Input uses the `canUseTool` callback to intercept dangerous operations and `AskUserQuestion` for requirements gathering.
๐ Title: Handling Approvals and User Input
๐ URL:
๐งฉ Overview
`canUseTool` intercepts each tool call with 6 response patterns: approve, approve with modifications, approve and remember, deny, suggest alternative, or full redirect. `AskUserQuestion` lets Claude present multiple-choice questions to users.
๐ How to use it
Define a `canUseTool` callback that returns `PermissionResultAllow` or `PermissionResultDeny` based on tool name and arguments.
๐ Practical usage
- Build an interactive approval UI that detects file deletions or Bash execution and prompts y/n. You can approve with modifications like "scope all Bash commands to /tmp/sandbox".
- Use "approve and remember" with `updated_permissions` to persist rules in `.claude/settings.local.json`.
- Combine `AskUserQuestion` with `plan` mode to gather requirements before making changes: "Which tech stack for the mobile app?" with multiple choice options.
๐ก Use cases
๐ก Interactive approval UI for dangerous operations
๐ Multi-choice requirements gathering
๐ Persistent approval rule learning
โ ๏ธ Watch out
AskUserQuestion is not available in sub-agents. Questions are limited to 1-4, choices to 2-4. In Python, `can_use_tool` requires streaming mode plus a dummy PreToolUse hook.
#
ClaudeAgentSDK# #
AI#