osFoundry 如何在磁碟上找到你的 Claude Code 和 Codex 工作階段,用 Python 重做一遍
~/.claude/projects/-Users-alex-code-shop-api/c5e1a7b2-9d40-4f3e-8b16-2a7c0e9d4f58.jsonl ~/.claude/projects/-Users-alex-code-shop-api/c5e1a7b2-9d40-4f3e-8b16-2a7c0e9d4f58/subagents/agent-<id>.jsonl ~/.codex/state_5.sqlite -> table threads (id, rollout_path, cwd, git_branch, title, …) ~/.codex/sessions/2026/11/04/rollout-2026-11-04T10-00-00-<thread id>.jsonl $ claude --resume…
Claude Code and Codex sessions are stored as JSONL files on disk, with filenames matching the session ID. These files are located within a folder named after the workspace directory. The folder name is a sanitized version of the absolute path, replacing all non-alphanumeric characters with hyphens. The session files contain a list of records, with each line representing a record containing various attributes such as 'type', 'sessionId', 'cwd', 'gitBranch', 'timestamp', and 'version'.
The records also include 'user' and 'assistant' entries, which contain important information like the model used, effort, git branch, and message content. The titles are derived from the 'custom-title' record or, in some cases, from the 'ai-title' record. The JSONL files can be quite large, with the median file size being around 168 MB and the maximum size reaching up to 2.07 GB.
To efficiently process these files, osFoundry reads only the first 80 lines and the last 512 KiB of each file. The script written in Python reads these sessions and extracts the required fields, including the App name, session ID, workspace directory, git branch, and title. The script avoids parsing the entire file and instead focuses on the relevant sections, optimizing the processing time.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.