Other

How a session picker finds Claude Code and Codex sessions on disk, rebuilt in Python

DEV: claudecode BBT
Other

A German-language walkthrough rebuilds in roughly 150 lines of Python how a session picker locates Claude Code and Codex sessions on disk: JSONL transcripts under ~/.claude/projects and rollout files plus a SQLite index under ~/.codex. The interesting part is performance, because reading 19.4 GB of transcripts would take about 70 seconds while sampling each file's head and tail brought 52 sessions back in 80-150 ms.

Key points

  • Claude Code writes one JSONL transcript per session; the parent folder encodes the working directory, but the encoding is lossy, so read cwd from the records.
  • Files starting with agent- are sub-agent transcripts and should be skipped, since nobody resumes them directly.
  • Reading the first 80 lines and the last 512 KiB was enough to collect folder, branch, title, model and approval mode for all 40 transcripts.
  • A capped readline matters: a pasted image makes a single multi-megabyte line that an unbounded loop would load into memory.
  • Codex's state_<n>.sqlite threads table is a ready-made index; open it with immutable=1 when another app may be holding it.
  • Searching titles, folders, branches, app and ID is instant; searching message text would mean reading 19.4 GB.

Why it matters

Anyone building tooling on top of coding agents can copy the approach: the files are a de facto API, and sampling head and tail instead of parsing whole transcripts is the difference between an instant list and a spinner.

Real-world use

  • A terminal dashboard that lists every Claude Code session across dozens of repositories and jumps straight back into the right folder.
  • A team internal tool that finds the session where a bug was fixed, using folder and git branch instead of scrolling chat history.
  • An IDE extension or launcher that resumes a Codex thread with the model, reasoning effort and approval mode it originally used.
  • A housekeeping script that reports how much disk space old agent transcripts consume per project before archiving them.

This summary was generated by the agent from the original post on DEV: claudecode. The full text and all rights belong to its author and publisher. Go to original

Report this story

Is something wrong with the summary, or do you own this content? Your message comes straight to my inbox.

Type of message

Related stories

Feedback

Found a bug or have an idea? Your message lands straight in my inbox.

Type of message