[BUG]

Status Closed — not planned
Maintainer reply None cached
Activity 13 comments · opened Aug 3, 2025 · closed Jan 10, 2026

Claude Code SDK Session Resumption Not Working

Environment

  • Platform (select one):
  • [x] Other: Claude Code SDK (Python)
  • Claude CLI version: 1.0.67
  • Operating System: macOS
  • Terminal: claude-code-sdk

Bug Description

The Claude Code SDK's session resumption functionality is not working as expected. When attempting to resume a session using either the resume parameter or continue_conversation=True in ClaudeCodeOptions, the SDK creates a new session instead of resuming the existing one.

Steps to Reproduce

  1. Create a new session and capture the session ID
  2. Attempt to resume the session using resume=session_id
  3. Observe that a new session is created with a different ID

Test Script

I've created a test script that demonstrates the issue:

# test_claude_simple.py
import asyncio
from claude_code_sdk import query, ClaudeCodeOptions

async def test_session():
    # 1. Create initial session
    options = ClaudeCodeOptions(
        max_turns=2,
        cwd="/tmp",
        allowed_tools=["Read", "Write", "Bash"]
    )
    
    # First query - new session
    print("1. Creating new session...")
    session_id = None
    async for message in query("Create a test file", options=options):
        if hasattr(message, 'data') and 'session_id' in message.data:
            session_id = message.data['session_id']
            print(f"  ✓ Session created: {session_id}")
            break
    
    if not session_id:
        print("  ✗ Failed to create session")
        return
    
    # Second query - attempt to resume
    print(f"\n2. Attempting to resume session {session_id}...")
    resume_options = ClaudeCodeOptions(
        max_turns=2,
        cwd="/tmp",
        allowed_tools=["Read", "Write", "Bash"],
        resume=session_id,
        continue_conversation=True
    )
    
    async for message in query("Read the test file", options=resume_options):
        if hasattr(message, 'data') and 'session_id' in message.data:
            new_session_id = message.data['session_id']
            print(f"  ✓ New session ID: {new_session_id}")
            if new_session_id == session_id:
                print("  ✓ Session resumed successfully!")
            else:
                print(f"  ✗ Session not resumed - new session created")
            break

if __name__ == "__main__":
    asyncio.run(test_session())

Expected Behavior

  1. First call creates a new session and returns a session ID
  2. Second call with resume=session_id should continue the same session
  3. The session ID should remain the same for both calls

Actual Behavior

  1. First call creates a new session (expected)
  2. Second call creates a completely new session with a different ID
  3. The original session is not resumed

Additional Context

  • The issue is reproducible in both Python SDK and CLI interfaces
  • The session files are created in ~/.claude/projects/ but are not being reused
  • This breaks multi-turn conversation functionality as each turn creates a new session
  • No errors are thrown - the API silently creates new sessions

CLI Test Results

=== Testing Claude CLI Approach ===

1. Creating new session...
✓ First session completed. Session ID: 47c860ef-fcbc-42e4-89a4-0fcfc826ddb4
  Result preview: ...

2. Resuming session 47c860ef-fcbc-42e4-89a4-0fcfc826ddb4...
✓ Resumed session completed. Session ID: e3e10d97-880f-4e40-89f9-0354d8083d17
✗ Session resumption FAILED. Different session ID: e3e10d97-880f-4e40-89f9-0354d8083d17

Impact

This issue makes it impossible to maintain context between multiple turns of conversation, which is a critical feature for many Claude Code SDK use cases.

View original on GitHub ↗

13 Comments

github-actions[bot] · 1 year ago

Found 3 possible duplicate issues:

  1. https://github.com/anthropics/claude-code/issues/2778
  2. https://github.com/anthropics/claude-code/issues/4926
  3. https://github.com/anthropics/claude-code/issues/3188

If your issue is a duplicate, please close it and 👍 the existing issue instead.

🤖 Generated with Claude Code

guiramos · 1 year ago

This is a really important one. Can some from anthropic chime in?

wenod · 1 year ago

This issue is lingering both on CLI and SDK for some time. Appreciate an acknowledgement / Fix!

guiramos · 1 year ago

Totally, and this is a really good and important feature(being able to resume conversations in the cli and in the sdk).

Pleae help us.

guiramos · 1 year ago

Please help @bcherny

sebesdm · 1 year ago

Seeing this issue as well

Edit: As others have mentioned in other threads, the session-id is supposed to change every time, even when resuming. This allows you to return to previous "sessions" and fork. As long as you keep the newest session-id in a linear chat, Claude can chain back through the line of session-ids. So, always keep track of the newest session-id that is created if you want persistent chats. I switched to Json formatting which includes the new session-id in responses.

subashiniunny · 11 months ago

Any update on when this issue will be fixed? When we resume claude code with a valid session id, it does show the conversations from the correct session but the session id is not retained and instead it recreates a new session id (checked by doing /status).

runninghare · 10 months ago

I am also confused by this CLI option:
--fork-session When resuming, create a new session ID instead of reusing the original (use with --resume or --continue)

I have confirmed even I do with a particular session-id without this option. like:

claude --resume a56a316e-1d92-4b07-8a86-ca96ac677ac8

It still creates a new session. Then what's the purpose of "--fork-session"? It's already like that. How can we continue with a previous session without creating new? There are too many sessions in the working space which I don't think are necessary. Very difficult to locate the one we are interested in.

wenod · 10 months ago

Looks like the session resume on CLI has been fixed. No issues now.

runninghare · 10 months ago

yeah. Just tested it with 2.0.22. claude --resume <session id> or claude -c can now continue with the original session without creating new.

github-actions[bot] · 8 months ago

This issue has been inactive for 30 days. If the issue is still occurring, please comment to let us know. Otherwise, this issue will be automatically closed in 30 days for housekeeping purposes.

github-actions[bot] · 7 months ago

This issue has been automatically closed due to 60 days of inactivity. If you're still experiencing this issue, please open a new issue with updated information.

github-actions[bot] · 7 months ago

This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.