ClaudeAgentStorage integration persists messages from the Claude Agent SDK to Acontext automatically. It stores only UserMessage and AssistantMessage in Anthropic format — SystemMessage, ResultMessage, and StreamEvent are used only for session-id resolution.
Quick Start
Session Handling
Auto-discovered session id
By default,ClaudeAgentStorage discovers the session id from the Claude Agent SDK.
When the Claude session id is a valid UUID, Acontext reuses it as the Acontext session id (via use_uuid). This means the Acontext session and the Claude session share the same id, making it easy to correlate them across systems.
If the Claude stream provides a non-UUID session id, it is ignored and Acontext generates its own session id instead.
- Python
- TypeScript
Explicit Acontext session
To correlate the Claude run with a specific Acontext session:- Python
- TypeScript
Options
Include thinking blocks
By default,ThinkingBlock content is omitted from stored messages. To include it as native thinking blocks:
- Python
- TypeScript
thinking content blocks with their signature preserved. When retrieved in Anthropic or Gemini format, they round-trip as native thinking blocks. When retrieved in OpenAI format, thinking content is automatically downgraded to plain text.
The stored message meta will contain "has_thinking": True for observability.
Custom error handling
By default, API errors during storage are logged and swallowed so your message loop is never interrupted. To customize:- Python
- TypeScript
User identifier
Pass auser string to associate the Acontext session with a specific user. This value is forwarded to sessions.create() when the session is first created:
- Python
- TypeScript
What gets stored
| Message type | Stored? | Notes |
|---|---|---|
| UserMessage | Yes | role: "user". String content wrapped as text block. ToolUseBlock skipped (invalid in user role). |
| AssistantMessage | Yes | role: "assistant". model stored in message meta. ToolResultBlock skipped (invalid in assistant role). If error field is set, its value is included in meta.error for observability. |
| SystemMessage | No | Used only for session-id resolution (subtype == "init" in Python, session_id field in TypeScript). |
| ResultMessage | No | Fallback session-id source. |
| StreamEvent | No | Fallback session-id source. |