read-claude-code-history
Reads, searches, and exports local Claude Code history without resuming work. Covers recent session inventory, exact session timelines, verbatim human input including queued mid-turn prompts, full-event keyword search, hybrid recall when wording changed, end-state triage, and deleted-file recovery across active Claude homes plus registered archives. Use whenever the user asks what they or Claude said, wants a Claude Code session ID or original context, remembers prior work vaguely, needs an old file from a transcript, or must prove what a Claude session contained before continuing it. Also owns the only Kimi CLI surface, via its Kimi inventory and search flags. For Codex history use read-codex-history; when the request names no platform at all or spans providers, start at local-conversation-history.
1How It Works & Mechanism
Implemented as 6 local Python CLIs (list_local_history / read_claude_session / extract_user_messages / analyze_sessions / history_index / recover_content), respectively covering inventory, exact session reconstruction, human input export, keyword search, hybrid recall, triage, and file recovery; invoked by the agent according to the SKILL routing table, with resuming old processes explicitly prohibited.
| Recent Claude Code sessions, titles, dates, or IDs | `scripts/list_local_history.py --source claude` |
'Not found' is an expensive answer: full discovery across multiple homes is the foundation of correctness. homes.py enumerates CLAUDE_CONFIG_DIR, ~/.claude, ~/.claude-profiles/*, and ~/.claude-* sibling homes; sources.py then merges archives registered in ~/.claude/history-sources.json; sessions are deduplicated by Session ID and sorted by in-record timestamps rather than mtime.
# CLAUDE_CONFIG_DIR wins first when set, then the default home.
Claude records are processed semantically rather than literally: storage labels (type: user) do not equate to the author; queued commands during busy periods are hidden in attachment.queued_command.prompt (origin.kind: human), and reading only user records misses corrections.
Treat Claude's record labels as storage metadata, not authorship proof.
Optional 'hybrid recall' path (history_index.py recall): Chinese tokenization FTS5 (wangfenjin/simple libsimple, pinned to version v0.7.1 + SHA256 verified download) + Qwen3 embeddings (Apple Silicon MLX), blending BM25 and vector search to resolve semantic recall when 'wording has changed'; not part of the default read-only path.
EMBEDDING_MODEL_ID = "Qwen/Qwen3-Embedding-0.6B"
File recovery (recover_content.py) follows a three-stage gate of 'report-approve-write': a recovery report is first generated against the exact session file, and writing only occurs after manual review of each destination path; directly overwriting the active project tree is prohibited.
First run the recovery report against the exact Session file, review every proposed destination, then write only after the user asked to recover content. Never restore directly over the current project tree.
Kimi CLI history is a live surface of this skill: inventory is handled via list_local_history.py --source kimi, and full-text search via analyze_sessions.py search --kimi, parsing state.json/wire JSONL under ~/.kimi-code (home precedence: --kimi-home > KIMI_HOME > ~/.kimi-code).
Kimi CLI (kimi-code) stores conversations under ``~/.kimi-code/`` (override with ``KIMI_HOME``).
2Core Capabilities
3External Dependencies
| Kind | Dependency / Endpoint |
|---|---|
| cli | git |
| cli | rg/grep(可选路径预过滤) |
| network | github.com 发布物下载(wangfenjin/simple libsimple,固定版本+SHA256 校验,仅混合索引 setup) |
| network | Hugging Face 模型(Qwen/Qwen3-Embedding-0.6B,仅 --download-model 经 mlx_embeddings.load) |
| package | 可选 Python 依赖 chonkie/transformers(分块)与 mlx-embeddings/mlx(Apple Silicon 向量) |
4Recommended Governance & Evidence
- scripts/: Execute local scripts or commands: runs 6 bundled scripts using python3 (pure standard library by default)
- 网络端点: Declared external network access: urllib.urlopen downloads from https://github.com/wangfenjin/simple/releases/download/v0
- 本地工作目录: File read/write and artifact output: extract_user_messages.py writes Markdown/HTML to a user-specified output base path
5Second-Pass Verification
- [ok] libsimple 下载(github.com/wangfenjin/simple)调用点 — history_index.py url 构造 + urlopen;sha256 校验与 _safe_extract_zip 穿越防护真实存在。
- [ok] 无其他网络调用(排除 requests/curl/wget/其他 urlopen) — 全目录扫描仅 history_index.py 引入 urllib.request;其余脚本零网络 import。
- [ok] Kimi 表面真实存在且只读 — list_local_history.py argparse choices 含 kimi;analyze_sessions.py search 有 --kimi/--kimi-home;_core/kimi.py 只解析 state.json/wire.jsonl,无 kimi CLI 调用。
- [ok] read-only 承诺与写盘面核对 — SKILL guardrails 禁止 resume/continue;写盘仅 extract_user_messages(用户给输出基址)、recover_content(报告后批准)、history_index(可选索引库)。
- [unlocatable] Qwen 嵌入模型网络端点 — 静态证据止于 EMBEDDING_MODEL_ID + mlx_embeddings.load(...) 与 ~/.cache/huggingface 路径;HF 实际网络端点由 mlx-embeddings 库行为决定,源码未直写,未运行验证。
- [ok] 能力声明夸大检查(exact timelines/verbatim input/full-event search) — read_claude_session.py 严格解析含 compaction 前记录、extract_user_messages 去噪逻辑(NOISE_USER_PATTERNS/IMG_TOKEN_RE)、analyze_sessions 预算超时显式失败——均有代码与测试佐证。
6Verdict & Scenarios
646d5ca94bdfe86a…