Skip to main content

Module sessions

Module sessions 

Source
Expand description

Read-side access to Claude Code’s live session registry.

Each running Claude Code process registers itself as ~/.claude/sessions/<pid>.json:

{
  "pid": 31546,
  "sessionId": "a2000338-8786-49e7-be7b-3ffff9ce15e4",
  "cwd": "/path/to/project",
  "startedAt": 1785430795867,
  "version": "2.1.219",
  "kind": "interactive",
  "entrypoint": "claude-desktop",
  "name": "claude-wrapper-85"
}

The sessionId joins a running process to its transcript in crate::history. This module is read-only on purpose, like the other introspection modules. The layout is undocumented Claude Code internal state (observed against CLI 2.1.219) and can change across CLI versions, so parsing is defensive: every typed field is Option-shaped, mistyped values stay in LiveSession::rest, and unknown fields land there too.

§Staleness

Registry files can outlive their process (a crash skips cleanup), so an entry is evidence a session was running, not proof it still is. Liveness is deliberately left to the caller: check LiveSession::pid with a platform-appropriate probe if it matters.

§Example

use claude_wrapper::sessions::SessionsRoot;

let root = SessionsRoot::home()?;
for s in root.list()? {
    println!(
        "{} {} {}",
        s.pid.unwrap_or(0),
        s.name.as_deref().unwrap_or("?"),
        s.cwd.as_deref().unwrap_or("?"),
    );
}

Structs§

LiveSession
One entry from the live session registry.
SessionsRoot
Root directory of Claude Code’s live session registry. Defaults to ~/.claude/sessions; override with SessionsRoot::at for tests or non-default installs.