[BUG] TypeScript SDK ignores `resume` parameter - session resumption not working
[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
- Create a Claude session and capture the session ID from the first request
- Make a second request using
resume: sessionIdparameter - 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
resumeparameter - 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:
- โ Top-level:
query({resume: sessionId, ...}) - โ In options:
query({options: {resume: sessionId}}) - โ 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
- CLI documentation shows working
--resumefunctionality - TypeScript SDK documentation doesn't mention
resumeparameter at all - No error/warning when invalid parameters are used
- 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:
- Honor the
resumeparameter when provided - Continue existing sessions instead of creating new ones
- Update documentation to reflect TypeScript capabilities
- 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 were you able to find a workaround? This is currently a blocker for my use-case
Although session ids are different between the first and second calls, claude can really continue to work with the previous context.
@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.
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. :-/
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.
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.
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.