anthropics / anthropics/claude-agent-sdk-python
continue_conversation=True starts a new session instead of resuming the previous one
- 主要語言
- Python
- 星號
- 8.1k
- 分支
- 1.3k
- 平均合併
- 2 天 31 分鐘
- 30 天內合併 PR
- 1
描述
In the Python Agent SDK, `ClaudeAgentOptions(continue_conversation=True)` does not resume the previous session after restarting the script.
A new `session_id` is created on every run, even when:
- the same script is used
- the same `cwd` is used
- the previous run fully completes and reaches `ResultMessage`
According to the docs, this option should continue the most recent session in the directory.
## Minimal repro
```python
import asyncio
from pathlib import Path
from claude_agent_sdk import query, ClaudeAgentOptions, ResultMessage
PROJECT_DIR = Path(__file__).resolve().parent
async def main():
options = ClaudeAgentOptions(
cwd=str(PROJECT_DIR),
continue_conversation=True,
)
result = None
async for message in query(
prompt="Do you remember what we talked about last time?",
options=options,
):
if isinstance(message, ResultMessage):
result = message
print("session_id:", result.session_id)
asyncio.run(main())
```
Steps
Run the script once
Note the printed session_id
Run it again
The second run gets a different session_id
Expected
The second run should resume the most recent session in the same directory.
Actual
A new session is created each time.
貢獻指南
這個儲存庫沒有索引到貢獻指南
評估
這個 Issue 還沒有評估資料。