anthropics / anthropics/claude-agent-sdk-python

ExitPlanMode terminates the current SDK turn — no tool execution possible after exiting plan mode

未關閉
#774 1 則留言 1 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
Python
星號
8.1k
分支
1.3k
平均合併
2 天 31 分鐘
30 天內合併 PR
1

描述

## Issue Description

When using `ClaudeSDKClient` with `permission_mode="bypassPermissions"`, calling `ExitPlanMode` terminates the current query/turn immediately. No further tool calls execute after `ExitPlanMode` within the same turn — the `ResultMessage` is emitted and `receive_messages()` completes.

This means any workflow that enters plan mode, gets user approval, exits plan mode, and then executes actions (Agent dispatch, Bash, Write, etc.) requires a **separate follow-up turn** after `ExitPlanMode`. The model cannot complete a plan-then-execute workflow in a single turn.

## Reproduction

```python
from claude_agent_sdk import ClaudeSDKClient, ClaudeAgentOptions, HookMatcher

options = ClaudeAgentOptions(
cwd="/some/project",
permission_mode="bypassPermissions",
hooks={
"PreToolUse": [
HookMatcher(
matcher="AskUserQuestion",
hooks=[ask_hook], # hook that denies + injects answer
),
],
},
)

client = ClaudeSDKClient(options=options)
await client.connect()
await client.query("""Do these steps in order:
1. Call EnterPlanMode
2. Read a file
3. Ask user for approval via AskUserQuestion
4. Call ExitPlanMode
5. Run: echo HELLO via Bash
""")

# Collect all tool calls
tools = []
async for msg in client.receive_messages():
# ... collect tool names from AssistantMessage blocks
```

### Observed tool sequence:
```
['ToolSearch', 'EnterPlanMode', 'Read', 'AskUserQuestion', 'ToolSearch', 'ExitPlanMode']
```

Step 5 (`Bash`) never executes. The turn completes immediately after `ExitPlanMode`.

### Expected tool sequence:
```
['ToolSearch', 'EnterPlanMode', 'Read', 'AskUserQuestion', 'ToolSearch', 'ExitPlanMode', 'Bash']
```

All 5 steps should complete in a single turn.

## Workaround

Send a follow-up `query()` after the turn completes to continue execution post-plan-mode. This works but requires the caller to detect the plan mode exit and re-prompt.

## Environment

- `claude-agent-sdk==0.1.52`
- Claude CLI 2.1.86
- `permission_mode="bypassPermissions"`
- Python 3.12, Linux (Docker)

## Impact

This affects any SDK-based automation that uses plan mode as part of a multi-step workflow (e.g., design orchestrators that plan architecture then dispatch implementation agents). The plan-then-execute pattern is broken in a single turn.

貢獻指南

這個儲存庫沒有索引到貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。