历史文件找回
claude-code-history-files-finder
by daymade
扫描Claude Code在~/.claude/projects的会话历史,按关键词定位旧会话、恢复被删代码或文件,并追踪跨会话修改记录与工具操作轨迹。
误删代码或想追溯改动时,它能直接从 Claude Code 会话历史里捞回文件内容,跨会话恢复尤其省心。
安装
claude skill add --url github.com/daymade/claude-code-skills/tree/main/claude-code-history-files-finder文档
Claude Code History Files Finder
Extract and recover content from Claude Code's session history files stored in ~/.claude/projects/.
Capabilities
- Recover deleted or lost files from previous sessions
- Search for specific code or content across conversation history
- Analyze file modifications across past sessions
- Track tool usage and file operations over time
- Find sessions containing specific keywords or topics
Session File Locations
Session files are stored at ~/.claude/projects/<normalized-path>/<session-id>.jsonl.
For detailed JSONL structure and extraction patterns, see references/session_file_format.md.
Core Operations
1. List Sessions for a Project
Find all session files for a specific project:
python3 scripts/analyze_sessions.py list /path/to/project
Shows most recent sessions with timestamps and sizes.
Optional: --limit N to show only N sessions (default: 10).
2. Search Sessions for Keywords
Locate sessions containing specific content:
python3 scripts/analyze_sessions.py search /path/to/project keyword1 keyword2
Returns sessions ranked by keyword frequency with:
- Total mention count
- Per-keyword breakdown
- Session date and path
Optional: --case-sensitive for exact matching.
3. Recover Deleted Content
Extract files from session history:
python3 scripts/recover_content.py /path/to/session.jsonl
Extracts all Write tool calls and saves files to ./recovered_content/.
Filtering by keywords:
python3 scripts/recover_content.py session.jsonl -k ModelLoading FRONTEND deleted
Recovers only files matching any keyword in their path.
Custom output directory:
python3 scripts/recover_content.py session.jsonl -o ./my_recovery/
4. Analyze Session Statistics
Get detailed session metrics:
python3 scripts/analyze_sessions.py stats /path/to/session.jsonl
Reports:
- Message counts (user/assistant)
- Tool usage breakdown
- File operation counts (Write/Edit/Read)
Optional: --show-files to list all file operations.
Workflow Examples
For detailed workflow examples including file recovery, tracking file evolution, and batch operations, see references/workflow_examples.md.
Recovery Best Practices
Deduplication
recover_content.py automatically keeps only the latest version of each file. If a file was written multiple times in a session, only the final version is saved.
Keyword Selection
Choose distinctive keywords that appear in:
- File names or paths
- Function/class names
- Unique strings in code
- Error messages or comments
Output Organization
Create descriptive output directories:
# Bad
python3 scripts/recover_content.py session.jsonl -o ./output/
# Good
python3 scripts/recover_content.py session.jsonl -o ./recovered_deleted_docs/
python3 scripts/recover_content.py session.jsonl -o ./feature_xy_history/
Verification
After recovery, always verify content:
# Check file list
ls -lh ./recovered_content/
# Read recovery report
cat ./recovered_content/recovery_report.txt
# Spot-check content
head -20 ./recovered_content/ImportantFile.jsx
Limitations
What Can Be Recovered
✅ Files written using Write tool ✅ Code shown in markdown blocks (partial extraction) ✅ File paths from Edit/Read operations
What Cannot Be Recovered
❌ Files never written to disk (only discussed) ❌ Files deleted before session start ❌ Binary files (images, PDFs) - only paths available ❌ External tool outputs not captured in session
File Versions
- Only captures state when Write tool was called
- Intermediate edits between Write calls are lost
- Edit operations show deltas, not full content
Troubleshooting
No Sessions Found
# Verify project path normalization
ls ~/.claude/projects/ | grep -i "project-name"
# Check actual projects directory
ls -la ~/.claude/projects/
Empty Recovery
Possible causes:
- Files were edited (Edit tool) but never written (Write tool)
- Keywords don't match file paths in session
- Session predates file creation
Solutions:
- Try
--show-editsflag to see Edit operations - Broaden keyword search
- Search adjacent sessions
Large Session Files
For sessions >100MB:
- Scripts use streaming (line-by-line processing)
- Memory usage remains constant
- Processing may take 1-2 minutes
Security & Privacy
Before Sharing Recovered Content
Session files may contain:
- Absolute paths with usernames
- API keys or credentials
- Company-specific information
Always sanitize before sharing:
# Remove absolute paths
sed -i '' 's|/Users/[^/]*/|/Users/username/|g' file.js
# Verify no credentials
grep -i "api_key\|password\|token" recovered_content/*
Safe Storage
Recovered content inherits sensitivity from original sessions. Store securely and follow organizational policies for handling session data.
相关 Skills
Word文档
by anthropics
覆盖Word/.docx文档的创建、读取、编辑与重排,适合生成报告、备忘录、信函和模板,也能处理目录、页眉页脚、页码、图片替换、查找替换、修订批注及内容提取整理。
✎ 搞定 .docx 的创建、改写与精排版,目录、批量替换、批注修订和图片更新都能自动化,做正式文档尤其省心。
PDF处理
by anthropics
遇到 PDF 读写、文本表格提取、合并拆分、旋转加水印、表单填写或加解密时直接用它,也能提取图片、生成新 PDF,并把扫描件通过 OCR 变成可搜索文档。
✎ PDF杂活别再来回切工具了,文本表格提取、合并拆分到OCR识别一次搞定,连扫描件也能变可搜索。
PPT处理
by anthropics
处理 .pptx 全流程:创建演示文稿、提取和解析幻灯片内容、批量修改现有文件,支持模板套用、合并拆分、备注评论与版式调整。
✎ 涉及PPTX的创建、解析、修改到合并拆分都能一站搞定,连备注、模板和评论也能处理,做演示文稿特别省心。
相关 MCP 服务
文件系统
编辑精选by Anthropic
Filesystem 是 MCP 官方参考服务器,让 LLM 安全读写本地文件系统。
✎ 这个服务器解决了让 Claude 直接操作本地文件的痛点,比如自动整理文档或生成代码文件。适合需要自动化文件处理的开发者,但注意它只是参考实现,生产环境需自行加固安全。
by wonderwhy-er
Desktop Commander 是让 AI 直接执行终端命令、管理文件和进程的 MCP 服务器。
✎ 这工具解决了 AI 无法直接操作本地环境的痛点,适合需要自动化脚本调试或文件批量处理的开发者。它能让你用自然语言指挥终端,但权限控制需谨慎,毕竟让 AI 执行 rm -rf 可不是闹着玩的。
EdgarTools
编辑精选by dgunning
EdgarTools 是无需 API 密钥即可解析 SEC EDGAR 财报的开源 Python 库。
✎ 这个工具解决了金融数据获取的痛点——直接让 AI 读取结构化财报,比如让 Claude 分析苹果的 10-K 文件。适合量化分析师或金融开发者快速构建数据管道。但注意,它依赖 SEC 网站稳定性,高峰期可能延迟。