anthropics / anthropics/claude-agent-sdk-typescript
Feature Request: Add session reset and file checkpointing to v2 Session API
- Lingua principale
- Shell
- Stelle
- 1.8k
- Fork
- 226
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
## Feature Request
### Problem
The `unstable_v2_createSession` API provides a cleaner session lifecycle model but lacks two critical features needed for multi-scenario execution with session reuse:
1. **No conversation reset mechanism** - There's no way to clear conversation history between prompts without closing and recreating the session
2. **No file checkpointing support** - The `rewindFiles()` method available on `Query` objects is not available on `SDKSession`
### Use Case
We're building an evaluation framework that runs multiple test scenarios against Claude Code plugins. For efficiency, we batch scenarios by component and reuse sessions between them. This requires:
1. **Resetting conversation state** between scenarios to prevent cross-contamination
2. **Rewinding file changes** after each scenario to restore the filesystem to a known state
### Current Workaround
We use the v1 `query()` API with:
- `continue: true` + `persistSession: true` for session reuse
- `/clear` command to reset conversation between scenarios
- `Query.rewindFiles(messageId)` for file checkpointing
This works but the v2 session API would be cleaner if it supported these capabilities.
### Proposed Solution
Add to `SDKSession` interface:
```typescript
interface SDKSession {
// Existing methods
readonly sessionId: string;
send(message: string | SDKUserMessage): Promise;
stream(): AsyncGenerator;
close(): void;
// Proposed additions
clear(): Promise; // Reset conversation history
rewindFiles(messageId: string): Promise; // Restore files to checkpoint
}
```
### Alternatives Considered
1. **Close and recreate session** - Defeats the purpose of session reuse (subprocess overhead)
2. **Send `/clear` via `session.send()`** - May work but undocumented for v2 API
3. **Continue using v1 query() API** - Current approach, works but less elegant
### Additional Context
- SDK version: ^0.2.5
- The v2 API already supports hooks via `SDKSessionOptions.hooks`, so capability parity seems intended
- Related: The `unstable_v2_prompt` single-shot API may also benefit from file checkpointing
---
🤖 Created with [Claude Code](https://claude.com/claude-code)
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Valutazione
Questa issue non è ancora stata valutata.