Repository navigation
fix: follow a Claude Code transcript that moved to another project folder - #27
Merged
Merged
Conversation
Forget and a reset each listed the eight tables keyed by file_id. The next change drops one file's rows as well, so the list lives in one place.
…lder
When a session enters or leaves a worktree, Claude Code moves its
transcript between the two folders' project directories under the same
name. The index took the old path for a deleted transcript and the new one
for a second file of the same session. Session b6dcd6a5 on the author's
machine went into a worktree and back, and ccli ended up with two main rows:
the worktree copy, frozen at 8 turns and now missing, and the live file with
33. log picked the missing one ("the transcript is gone from disk", 8 turns
mostly without cost), and show counted 40 typed prompts instead of 32 and
called the stale copy's $1.26 the main conversation.
A file whose account, session, kind and agent match a vanished row, and
that starts with the bytes the row read, is now taken to be that
transcript. At a new path the row moves to it, as Codex moves already do,
and keeps what it read. At a path that already has a row, the vanished row
is a stale copy: it is dropped and the kept file is read again from the
start, in one transaction, so its replies come back to it. The transfer
ledger follows the file in both cases.
Rejected: picking the present file when a session has two main rows. It
would show the right turns but keep the doubled prompt count and leave the
copy's replies on a row nobody sees.
Tested: go test ./... and -race on index and store; on a copy of the live
index one session changed: log lists 33 turns with costs, 32 typed
prompts, total still $53.61.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When a session enters or leaves a worktree (
EnterWorktree/ExitWorktree/claude --worktree), Claude Code moves its transcript between the two folders' project directories under the same file name. The index treated the old path as a deleted transcript and the new path as a second file of the same session.Seen on session b6dcd6a5: it went into the
integrations-polishworktree and back. The index had two main rows, a frozen 8-turn copy (now missing) and the live 33-turn file.logpicked the missing copy ("the transcript is gone from disk"),showcounted 40 typed prompts instead of 32, and the agent tree called the copy's $1.26 the main conversation.Now a file whose account, session, kind and agent match a vanished row, and that starts with the same bytes the row read, is that transcript:
DropCopyremoves it and marks the kept file to be read again from the start, in one transaction.The transfer ledger follows the file either way. The first commit is a refactor that names the per-file tables once.
Test plan
TestMovedTranscriptIsFollowedandTestStaleCopyOfMovedTranscriptIsDropped, both failing before the fixgo test ./...,go test -race ./internal/index ./internal/storelog b6dcd6a5lists 33 turns with costs, 32 typed prompts, total unchanged at $53.61