anthropics / anthropics/claude-agent-sdk-python

bypassPermissions mode does not execute settings.json shell hooks

Open
#768 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
8.1k
Forks
1.3k
Avg merge
2d 31m
Merged PRs (30d)
1

Description

## 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

1. Configure a PreToolUse hook in `~/.claude/settings.json`:
```json
{
"hooks": {
"PreToolUse": [{
"matcher": "AskUserQuestion",
"hooks": [{"type": "command", "command": "/path/to/hook.sh"}]
}]
}
}
```

2. Run a query that triggers AskUserQuestion:
```python
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
```

3. 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)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.