[BUG]

Resolved 💬 13 comments Opened Aug 3, 2025 by guiramos 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 ↗

This issue has 13 comments on GitHub. Read the full discussion on GitHub ↗