Skip to content

basou: Keep the order of imported Claude Code transcripts when their birth times change - #378

Merged
takashi-matsuyama merged 1 commit into
mainfrom
import/fork-order-store
Oct 19, 2026
Merged

takashi-matsuyama merged 1 commit into
mainfrom
import/fork-order-store

Conversation

@takashi-matsuyama

Copy link
Copy Markdown
Member

Summary

basou import claude-code groups the transcripts of a conversation by their first record and lets the one whose file was created first keep the shared records, importing each later one without them (#377). Birth times are read from the files on every import, and they can change after one (a restore from a backup, a copy to another disk). When they flipped:

  • the session holding the shared records was re-derived without them, while the fork, whose session begins after its copies, did not take them back, so they were counted in no session;
  • between two forks, when the earlier one grew after a later one had copied from it, the earlier one dropped the records the later one copied, and nothing reported it.

This change:

  • Transcripts already imported keep the order in which their sessions begin, within the places they hold by birth time (a stable sort: two sessions that begin together keep their birth order).
  • A transcript not imported yet keeps its place by birth time, unless it holds a copy of a record an imported fork's session counts; then it forked from that fork and goes after it. The files are read for this only when such a transcript sits before an imported fork.
  • The session store is loaded, with the existing symlink checks, before the conversations are indexed, and passed to the shared import core, so it is still read once per run.
  • docs/spec/terminal-and-import.md section 14.2 and the Unreleased changelog entry describe the rule and the three cases the order still cannot recover from the files.

No on-disk format change.

Tests

New cases in packages/cli/src/commands/import.test.ts (forked transcripts):

  • birth times flip after an import: nothing is re-derived, and both sessions' events are unchanged;
  • the original grows after the flip and keeps the shared records;
  • a fork of a fork flips with its parent, and the parent grows: it keeps what the later fork copied;
  • --force after the flip re-creates the sessions in the order they began;
  • a fork and an original both imported with the shared records (as an earlier basou left them) are still re-derived by birth order;
  • a new fork of an imported original, and a new fork of a fork, are placed by birth time;
  • a transcript not imported yet whose restored birth time falls before an imported fork it copied from goes after that fork (in two orders);
  • an original not imported yet stays before an imported fork it holds nothing of.

Checks run: pnpm -r build, pnpm typecheck, pnpm lint, pnpm lint:lang, pnpm lint:paths, pnpm test, pnpm test:scripts.

…birth times change

The import groups the transcripts of a conversation and lets the one whose
file was created first keep the shared records. Birth times are read on
every import, so when they changed after an import (a restore from a
backup, a copy to another disk) and the order flipped, the session holding
the shared records was re-derived without them, and the fork, whose
session begins after its copies, did not take them back: they were counted
in no session. The same happened between two forks when the earlier one
grew after a later one had copied from it.

The transcripts already imported now keep the order in which their
sessions begin, in the places they hold by birth time. A transcript not
imported yet is still placed by its birth time, unless it holds a copy of
a record an imported fork's session counts: then it forked from that fork
and goes after it, so a restore cannot place it where it would take that
fork's records again. The session store is loaded before the conversations
are indexed, still once per run. The spec and the changelog name the cases
the order still cannot recover from the files.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant