View & Recover Claude Code Session History
Claude Code saves full session history in ~/.claude/ — learn how to search terminal logs, recover lost code, and find past solutions with this free guide.
Every Claude Code session — the code it wrote, files it changed, commands it ran — is automatically saved to ~/.claude/ on your machine. This playbook shows you exactly how to navigate that history, search by date or keyword, and recover any snippet of work you thought was gone.
Who it's for: developers who lost code changes when a Claude Code session ended unexpectedly, programmers wanting to find a specific solution Claude generated in a past conversation, team members recovering Claude-generated code that was never committed to version control, power users building searchable archives of their Claude Code interaction history, developers debugging issues by reviewing what Claude changed in previous sessions
Example
"Find the database migration code Claude wrote for me last Tuesday" → Recovery pipeline: scan Claude Code session history files (~/.claude/) for matching timeframe, search conversation logs for code blocks and file modifications, extract and reconstruct the specific code changes, present recovered snippets with file paths and context, and optionally re-apply the changes to current project
New here? 3-minute setup guide → | Already set up? Copy the template below.
# Session History Recovery
## Your Role
You help search through Claude Code session history to recover code, files, or solutions from previous sessions that you may have forgotten to save.
## Session History Location
```markdown
## Where Sessions Are Stored
### macOS/Linux
~/.claude/projects/[project-hash]/sessions/
### Windows
%USERPROFILE%\.claude\projects\[project-hash]\sessions\
### Session File Format
- Each session: JSON file with timestamp
- Contains: Full conversation history
- Includes: All tool calls and responses
```
## Search Strategies
### By Content
```markdown
## Finding Specific Content
### Search for Code
Look for sessions containing:
- Specific function names
- Variable names
- Error messages you remember
- Library names
### Search for Files
Look for sessions where:
- Specific file was created
- Certain file was modified
- Path was mentioned
### Search by Topic
Keywords from your conversation:
- Project names
- Feature descriptions
- Problem descriptions
```
### By Time
```markdown
## Time-Based Search
### Find Sessions From
- Today
- Yesterday
- This week
- Specific date range
### Session Metadata
- Created timestamp
- Last modified
- Project directory
- Duration
```
## Recovery Templates
### Code Recovery
```markdown
## Code Recovery Request
### What I'm Looking For
- **Type:** [Function/Component/Script/Config]
- **Description:** [What it did]
- **Approximate date:** [When you created it]
- **Project:** [Which project if known]
### Clues
- [ ] Remember any function names?
- [ ] Remember the file name?
- [ ] Remember the language?
- [ ] Remember any imports/libraries?
- [ ] Remember any error it was fixing?
```
### Solution Recovery
```markdown
## Solution Recovery
### The Problem You Solved
[Describe the issue]
### When (approximately)
[Date range]
### What You Remember
- The approach that worked
- Commands you ran
- Configuration changes
- Any error messages
### Why You Need It
[Current similar problem]
```
## Session Analysis
```markdown
## Session Summary: [Date]
### Files Touched
| File | Action | Content Preview |
|------|--------|-----------------|
| [path] | Created | [First 100 chars] |
| [path] | Modified | [Change summary] |
| [path] | Read | — |
### Code Written
```language
[Code snippets from session]
```
### Commands Run
```bash
[Bash commands from session]
```
### Key Decisions
- [Decision 1]
- [Decision 2]
### Problems Solved
- [Problem → Solution]
```
## Common Recovery Scenarios
### "I Made a Config File"
```markdown
## Find Configuration
Search for sessions containing:
- Config file patterns (.json, .yaml, .env)
- Settings-related keywords
- Service names mentioned
Recovery approach:
1. Search by date range
2. Look for Write tool calls
3. Find config file content
```
### "There Was a Script"
```markdown
## Find Script
Search for:
- Script execution (bash commands)
- Script creation (Write tool)
- Specific shebang (#!)
Look for:
- Automation keywords
- Cron/schedule mentions
- Input/output paths
```
### "I Fixed That Bug Before"
```markdown
## Find Bug Fix
Search for:
- Error message text
- File that had the bug
- Fix-related keywords (fix, resolve, solve)
Look at:
- Edit tool calls
- Before/after code
- Explanation of fix
```
## Session Export
```markdown
## Export Session Content
### Full Export
- Complete conversation
- All tool calls
- All responses
### Selective Export
- Only code blocks
- Only file changes
- Only commands
- Only solutions
### Format Options
- Markdown
- JSON
- Plain text
```
## Instructions
1. Describe what you're looking for
2. Provide any clues (date, keywords, file names)
3. I'll search through session history
4. Review potential matches
5. Recover the content you need
## Commands
```
"Find the session where I created [file]"
"Search for code that [description]"
"What did I work on [date/time]?"
"Find my solution for [problem]"
"List all sessions for [project]"
"Export the code from session [X]"
```
## Tips for Future Sessions
### Save Important Work
- Copy code to persistent files
- Document solutions in notes
- Use git for code changes
### Make Sessions Findable
- Use descriptive file names
- Mention project names
- Note what problems you're solving
### Regular Cleanup
- Export important sessions
- Note key solutions
- Create reference documents
What This Does
Every Claude Code session — including all code written, files changed, and commands run — is automatically saved to a local directory on your machine. This playbook gives Claude Code a structured way to navigate that history, search it by date or keyword, and extract specific pieces of work you need to recover.
Where Claude Code Stores Session History
Claude Code saves every session as a JSON file containing the full conversation, tool calls, and responses.
macOS / Linux:
~/.claude/projects/[project-hash]/sessions/
Windows:
%USERPROFILE%\.claude\projects\[project-hash]\sessions\
Each session file includes:
- Complete conversation history
- All tool calls (file reads, writes, edits)
- All bash commands that were run
- Timestamps for every action
Quick Start
Step 1: Download the Template
Click Download above and place the CLAUDE.md file in any working folder, then open Claude Code in that folder.
Step 2: Describe What You're Looking For
Give Claude as much context as you can:
- When (approximately) the work happened
- What files were involved
- Keywords from the conversation
- The problem you were solving
Step 3: Search and Recover
Start with a broad search and narrow down:
Find the session where I created [file/solution]
What did I work on last Tuesday?
Search for code that handles [description]
Search Strategies
By date:
What did I work on yesterday?
Find sessions from this week
Show me everything I did on [specific date]
By content:
Find the function that handles authentication
Search for sessions mentioning [library name]
Find where I fixed the [error message]
By file:
When did I create utils.ts?
Find sessions where I modified package.json
Which session created the database schema?
By problem:
Find that bug I fixed with the API timeout
Search for my solution to the CORS error
Find the caching implementation I wrote
Common Recovery Scenarios
Recovering a Config File
If you need to find configuration you set up in a previous session:
Search for sessions containing config file patterns (.json, .yaml, .env)
Look for Write tool calls that created settings files
Find where I configured [service name]
Recovering a Script
Find sessions where I created a bash script
Search for sessions with automation or cron keywords
Find the script that processed [input/output description]
Recovering a Bug Fix
Search for sessions containing [the error message]
Find where I fixed the bug in [file name]
Look for Edit tool calls on [file] with fix-related context
Session Export Options
Once you locate the session, you can export:
- Full export — complete conversation, all tool calls, all responses
- Code only — extract just the code blocks written
- File changes only — show only what was created or modified
- Commands only — list all bash commands that were run
- Solutions summary — key decisions and problems solved
Tips for Making Sessions Findable in the Future
- Save important work immediately — copy critical code to committed files, don't rely on history alone
- Use descriptive file names — makes keyword search far more effective
- Mention project names — give Claude context about which project you're in
- Note what problem you're solving — future searches by problem description are the most reliable
- Export key sessions — for critical solutions, export a markdown summary to your notes