feat(sessions): session identity — shared resolver, codev session CLI, copy menu and details view

Merged
GR
4d ago
+4385-179

What

Ways to get at what identifies a Claude Code session — its title, full id, account, project path, transcript path and resume command — from the Sessions tab and from a terminal, across every account.

  1. One resolver (src/cli/session-identity.ts) used by the app and by a new CLI.
  2. codev session CLI, next to codev account: list, show, view, self, resume.
  3. Copy actions in the Sessions tab: a right-click menu on a row, and ⌘⇧C for the selected row.
  4. A details view of the same fields, each line click-to-copy, in two forms to try: an overlay (⌘I) and a panel under the row (⌘↓).

Why

  • To hand a session to another Claude Code session you need its title (its /rename name); to read it you need its transcript path; to resume it somewhere else you need the resume command under the right account. Today each of these means digging in ~/.claude.
  • claude -r sees one config directory. CodeV already knows every account, so the CLI can list and resume across all of them.

The resolver

  • src/cli/session-identity.ts holds the history scan, the transcript lookup, the title rule (custom title over generated title), matching by id or title, and the resume command. src/cli/session-identity-fields.ts is the part with no Node imports, so the renderer can import it.
  • The main process now uses the same code for readClaudeSessions, the title rule, buildResumeCommand, findTranscriptPath and copyResumeCommand — one copy, not two. Everything the CLI imports lives in src/cli/, because the CLI is compiled with plain tsc into resources/cli.
  • Behaviour change: the copied resume command now single-quotes the project path (cd '…' && …) instead of double-quoting it, so a path with a space or a $ pastes correctly.

Where a transcript lives (checked, not assumed)

The work started from a suspicion that the app looked for transcripts under the wrong projects/<slug> directory. It does not. A transcript is filed under the slug of the session's own working directory, not under the git common directory that auto-memory uses. Counts from 363 transcripts on one two-account machine:

Where the session startedFiled under its own cwd slug
Repository subdirectory2 of 2
Linked worktree (not a /branch copy)18 of 18
Repository root (not a /branch copy)121 of 121
Not a repository, or the directory is gone205 of 205

The 17 transcripts whose first recorded cwd did not match were all /branch copies, which begin with their parent's records. So the existing lookups are unchanged. The resolver additionally checks that the file exists, and for reading only it can fall back to searching every project directory.

codev session

CommandWhat it does
list [--path <dir>] [--account <name>] [--all | --limit N]Sessions, newest first. --path . = sessions whose project is this directory
show <title | id>Every field, for every matching session
view <title | id> [--last N]The last N things the user and the assistant said (text only)
selfThe session this command is running in
resume <title | id>Resume in the current terminal, under the session's own account
  • list, show, view and self print one line of JSON on stdout (agents are the main consumer); --pretty prints text for people. resume prints a shell command instead (see below). Errors go to stderr. Exit status: 0 found, 1 no match, 2 ambiguous or bad usage. An unknown option is bad usage, not ignored.
  • <title | id> is a full session id, the first four or more hex characters of one (hyphens allowed), or a title — the /rename name or, when there is none, the generated title. Part of a title matches only when nothing matches outright.
  • --path lists every match unless --limit is given; without --path the default is 30 rows.
  • A title is not unique (/branch copies share theirs), so show lists every match, and view / resume list the candidates and exit non-zero instead of picking one.
  • resume prints the command and the codev() shell function evaluates it, so claude is a child of the user's shell and not of the app binary. Stdout carries only the command; a non-zero status evaluates nothing. resume refuses when the transcript or the project directory is gone. A session id must be hex-shaped before any path or command is built from it.
  • self walks parent process ids to the nearest one with a sessions/<pid>.json in any account directory, and requires the file's recorded process start time to equal the live process's, so a leftover file from a reused pid is rejected. A registration with no recorded start time is trusted only when the environment's session id names the same session.
  • view reads back from the end of the file and skips tool calls, tool results, thinking and harness wrapper records.
  • Titles are read by scanning back from the end of the transcript, not by grep: macOS grep took about 1.5 s on one 255 MB transcript; the backward scan took about 0.55 s for all 363.

Sessions tab

  • The copy menu is drawn inside the window, not as a native menu: in Menu Bar mode the window hides when it loses focus, and a native menu could trigger that. Each item shows a shortened preview of what it copies. Arrows, Enter and Esc work; a marked comment shows where a future "Hide session" item goes.
  • ⌘⇧C copies the reference (title + full id) and confirms in the banner. Clipboard writes go through the main process.
  • One SessionDetail component, two thin hosts tagged HOST B (overlay) and HOST C (inline) so that either can be deleted once it is clear which one gets used. ⌘↓ used to behave like plain ↓ (the old handler ignored the modifier); it now opens the inline panel.

Verification

  • npx tsc --noEmit: 0 errors. yarn test: 320 tests pass on the branch with main merged in (which brings the Session Preview change, 1.0.95). Fixtures follow the shape of real transcript and history records, with invented values. Guards were mutation-checked (ambiguity refusal in pickOne, resume and view; the shell function's || return $? in zsh and bash; self's process-start comparison and its refusal of an untied registration; rejection of unknown options; the four-character minimum for an id prefix).

  • CLI run against real config directories, read-only: show, list --path ., list --all (836 rows, 1.3 s), view --last 4, self. resume was run only to print its command.

  • Run in the dev app (yarn start), driven by events dispatched into the page: the Sessions list loads through the refactored history scan; right-click opens the menu with all items and previews; arrow + Enter copies and the banner confirms, with focus back in the search box; ⌘⇧C copies the reference (clipboard content checked); ⌘I opens the overlay with all seven fields; ⌘↓ opens the inline panel. That run found that a row near the bottom opened its panel below the fold — fixed and re-run. After review round 1 the dev app was run again: the overlay takes focus, arrows move focus between rows, Enter copies and Esc returns focus to the search box; the menu's active item is exposed to assistive technology; a search that filters the expanded row away removes the inline panel and the next Esc clears the search; Esc with the panel open closes only the panel.

  • The packaged app (yarn make, built before review round 1) bundles the CLI: list and self were run through the app binary with ELECTRON_RUN_AS_NODE and returned correct results.

  • Tested by hand on a packaged build (yarn make, at the round-2 head) in both Normal App and Menu Bar mode: the copy menu, ⌘⇧C, the overlay, the inline panel (including the scroll into view), and the CLI through the generated codev() shell function — list with --path, --account, --all, show by full id, id prefix and part of a title, view --last, self inside a session of each of two accounts and in a plain terminal (not found, exit 1), a real resume of a session of each account, the refusal on an ambiguous query (exit 2), an unknown option, an unknown command, help, and codev account list. Duplicate titles were run through the packaged CLI directly: show listed both sessions; view and resume refused with exit 2, full ids on stderr and nothing on stdout.

  • That testing found one bug, fixed in review round 3 and re-run in the dev app: with the overlay (or the menu) open, hiding the window with the global shortcut and showing it again put focus back in the search box, and the next Esc hid the whole window with the overlay still open. Esc now closes the open layer first.

  • Round 3's other UI changes were run in the dev app too: hovering an overlay row moves focus to it and Enter copies that row; the overlay has a maximum height and scrolls.

Not verified:

  • Round 3's changes on a packaged build (they were run in the dev app with events dispatched in the page, not typed).
  • The inline panel's focus ring.
  • Whether self follows a /branch.

Known limits

  • The resume command of a default-account session carries no CLAUDE_CONFIG_DIR, so it fails (No conversation found) when run in a shell that already has the variable set for another account — for example codev session resume run from inside another account's session. This is the existing command format, not new here; it is tracked in grimmerk/codev#172 (related, not resolved by this PR).

  • For a session whose transcript is not under its own project slug, the app looks it up in an index of all project directories that is kept for 30 seconds, so a transcript that appears elsewhere can read as not found for up to that long.

  • In the inline details panel the rows can take focus but cannot be reached with Tab from the search box, because the app already uses Tab to switch between the Projects and Sessions tabs. The overlay (⌘I) is the keyboard path.

  • The CLI lists sessions that appear in history.jsonl. A session that was never prompted, and VS Code or Desktop sessions, do not appear in list / show / view / resume; self works for them.

  • For an account that shares the anchor's auto-memory, building the resume command writes the same per-project settings file the app already writes.

Version 1.0.96, with CHANGELOG, README and design-doc entries. main (1.0.95) is merged in, with both CHANGELOG entries kept; the merged tree was run in the dev app (the Session Preview settings and the session details work side by side). One more open change takes 1.0.97.

🤖 Generated with Claude Code