v2/docs/wiki/session-persistence.md
Claude Code provides sophisticated session persistence that goes beyond simple conversation history. It maintains complete development environment state including background processes, file contexts, permissions, and working directories.
| Command | Description | Example |
|---|---|---|
claude --continue | Continue the most recent conversation | claude --continue |
claude --resume | Resume a specific session (interactive selection) | claude --resume |
claude --resume <id> | Resume a specific session by ID | claude --resume abc123-def456 |
claude --session-id <uuid> | Start with a specific session ID | claude --session-id my-custom-id |
Background tasks started with run_in_background: true persist across sessions:
# Example: Server started in one session
python3 -m http.server 8080 # bash_3
# After --continue or --resume:
# - Process still running
# - Shell ID preserved (bash_3)
# - Can check output with BashOutput tool
# - Can kill with KillBash tool
Verified Test Results:
Claude remembers which files have been accessed:
# Files read with Read tool
# Files edited with Edit tool
# Files created with Write tool
# All remembered across sessions
Test Example:
# Session 1: Create a marker file
claude> Write test-session-marker.txt
# Session 2: Claude knows about the file without re-reading
claude --continue
claude> "What's in test-session-marker.txt?"
# Claude can reference it from memory
# Current working directory preserved
# Environment state maintained
# Path contexts remembered
Permissions granted in one session carry over:
# First session: Approve Bash tool for git commands
# Subsequent sessions: No re-approval needed for same patterns
The BashOutput tool maintains read positions:
# First check of bash_6
BashOutput(bash_6) → Shows lines 1-10
# Second check (even after session resume)
BashOutput(bash_6) → Shows only NEW lines 11-20
# Prevents duplicate output display
Sessions are stored locally on the machine (exact path varies by OS):
~/.config/claude/ or similar{
"sessionId": "abc123-def456",
"startTime": "2025-08-11T22:00:00Z",
"lastActive": "2025-08-11T22:27:00Z",
"messages": [...],
"backgroundTasks": {
"bash_3": {
"command": "python3 -m http.server 8080",
"status": "running",
"pid": 295416,
"outputPosition": 1234
}
},
"fileContext": {
"read": ["file1.txt", "file2.js"],
"modified": ["config.json"],
"created": ["test-marker.txt"]
},
"permissions": {
"approvedTools": ["Bash(git:*)", "Edit"],
"directories": ["/workspaces/project"]
}
}
# Monday: Start development
claude
> Start npm run dev in background
> Start docker-compose up in background
> Work on features...
> Exit (servers keep running)
# Tuesday: Continue work
claude --continue
> Check status of npm run dev # Still running!
> Show docker logs # Can see all output
> Continue development...
# Start a long build
claude
> Run build script in background
> Exit for lunch
# Return and check progress
claude --continue
> Check build output # See what happened while away
> Build completed? Check exit code
# Complex debugging session
claude
> Set up monitoring in background
> Create test files
> Run diagnostics
> [System crash/need to leave]
# Resume exactly where left off
claude --resume
> All background monitors still running
> Test files still in context
> Continue debugging from exact point
DO:
--continue for same-day work continuity--resume when you need a specific past session--session-idDON'T:
# Before ending a session, check background tasks
/bashes # List all background tasks
# Clean up if needed
"Kill all background tasks except the dev server"
# Or selectively
"Kill bash_1 and bash_2 but keep bash_3"
# Create a session marker for complex work
"Create SESSION_NOTES.md with current context"
# Helps both you and Claude remember the context
"Update SESSION_NOTES.md with progress"
You can resume the same session multiple times:
# Original work
claude --session-id project-main
# Branch 1: Try approach A
claude --resume project-main
# Work on approach A
# Branch 2: Try approach B
claude --resume project-main
# Work on approach B
# Both branches have the same starting context
Even if a session is partially corrupted:
Claude Code automatically manages sessions:
# Check if process still exists
ps aux | grep <command>
# If process died, restart it
"Restart the dev server that was in bash_3"
# Try continue instead
claude --continue
# List recent sessions
claude --resume # Interactive selection
# Start fresh if needed
claude # New session
# Permissions may expire for security
# Simply re-approve when prompted
# Or use --dangerously-skip-permissions for development
The following features have been tested and verified:
✅ Background Task Persistence
python3 -m http.server 8080 as bash_3ps aux✅ Shell ID Preservation
✅ Incremental Output
✅ File Context Memory
✅ Multiple Background Tasks
Last updated: August 2025 Verified with Claude Code latest version