intermediatetypescript
Context Window Checkpoint
Persist agent state at a natural pause point so a future invocation can resume without replaying the full history.
Code
import { createCheckpoint, loadCheckpoint } from '@dcyfr/ai';
// --- At pause point ---
const checkpoint = createCheckpoint({
goal: 'Refactor auth module',
completedSteps: [
'Read src/auth/jwt.ts — found missing expiry validation',
'Updated jwt.ts with validateExpiry() call',
],
openQuestions: [
'Does refreshToken flow also bypass expiry check?',
],
keyFacts: {
affectedFiles: ['src/auth/jwt.ts', 'src/auth/refresh.ts'],
breakingChange: false,
},
});
await checkpoint.save('auth-refactor-session-1');
// --- On next invocation ---
const state = await loadCheckpoint('auth-refactor-session-1');
console.log('Resuming:', state.goal);
console.log('Open questions:', state.openQuestions);How it works
Checkpoints are the antidote to context degradation in long-running tasks. Rather than keeping 50k tokens of history, save a structured state object at natural pause points. The next invocation loads the checkpoint and resumes from a clean, high-signal context.