anthropics / anthropics/claude-agent-sdk-python

continue_conversation=True starts a new session instead of resuming the previous one

Open
#809 0 comments 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

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.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start at the ClaudeAgentOptions continue_conversation handling and the query entry point, then inspect how the most recent session is selected after ResultMessage. Run the minimal repro twice with the same cwd; done means the second run resumes the previous session and reports the same session_id.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
70/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.