ExMCP.ACP.Adapters.ClaudeSDK.SessionStore (ex_mcp v1.0.0-rc.0)

View Source

Pure helpers for Claude Code's SDK session store.

Claude Code persists conversations as JSONL files under CLAUDE_CONFIG_DIR/projects/<project-key>. The project key and metadata extraction in this module intentionally follow the official Claude Agent SDK helpers so the ACP adapter can expose session/list and session/delete without shelling out to Node.

Summary

Functions

Resolves the Claude config directory from adapter options, environment, or ~/.claude.

Deletes a persisted Claude session by UUID.

Copies a persisted session transcript to a new Claude session UUID.

Returns ACP SessionInfo maps for Claude Code sessions.

Returns SDK-shaped metadata for sessions visible from the given options.

Returns the official SDK project key for a cwd.

Reads decoded JSONL transcript entries for a persisted session.

Types

opts()

@type opts() :: keyword() | map()

Functions

config_dir(opts \\ [])

@spec config_dir(opts()) :: String.t()

Resolves the Claude config directory from adapter options, environment, or ~/.claude.

delete_session(session_id, opts \\ [])

@spec delete_session(String.t(), opts()) :: :ok | {:error, term()}

Deletes a persisted Claude session by UUID.

When :cwd or :dir is supplied, deletion is restricted to that project and its worktrees. Without a cwd, all project directories under the configured Claude store are searched.

fork_session(session_id, opts \\ [])

@spec fork_session(String.t(), opts()) :: {:ok, String.t()} | {:error, term()}

Copies a persisted session transcript to a new Claude session UUID.

This implements ACP session/fork for the disk-backed SDK store. The copied transcript is rewritten with the new session id where common Claude JSONL id fields are present, while message UUIDs are preserved so clients can still refer to replayed history.

list_acp_sessions(opts \\ [])

@spec list_acp_sessions(opts()) :: {:ok, [map()]} | {:error, term()}

Returns ACP SessionInfo maps for Claude Code sessions.

list_sessions(opts \\ [])

@spec list_sessions(opts()) :: {:ok, [map()]} | {:error, term()}

Returns SDK-shaped metadata for sessions visible from the given options.

Supported options:

  • :claude_config_dir - explicit Claude config directory
  • :env - environment map or keyword list, checked for CLAUDE_CONFIG_DIR
  • :cwd / :dir - restrict sessions to the matching project directory
  • :include_worktrees - include Git worktrees for the requested cwd, default true
  • :offset / :limit - optional in-memory pagination

project_key(path)

@spec project_key(String.t()) :: String.t()

Returns the official SDK project key for a cwd.

read_session_messages(session_id, opts \\ [])

@spec read_session_messages(String.t(), opts()) :: {:ok, [map()]} | {:error, term()}

Reads decoded JSONL transcript entries for a persisted session.