Skip to main content
guidesSource-backed

External Session Storage for Claude Agent SDK Hosts

A practical walkthrough of mirroring Claude Agent SDK session transcripts to external storage: the SessionStore interface, the SessionKey shape, resuming across hosts, reference adapters for S3/Redis/Postgres, and behavior notes.

by JPette1783·added 2026-06-05·
Review first review before installing

Open the source and read safety notes before installing.

Citation facts

Source-backed facts for citing this resource, derived directly from the registry — also available as plain text for AI assistants.

Source URLs
https://code.claude.com/docs/en/agent-sdk/session-storage, https://github.com/JSONbored/awesome-claude/blob/main/content/guides/external-session-storage-for-claude-agent-sdk-hosts.mdx
Safety notes
The store is a mirror, not a replacement: the CLI writes locally first, then append() forwards. sessionStore cannot combine with persistSession: false or enableFileCheckpointing., Mirror writes are best-effort; a failed append emits a system mirror_error message and the query continues, so monitor for mirror_error to detect store data loss., Deleting the main session key must cascade to subagent subkeys; implement delete carefully or treat the backend as append-only.
Privacy notes
Transcripts contain the full conversation, tool inputs, and outputs; store them in a backend you govern with your own encryption, access controls, and retention., The SDK never deletes from your store; retention (TTLs, S3 lifecycle, scheduled cleanup) is your responsibility., Keep backend credentials out of code; pass a pre-configured client to the adapter so you control TLS, region, and pooling.
Author
JPette1783
Submitted by
JPette1783
Claim status
unclaimed
Last verified
2026-06-05

Decision playbook

Review trust signals before you adopt

Signals are present but mixed. Use the checklist below to confirm the source and operational safety for your environment.

Compare context
Selected

0

Current score

63

Baseline

Delta

No baseline selected

No major trust-signal divergence detected in the current selection.

Source and provenance checks

Needs review

Confirm ownership and provenance before trusting install instructions.

  • Source link availableRequired

    Open the canonical repository and verify ownership.

    Done
  • Source provenance statusRequired

    Marked as source-backed.

    Done
  • Metadata reviewed

    No reviewed flag detected in metadata.

    Pending

Safety and privacy checks

Complete

Validate risk disclosures before installation or API wiring.

  • Safety notes presentRequired

    Review the listed safety guidance before running commands.

    Done
  • Privacy notes presentRequired

    Review data handling notes before connecting accounts or secrets.

    Done
  • Trust level risk gateRequired

    Trust level does not block evaluation.

    Done

Package and install checks

Needs review

Check package metadata and artifact integrity signals.

  • Install payload available

    Install or copy payload is available for review.

    Done
  • Package verification flag

    No package verification flag provided.

    Pending
  • Checksum metadata

    No checksum provided for downloaded artifact.

    Pending

Compare-driven decision checks

Needs review

Use compare context to validate trade-offs before adoption.

  • Compare tray has multiple entries

    Add at least one more entry to compare trust differences.

    Pending
  • Baseline comparison available

    No baseline peer selected yet.

    Pending
  • Diverging trust signals identified

    No major trust-signal divergence found.

    Pending

Setup at a glance

Copy & paste

Copy-ready — paste the snippet to get started.

Adoption plan

Balanced adoption plan

Current risk score 24/100. Use staged verification before broader rollout.

Risk 24

Pre-adoption checks

Validate source and review signals before any execution.

  • Confirm source provenanceRequired

    Source URL/provenance metadata is present.

    Done
  • Confirm metadata review state

    No review metadata found; increase manual validation.

    Pending
  • Verify install payload

    Install/config payload exists and can be inspected.

    Done

Security checks

Confirm safety, privacy, and package integrity signals.

  • Review safety notesRequired

    Safety notes are present.

    Done
  • Review privacy notesRequired

    Privacy notes are present.

    Done
  • Verify package integrity metadata

    No package verification/checksum metadata.

    Pending

Rollout

Adopt in controlled steps based on the selected plan.

  • Run in isolated sandbox firstRequired

    Use a constrained sandbox and observe behavior across multiple tasks.

    Pending
  • Roll out graduallyRequired

    Roll out to a small cohort before wider usage.

    Pending
  • Set monitoring and fallback

    Define rollback path and monitor errors after adoption.

    Pending

Evidence readiness

Evidence readiness matrix · balanced

Missing required evidence: Metadata review. Risk score 31.

Risk 31

Source provenance

Present

Source repository/provenance is listed.

Required in this preset

Metadata review

Missing

Review metadata is missing.

Required in this preset

Safety notes

Present

Safety notes are present.

Required in this preset

Privacy notes

Present

Privacy notes are present.

Optional in this preset

Package integrity

Missing

Package integrity metadata is missing.

Optional in this preset

Install payload

Present

Install payload is available.

Required in this preset

Required gaps: Metadata review

Decision timeline

Decision timeline · balanced

Blocking gaps: Check metadata review status. Risk 28.

Risk 28

triage

Confirm source provenanceRequired

Source/provenance metadata is available.

Done

triage

Check metadata review statusRequired

Review metadata is missing.

Pending

verify

Review safety notesRequired

Safety notes are available.

Done

verify

Review privacy notes

Privacy notes are available.

Done

verify

Validate package integrity metadata

Package integrity metadata is missing.

Pending

rollout

Verify install payload and commandsRequired

Install payload is available.

Done

Blockers: Check metadata review status

Prerequisite readiness

Prerequisite readiness

3 prerequisites to line up before setup.

0/3 ready
Install & runtime2General1

Safety & privacy surface

Safety & privacy surface

3 safety and 3 privacy notes across 3 risk areas. Review closely: credentials & tokens, permissions & scopes.

3 areas
  • SafetyCredentials & tokensThe store is a mirror, not a replacement: the CLI writes locally first, then append() forwards. sessionStore cannot combine with persistSession: false or enableFileCheckpointing.
  • SafetyData retentionMirror writes are best-effort; a failed append emits a system mirror_error message and the query continues, so monitor for mirror_error to detect store data loss.
  • SafetyCredentials & tokensDeleting the main session key must cascade to subagent subkeys; implement delete carefully or treat the backend as append-only.
  • PrivacyPermissions & scopesTranscripts contain the full conversation, tool inputs, and outputs; store them in a backend you govern with your own encryption, access controls, and retention.
  • PrivacyData retentionThe SDK never deletes from your store; retention (TTLs, S3 lifecycle, scheduled cleanup) is your responsibility.
  • PrivacyCredentials & tokensKeep backend credentials out of code; pass a pre-configured client to the adapter so you control TLS, region, and pooling.

Safety notes

  • The store is a mirror, not a replacement: the CLI writes locally first, then append() forwards. sessionStore cannot combine with persistSession: false or enableFileCheckpointing.
  • Mirror writes are best-effort; a failed append emits a system mirror_error message and the query continues, so monitor for mirror_error to detect store data loss.
  • Deleting the main session key must cascade to subagent subkeys; implement delete carefully or treat the backend as append-only.

Privacy notes

  • Transcripts contain the full conversation, tool inputs, and outputs; store them in a backend you govern with your own encryption, access controls, and retention.
  • The SDK never deletes from your store; retention (TTLs, S3 lifecycle, scheduled cleanup) is your responsibility.
  • Keep backend credentials out of code; pass a pre-configured client to the adapter so you control TLS, region, and pooling.

Prerequisites

  • The Claude Agent SDK installed for Python or TypeScript.
  • An external backend (S3, Redis, a database) and its client library.
  • A working-directory layout where local transcript writes are available (the store mirrors them).

Schema details

Install type
copy
Troubleshooting
No
Full copyable content
## Overview

By default the Agent SDK writes session transcripts to local JSONL files under
`~/.claude/projects/`. A `SessionStore` adapter mirrors those transcripts to your
own backend (S3, Redis, a database) so a session created on one host can be
resumed on another. This matters for multi-host deployments, durability, and
compliance.

## The SessionStore interface

A `SessionStore` has two required methods, `append` and `load`, plus optional
`listSessions`, `delete`, and `listSubkeys`:

- `append(key, entries)` - called after each batch of transcript entries is
  written locally.
- `load(key)` - called once before the subprocess spawns when `resume` is set;
  returns `null` for an unknown session.

A `SessionKey` is `{ projectKey, sessionId, subpath? }`. `subpath` is set for
subagent transcripts or sidecar files (treat it as an opaque suffix). Implement
the optional methods to enable `listSessions()`, `deleteSession()`, and subagent
resume.

## Quick start

The SDK ships `InMemorySessionStore` for development. Pass a store via
`sessionStore` and resume with the captured session id:

```typescript
import { query, InMemorySessionStore } from "@anthropic-ai/claude-agent-sdk";
const store = new InMemorySessionStore();
let sessionId;
for await (const m of query({ prompt: "...", options: { sessionStore: store } })) {
  if (m.type === "result") sessionId = m.session_id;
}
for await (const m of query({ prompt: "...", options: { sessionStore: store, resume: sessionId } })) {
  /* full context from the first call */
}
```

## Write your own adapter

Implement `append` and `load` against your backend; add the optional methods for
full functionality. Treat entries as opaque JSON-safe values: persist in order and
return them deep-equal from `load` (key reordering is fine, so Postgres `jsonb`
works). The TypeScript repo includes runnable S3, Redis, and Postgres reference
adapters under `examples/session-stores/`, and both SDKs ship a conformance suite
to validate your adapter.

## Behavior notes

- **Dual-write**: the CLI writes locally first; the store mirrors. To make the
  local copy ephemeral, point `CLAUDE_CONFIG_DIR` at a temp dir.
- **Best-effort mirror**: a failed `append` logs, emits a `mirror_error` system
  message, and continues; failed batches are not retried.
- **Compaction**: `getSessionMessages` returns the post-compaction chain; call
  `store.load(key)` for raw history.
- **Fork**: `forkSession` rewrites session ids and message UUIDs rather than doing
  a byte copy.
- **Retention**: the SDK never deletes from your store; you own TTLs and cleanup.

## Source

- Persist sessions to external storage: https://code.claude.com/docs/en/agent-sdk/session-storage

About this resource

Overview

By default the Agent SDK writes session transcripts to local JSONL files under ~/.claude/projects/. A SessionStore adapter mirrors those transcripts to your own backend (S3, Redis, a database) so a session created on one host can be resumed on another. This matters for multi-host deployments, durability, and compliance.

The SessionStore interface

A SessionStore has two required methods, append and load, plus optional listSessions, delete, and listSubkeys:

  • append(key, entries) - called after each batch of transcript entries is written locally.
  • load(key) - called once before the subprocess spawns when resume is set; returns null for an unknown session.

A SessionKey is { projectKey, sessionId, subpath? }. subpath is set for subagent transcripts or sidecar files (treat it as an opaque suffix). Implement the optional methods to enable listSessions(), deleteSession(), and subagent resume.

Quick start

The SDK ships InMemorySessionStore for development. Pass a store via sessionStore and resume with the captured session id:

import { query, InMemorySessionStore } from "@anthropic-ai/claude-agent-sdk";
const store = new InMemorySessionStore();
let sessionId;
for await (const m of query({ prompt: "...", options: { sessionStore: store } })) {
  if (m.type === "result") sessionId = m.session_id;
}
for await (const m of query({ prompt: "...", options: { sessionStore: store, resume: sessionId } })) {
  /* full context from the first call */
}

Write your own adapter

Implement append and load against your backend; add the optional methods for full functionality. Treat entries as opaque JSON-safe values: persist in order and return them deep-equal from load (key reordering is fine, so Postgres jsonb works). The TypeScript repo includes runnable S3, Redis, and Postgres reference adapters under examples/session-stores/, and both SDKs ship a conformance suite to validate your adapter.

Behavior notes

  • Dual-write: the CLI writes locally first; the store mirrors. To make the local copy ephemeral, point CLAUDE_CONFIG_DIR at a temp dir.
  • Best-effort mirror: a failed append logs, emits a mirror_error system message, and continues; failed batches are not retried.
  • Compaction: getSessionMessages returns the post-compaction chain; call store.load(key) for raw history.
  • Fork: forkSession rewrites session ids and message UUIDs rather than doing a byte copy.
  • Retention: the SDK never deletes from your store; you own TTLs and cleanup.

Source

Source citations

Add this badge to your README

Show that External Session Storage for Claude Agent SDK Hosts is listed on HeyClaude. Paste this Markdown into your README — it renders the badge and links back to this page.

Listed on HeyClaude
[![Listed on HeyClaude](https://heyclau.de/badge/guides/external-session-storage-for-claude-agent-sdk-hosts.svg)](https://heyclau.de/entry/guides/external-session-storage-for-claude-agent-sdk-hosts)

How it compares

External Session Storage for Claude Agent SDK Hosts side by side with 3 alternatives on trust, install, platform support, and disclosed safety notes — all from reviewed registry metadata.

Field

A practical walkthrough of mirroring Claude Agent SDK session transcripts to external storage: the SessionStore interface, the SessionKey shape, resuming across hosts, reference adapters for S3/Redis/Postgres, and behavior notes.

Open dossier

A practical walkthrough of loading local plugins in the Claude Agent SDK: the plugins option with type local and a path, what plugins bundle (skills, agents, hooks, MCP servers), verifying loads via the init message, and invoking namespaced plugin skills.

Open dossier

A practical walkthrough of using Agent Skills in the Claude Agent SDK: how skills are discovered from the filesystem via settingSources, the skills option to enable or filter them, tool access, and troubleshooting discovery.

Open dossier

A practical walkthrough of securely deploying Claude Agent SDK applications: the prompt-injection threat model, isolation options (sandbox runtime, containers, gVisor, VMs), least privilege, the proxy credential pattern, and filesystem controls.

Open dossier
Next steps
Trust
Review statusNot reviewedNot reviewedNot reviewedNot reviewed
Package trustPackage not verifiedPackage not verifiedPackage not verifiedPackage not verified
Source provenanceSource-backedSource-backedSource-backedSource-backed
SubmitterJPette1783JPette1783JPette1783JPette1783
Install riskReview firstReview firstReview firstReview first
Notes Safety ✓ Privacy ✓ Safety ✓ Privacy ✓ Safety ✓ Privacy ✓ Safety ✓ Privacy ✓
Brand
Categoryguidesguidesguidesguides
SourceSource-backedSource-backedSource-backedSource-backed
AuthorJPette1783JPette1783JPette1783JPette1783
Added2026-06-052026-06-052026-06-052026-06-05
Platforms
Harness
Source repo
Safety notesThe store is a mirror, not a replacement: the CLI writes locally first, then append() forwards. sessionStore cannot combine with persistSession: false or enableFileCheckpointing. Mirror writes are best-effort; a failed append emits a system mirror_error message and the query continues, so monitor for mirror_error to detect store data loss. Deleting the main session key must cascade to subagent subkeys; implement delete carefully or treat the backend as append-only.The SDK only accepts type: local plugins; to use a marketplace plugin, download it first and point at the local directory. Plugins can bundle hooks, MCP servers, and agents that run with your application's privileges; review a plugin's contents before loading it. Check the system init message's plugin_errors to fail fast in CI when a plugin or a dependency version did not load.The skills option is a context filter, not a sandbox: unlisted skills are hidden from the model but their files remain on disk and are reachable via Read and Bash. Skills are model-invoked; pair them with a tight allowedTools list (and dontAsk where appropriate) so an invoked skill cannot use more tools than intended. The allowed-tools frontmatter in SKILL.md does not apply through the SDK; control tool access with the main allowedTools option.Agents generate actions dynamically and can be influenced by content they process (prompt injection); apply defense in depth, not a single control. Use least privilege: mount only needed directories (prefer read-only), restrict network to specific endpoints, and drop Linux capabilities in containers. Inject credentials via a proxy outside the agent boundary so the agent never sees secrets; do not mount ~/.ssh, ~/.aws, .env, or similar into the agent.
Privacy notesTranscripts contain the full conversation, tool inputs, and outputs; store them in a backend you govern with your own encryption, access controls, and retention. The SDK never deletes from your store; retention (TTLs, S3 lifecycle, scheduled cleanup) is your responsibility. Keep backend credentials out of code; pass a pre-configured client to the adapter so you control TLS, region, and pooling.Bundled MCP servers and hooks can access local files and external services; confirm what a plugin's components reach before deploying it. Plugin skills and commands are sent to the model as available capabilities; keep secrets out of plugin definitions. Loading a plugin from a path you do not control is a supply-chain decision; prefer plugins you have reviewed and pinned.Skill descriptions are loaded so the model can decide when to use them; keep sensitive workflow detail and secrets out of descriptions. Skills sourced from outside your project run their instructions in your sessions; review them before enabling. Skill content is sent to the model provider when a skill is invoked; treat it like any other prompt content.Even read-only code mounts can expose credentials in .env, ~/.git-credentials, ~/.aws, .npmrc, and key files; exclude or sanitize them before mounting. Route egress through a proxy that enforces a domain allowlist and logs requests, so a compromised agent cannot exfiltrate data to arbitrary hosts. The built-in sandbox proxy does not inspect TLS; for stronger guarantees use a TLS-terminating proxy with its CA installed in the agent's trust store.
Prerequisites
  • The Claude Agent SDK installed for Python or TypeScript.
  • An external backend (S3, Redis, a database) and its client library.
  • A working-directory layout where local transcript writes are available (the store mirrors them).
  • The Claude Agent SDK installed for Python or TypeScript.
  • One or more plugin directories on the local filesystem (the parent of skills/, agents/, hooks/, or .claude-plugin/).
  • For marketplace plugins, the plugin downloaded locally so you can provide a path.
  • The Claude Agent SDK installed for Python or TypeScript.
  • SKILL.md files in .claude/skills/ (project) or ~/.claude/skills/ (user).
  • A cwd that points at or below the directory containing .claude/skills/, within the same repository.
  • A Claude Agent SDK application you intend to run beyond a trusted local laptop.
  • Knowledge of which files, endpoints, and credentials the agent legitimately needs.
  • Container, sandbox, or VM tooling appropriate to your isolation choice.
Install
Config
Citations
ClaimUnclaimedUnclaimedUnclaimedUnclaimed
Open 4 picks in the interactive comparison tool

Signals

Loading live community signals…

More like this, weekly

A short, calm digest of reviewed Claude resources. Unsubscribe any time.