Recover uncommitted files overwritten or deleted by a coding agent
When Claude Code, Cursor, Codex, or another agent runs git checkout -- ., git clean -fd, or rewrites a file you had not yet staged or committed, git reflog has nothing to restore. If the agent read, edited, or wrote that file earlier in the session, the text is still sitting in the local session transcript on disk.
Why git reflog cannot help here
Git only stores blobs when you run git add or git commit. Working-tree edits made during a long debugging session exist in two places before your first commit:
- The working tree file on disk (which the agent just overwrote or removed).
- The append-only JSONL or SQLite transcript that your coding agent writes locally for every tool call (
Read,Edit,Write,MultiEdit,apply_patch).
Do not delete or clear the agent session yet. Every tool call input and output that touched the file is still in the transcript directory.
Option 1: Recover with deja restore (across 43 agents)
Because deja indexes existing local transcripts on disk the moment you install it, you can install it after the accident and still pull the spans out of the session that overwrote your file:
brew install deja-vu
deja restore internal/store/pool.go
With no flags, deja restore <path> scans every indexed session that recorded an edit on that file path (or basename) and prints the recorded before/after spans in newest-first order:
SPAN WHEN HARNESS SESSION SIZE PREVIEW
1 2026-11-10 13:14 claude 8b2a19d0 2.4 KB func (p *Pool) Acquire(ctx context.Context) (*Conn, error) {
2 2026-11-10 12:58 claude 8b2a19d0 1.9 KB func (p *Pool) releaseLocked(c *Conn) {
3 2026-11-10 11:40 cursor 41f0c82a 4.1 KB type PoolConfig struct { MaxIdle int; IdleTimeout time.Duration }
To inspect or write a specific span to a recovery file without clobbering your working tree:
# Print span 1 to stdout
deja restore internal/store/pool.go --span 1
# Write span 1 to a separate file (refuses to overwrite the source file itself)
deja restore internal/store/pool.go --span 1 -o pool.recovered.go
# Dump all recorded edit spans for the file in chronological order
deja restore internal/store/pool.go --all > pool.all-spans.txt
By design, deja restore never writes directly back over the original path even if you pass -o internal/store/pool.go; it writes to a separate file so you can diff and splice what you need.
Option 2: Extract directly from raw JSONL with jq
If you only want a one-liner against Claude Code's raw JSONL files in ~/.claude/projects/ without installing anything:
# List every Edit / Write tool call that touched pool.go in the current project
jq -r '
.message.content[]?
| select(.type == "tool_use" and (.name == "Edit" or .name == "Write" or .name == "MultiEdit"))
| select(.input.file_path? | tostring | endswith("pool.go"))
| "=== " + .name + " " + .input.file_path + " ===\n"
+ (.input.old_string // .input.content // "")
' ~/.claude/projects/*/*.jsonl
And if the agent only read the file before deleting it (for example via rm or git checkout), the file contents are in the tool_result entries rather than tool_use:
grep -l "pool.go" ~/.claude/projects/*/*.jsonl | xargs jq -r '
.message.content[]?
| select(.type == "tool_result")
| (.content | if type == "string" then . else (.[0].text // "") end)
| select(contains("func (p *Pool)"))
'
For Codex CLI, run the same search against ~/.codex/sessions/*/*/*.jsonl; for other agents, see Where session history lives on disk.
Tracing which session changed a surviving line: deja blame
Sometimes the file is still there, but an agent rewrote a function three hours ago and you want the reasoning or the version right before that edit:
deja blame internal/store/pool.go:42
Unlike git blame, which only sees committed history, deja blame matches the surviving lines against the edit spans recorded by your coding agents and prints the session ID, harness, timestamp, and user prompt that produced the change. From there, deja show <session-id> prints the full transcript.
- Recover a deleted session — what remains when the session file itself was removed or compacted.
- Where session history lives on disk — exact paths for all 43 supported harnesses.
- Auditing what an agent did — inspecting every file read, edit, and shell command after a session finishes.
- CLI reference — full flag reference for
deja restoreanddeja blame.
Found this useful? Star deja-vu on GitHub.