The Claude Agent SDK embeds Claude Code’s agent loop into applications, providing tools like web search and MCP connections without manual tool definition. It automatically persists session transcripts to the local file system, but this is unsuitable for stateless deployments like Lambda functions where each invocation is a disposable instance. The MongoDB Claude SDK Session Adapter solves this by implementing the SDK’s SessionStore interface to mirror every conversation turn to MongoDB in real time. This enables cross-environment continuity, resilience to host failures, and auditability under existing access controls, without requiring a separate system for agent memory. The adapter can be configured with a few lines of code, making agent sessions portable across any instance with access to the MongoDB cluster.
Context
Claude Agent SDK automatically persists agent session transcripts to the local file system, which is unsuitable for stateless deployments like serverless functions or distributed systems. The MongoDB Session Adapter provides a durable, centralized session store that works across instances.
Approach / What changed
A MongoDB adapter that implements the Claude Agent SDK’s SessionStore interface, mirroring session transcripts to MongoDB in real time. Configured by passing a MongodbSessionStore instance in ClaudeAgentOptions with a few lines of Python code (TypeScript support planned for January 2027).
Takeaways
1
The MongoDB Session Adapter implements the Claude Agent SDK’s SessionStore interface to persist agent session data in MongoDB, enabling cross-environment continuity across different instances.
2
Session entries are written to MongoDB as they occur, not batched or cached locally, providing resilience to host failures or container rescheduling mid-conversation.
3
Session transcripts stored in MongoDB can be retained under existing access controls, backup policies, and data retention rules, eliminating the need for a separate audit system.
FAQ
How do I configure the MongoDB Session Adapter?
Configure it by passing a MongoDB session store instance in ClaudeAgentOptions. The Python example shows creating a session store with a MongoDB URI and setting it in the options. That's it.
What happens if a host crashes during a conversation?
The adapter writes each session entry to MongoDB as it occurs. If a host crashes, the session state up to the last completed step is preserved, and any instance can resume from that point.
Is TypeScript support available?
The adapter is currently available in Python, with TypeScript support planned for January 2027.
Compare two places to keep Claude's working state: curated files on your own machine versus a durable session store or isolated cloud computer, and learn which one fits your deployment.
Keep reading
Related reading
The Good Stuff
Paid picks we use ourselves. Links carry a referral code — a subscription through one earns us a commission at no extra cost to you.