Description
When using permission_mode="bypassPermissions", shell hooks configured in ~/.claude/settings.json are never executed. The PreToolUse hook for AskUserQuestion (configured as a shell command) never fires.
Steps to Reproduce
- Configure a PreToolUse hook in
~/.claude/settings.json:
{
"hooks": {
"PreToolUse": [{
"matcher": "AskUserQuestion",
"hooks": [{"type": "command", "command": "/path/to/hook.sh"}]
}]
}
}
- Run a query that triggers AskUserQuestion:
options = ClaudeAgentOptions(
permission_mode="bypassPermissions",
cli_path="/home/tester/.local/bin/claude",
)
async for msg in query(prompt="Ask my name with AskUserQuestion", options=options):
pass
- The hook script is never called (verified via logs and lack of HTTP calls from the hook).
The same hook fires correctly when running claude --print --dangerously-skip-permissions -p "..." directly.
Expected Behavior
Shell hooks from settings.json should still fire in bypassPermissions mode. Permission bypass should skip the interactive permission prompt, not skip all hooks.
Workaround
Use Python hook callbacks via the hooks parameter in ClaudeAgentOptions instead of shell hooks in settings.json.
Environment
- claude-agent-sdk: 0.1.51
- Claude CLI: 2.1.86
- Python: 3.12
- OS: Linux (Docker)
Description
When using
permission_mode="bypassPermissions", shell hooks configured in~/.claude/settings.jsonare never executed. The PreToolUse hook for AskUserQuestion (configured as a shell command) never fires.Steps to Reproduce
~/.claude/settings.json:{ "hooks": { "PreToolUse": [{ "matcher": "AskUserQuestion", "hooks": [{"type": "command", "command": "/path/to/hook.sh"}] }] } }The same hook fires correctly when running
claude --print --dangerously-skip-permissions -p "..."directly.Expected Behavior
Shell hooks from settings.json should still fire in
bypassPermissionsmode. Permission bypass should skip the interactive permission prompt, not skip all hooks.Workaround
Use Python hook callbacks via the
hooksparameter inClaudeAgentOptionsinstead of shell hooks in settings.json.Environment