anthropics / anthropics/claude-agent-sdk-typescript
File checkpointing snapshots not created in SDK (non-interactive) mode
- Vorherrschende Sprache
- Shell
- Sterne
- 1.8k
- Forks
- 226
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
## Bug Description
`rewindFiles()` always returns `{ canRewind: false, error: "No file checkpoint found for this message." }` when using the SDK programmatically, even though `enableFileCheckpointing: true` is set.
## Root Cause Analysis
After debugging, the root cause is in the CLI (`cli.js`). The file history snapshot creation function (creates per-message snapshots tagged with user message UUIDs) is **only called inside React/Ink interactive UI code paths** (via `useState` setters), and is **never called in SDK (non-interactive) mode**.
The flow requires two functions to work together:
1. **Snapshot creation** (called per user message turn) — creates a snapshot tagged with the user message UUID. This is the initial snapshot that file tracking depends on.
2. **File tracking** (called from Write/Edit/NotebookEdit tools) — adds file backups to the most recent snapshot. But it requires at least one snapshot to exist (`snapshots.at(-1)`), otherwise it logs `"FileHistory: Missing most recent snapshot"` and returns without tracking.
In SDK mode (`isInteractive = false`), the snapshot creation function is never invoked because all its call sites are inside React component render logic. As a result:
- No initial snapshot is created
- File tracking silently fails (no snapshot to attach backups to)
- Snapshot lookup by message UUID finds nothing
- `rewindFiles()` returns "No file checkpoint found for this message."
## Reproduction
```typescript
import { query } from "@anthropic-ai/claude-agent-sdk";
const response = query({
prompt: "Create a file called test.txt with the content 'hello world'",
options: {
enableFileCheckpointing: true,
permissionMode: "acceptEdits",
extraArgs: { "replay-user-messages": null },
},
});
let checkpointId: string | undefined;
let sessionId: string | undefined;
for await (const message of response) {
if (message.type === "user" && message.uuid) {
checkpointId = message.uuid;
}
if ("session_id" in message) {
sessionId = message.session_id;
}
}
// This always fails with "No file checkpoint found for this message."
if (checkpointId && sessionId) {
const rewindQuery = query({
prompt: "",
options: {
enableFileCheckpointing: true,
resume: sessionId,
},
});
for await (const msg of rewindQuery) {
const result = await rewindQuery.rewindFiles(checkpointId);
console.log(result); // { canRewind: false, error: "No file checkpoint found for this message." }
break;
}
}
```
## Environment
- SDK version: 0.2.76 (also verified in 0.2.77)
- Node.js: v22
- OS: macOS
## Evidence
The `iz()` check passes (otherwise error would be "File rewinding is not enabled"), confirming `CLAUDE_CODE_ENABLE_SDK_FILE_CHECKPOINTING` env var is correctly set by the SDK. The issue is purely that snapshot creation is missing from the non-interactive code path.
Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
Bewertung
Dieses Issue wurde noch nicht bewertet.