Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,39 @@ turns that wrote it before a rename), and by `backfill`.
session's tool edits already explain are left to those edits, the more
precise source.

- **Every worktree of the repository, live or removed.** Most agent work
happens in a worktree that is merged and deleted, so a backfill from any
checkout covers sessions whose cwd was in any worktree `git worktree list`
names, each edit's path made relative to the worktree it was written in.
A removed worktree is recognized **by what it wrote, not where it was**:
worktrees live wherever their creator put them (Ness nests them by branch
name, Claude Code under `.claude/worktrees`, people under `/tmp`), so no
layout is assumed. Each component prefix of the gone cwd is a candidate
root, and wins if the session's substantive lines (12+ characters, not
weak) are in this repository's files at the same relative paths, at the
tip of any branch, tag or worktree — at least 5 distinct lines, and
strictly more than any other prefix. A tie, or less, includes nothing. A
cwd inside another repository's checkout is never considered, whatever it
wrote, and nor is a directory that still exists but is no checkout of this
repository (scratch space, a `cp -r`): only a directory that is gone can
be a worktree git has forgotten. Blobs over 1MB are not read for evidence
and the rest are read 16MB at a time, so a lockfile at hundreds of tips
never sits in memory whole. The repository's tips are read as one tree walk per depth through
`cat-file --batch`, since hundreds of branches share nearly every subtree
(claude-harness: 666 tips, 7s by `ls-tree` per tip, 0.3s this way), and a
transcript is fully parsed only if a `file_path` in its raw text could land
on a path the repository has. On claude-harness this took backfill from 17
turns to 185 across 45 sessions in 39 worktrees, and `src/main/loch.ts`,
written in a since-removed worktree, from 0 to 383 of 439 lines.
The honest limits: a removed worktree whose work never reached any ref
leaves no evidence (nor anything to blame); a session in a removed
worktree that worked only through Bash has no tool edits to be recognized
by, so it is skipped with its commits even when they are still reachable
(recognizing a gone cwd by an exactly-credited commit would fix that, and
is exact by construction); and a squash-merged commit
can't be credited by the commit rule, since its time is the merge's, not
the Bash call's — its lines come from the tool edits or not at all.

Hook-recorded turns are never replaced, and a re-run replaces only earlier
backfilled turns. On this repository it rebuilt 21 turns across 2 sessions,
and with rename-following, files written before the crate moved out of
Expand Down
5 changes: 5 additions & 0 deletions SPEC.md
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,11 @@ formatter re-indenting a turn's code doesn't sever the link.
it is `git:` plus the repository's root commit (the smallest, if there are
several): read once, and immune to anything later history does. Anywhere
else it is `dir:` plus the root's directory name, which is weaker.
- **`root`** is the worktree the session worked in, and paths are relative to
it. It is informational, since matching is by `project` and path: a turn
written in any worktree of a repository blames in every other one once its
lines arrive there. A root may name a directory that no longer exists,
which is how a removed worktree's history survives.

**Store layout:**

Expand Down
Loading
Loading