claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

[BUG] TypeScript SDK ignores `resume` parameter - session resumption not working

Open salvinoarmati opened this issue 1 year ago โ€ข 7 comments

[BUG] TypeScript SDK ignores resume parameter - session resumption not working

Bug Description

The resume parameter in the TypeScript SDK is completely ignored, breaking session resumption functionality. While the CLI version correctly supports --resume, the TypeScript SDK creates new sessions on every request regardless of the resume parameter.

Environment

  • SDK Version: @anthropic-ai/[email protected]
  • Node.js Version: v23.10.0
  • OS: macOS 15.5 (24F74)
  • Architecture: ARM64 (Apple Silicon)

Steps to Reproduce

  1. Create a Claude session and capture the session ID from the first request
  2. Make a second request using resume: sessionId parameter
  3. Compare the session IDs - they should match but don't

Expected Behavior

Session resumption should work as documented in the CLI:

  • CLI: claude --resume abc123 โœ… Works correctly
  • TypeScript: query({resume: 'abc123'}) โŒ Broken

The TypeScript SDK should honor the resume parameter and continue the existing conversation.

Actual Behavior

  • TypeScript SDK completely ignores the resume parameter
  • New session ID generated on every request
  • Conversation context lost between requests
  • No error or warning indicating the parameter is invalid

Minimal Reproduction

File: minimal-reproduction.js

const { query } = require('@anthropic-ai/claude-code');
const fs = require('fs');
const os = require('os');
const path = require('path');

async function testResumeParameter() {
  console.log('๐Ÿงช Testing Claude SDK Resume Parameter Bug');
  console.log('SDK Version: @anthropic-ai/[email protected]\n');

  // Create temp directory
  const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'claude-resume-bug-'));
  process.chdir(tempDir);
  
  let firstSessionId = null;

  try {
    // STEP 1: First request to get initial session ID
    console.log('๐Ÿ“ค STEP 1: Making first request...');
    
    for await (const message of query({
      prompt: 'Create a file called test.txt with "Hello World"',
      options: { cwd: tempDir, maxTurns: 2, permissionMode: 'acceptEdits' }
    })) {
      if (message.session_id && !firstSessionId) {
        firstSessionId = message.session_id;
        console.log(`โœ… First session ID: ${firstSessionId}`);
      }
      if (message.type === 'result') break;
    }

    // STEP 2: Try to resume with the session ID
    console.log('\n๐Ÿ“ค STEP 2: Attempting to resume session...');
    console.log(`๐Ÿ”— Using resume parameter: ${firstSessionId}`);
    
    let secondSessionId = null;
    
    for await (const message of query({
      prompt: 'Create another file called test2.txt with "Hello Again"',
      resume: firstSessionId, // ๐Ÿšจ THIS SHOULD WORK BUT DOESN'T
      options: { cwd: tempDir, maxTurns: 2, permissionMode: 'acceptEdits' }
    })) {
      if (message.session_id && !secondSessionId) {
        secondSessionId = message.session_id;
        console.log(`๐Ÿ“จ Second session ID: ${secondSessionId}`);
      }
      if (message.type === 'result') break;
    }

    // STEP 3: Check if resume worked
    console.log('\n๐Ÿ“Š RESULTS:');
    console.log(`   ๐Ÿ”— First session:  ${firstSessionId}`);
    console.log(`   ๐Ÿ”— Second session: ${secondSessionId}`);
    console.log(`   ๐Ÿ”„ Sessions match: ${firstSessionId === secondSessionId ? 'โœ… YES' : 'โŒ NO'}`);
    
    if (firstSessionId === secondSessionId) {
      console.log('\nโœ… SUCCESS: Resume parameter works!');
    } else {
      console.log('\nโŒ BUG CONFIRMED: Resume parameter ignored!');
      console.log('   TypeScript SDK is not honoring the resume parameter.');
    }

  } finally {
    // Cleanup
    process.chdir('..');
    fs.rmSync(tempDir, { recursive: true, force: true });
  }
}

// Run the test
testResumeParameter().catch(console.error);

Output:

๐Ÿงช Testing Claude SDK Resume Parameter Bug
SDK Version: @anthropic-ai/[email protected]

๐Ÿ“ค STEP 1: Making first request...
โœ… First session ID: 7fbe2a88-89de-4006-98d7-d8471819f61d

๐Ÿ“ค STEP 2: Attempting to resume session...
๐Ÿ”— Using resume parameter: 7fbe2a88-89de-4006-98d7-d8471819f61d
๐Ÿ“จ Second session ID: 5ae866dc-30fc-4cc4-ae00-766e1aba2792

๐Ÿ“Š RESULTS:
   ๐Ÿ”— First session:  7fbe2a88-89de-4006-98d7-d8471819f61d
   ๐Ÿ”— Second session: 5ae866dc-30fc-4cc4-ae00-766e1aba2792
   ๐Ÿ”„ Sessions match: โŒ NO

โŒ BUG CONFIRMED: Resume parameter ignored!
   TypeScript SDK is not honoring the resume parameter.

Additional Testing

I tested all possible parameter structures to ensure this isn't a parameter placement issue:

  1. โŒ Top-level: query({resume: sessionId, ...})
  2. โŒ In options: query({options: {resume: sessionId}})
  3. โŒ In executableArgs: query({executableArgs: ['--resume', sessionId]})

All approaches failed - session IDs change on every request.

Impact

For Developers:

  • Breaks multi-turn conversations in TypeScript applications
  • Forces workarounds or prevents adoption of the TypeScript SDK
  • No way to maintain conversation context programmatically

For Applications:

  • Cannot build stateful AI assistants
  • Lost conversation history between requests
  • Increased token costs (no context reuse)

Documentation Issues

  1. CLI documentation shows working --resume functionality
  2. TypeScript SDK documentation doesn't mention resume parameter at all
  3. No error/warning when invalid parameters are used
  4. Mismatch between CLI capabilities and TypeScript SDK

Comparison: CLI vs TypeScript

Feature CLI TypeScript SDK Status
--resume sessionId โœ… Works โŒ Ignored Broken
--continue โœ… Works โŒ Not available Missing
Session persistence โœ… Works โŒ Broken Critical

Expected Fix

The TypeScript SDK should:

  1. Honor the resume parameter when provided
  2. Continue existing sessions instead of creating new ones
  3. Update documentation to reflect TypeScript capabilities
  4. Add parameter validation with helpful error messages

Workaround

Currently no workaround exists - session resumption is completely broken in the TypeScript SDK.

Related

This appears to be a fundamental issue with the TypeScript SDK implementation not properly bridging CLI parameters to the underlying Claude API calls.

salvinoarmati avatar Jul 01 '25 02:07 salvinoarmati

@salvinoarmati were you able to find a workaround? This is currently a blocker for my use-case

buremba avatar Jul 15 '25 13:07 buremba

Although session ids are different between the first and second calls, claude can really continue to work with the previous context.

dcalsky avatar Jul 23 '25 14:07 dcalsky

@salvinoarmati @buremba I was stuck on the same issue for days.. finally found out the root cause. This is not a bug in the sdk or the cli. Session is not suppose to be same between messages.

User message 1 -> assistant response (sessionId: 1)
User message 2 -r 1 -> assistant response (sessionId: 2)
User message 3 -r 2 -> assistant response (sessionId: 3) 

When you do -r sessionId claude-code will resume the session and process your prompt but while responding it will create a new sessionId. Now if you want to resume the same session then pass the latest sessionId in resume parameter.

iamgajendra avatar Jul 25 '25 13:07 iamgajendra

CLI: claude --resume abc123 โœ… Works correctly

That is one interesting sessoin id. ๐Ÿ™„ Do we have a filter against AI slop issues? I don't think, they are helping our cause.

Compare the session IDs - they should match but don't

Yes. They also don't in CLI. You hallucinated. :-/

foertel avatar Jul 26 '25 09:07 foertel

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] avatar Dec 04 '25 10:12 github-actions[bot]

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] avatar Jan 04 '26 10:01 github-actions[bot]

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.

github-actions[bot] avatar Jan 13 '26 14:01 github-actions[bot]