Skip to content

(sessions): follow /clear to the new transcript instead of listing it apart - #477

Open
abate wants to merge 1 commit into
devsuitup:mainfrom
abate:fix/clear-rekey
Open

abate wants to merge 1 commit into
devsuitup:mainfrom
abate:fix/clear-rekey

Conversation

@abate

@abate abate commented Oct 5, 2026

Copy link
Copy Markdown
Collaborator

Problem

/clear makes the CLI open a new jsonl under a new session id. Nothing in it names the session it replaced (no forkedFrom; every record carries the new id), so detectSessionTransitions() never matched it: the open terminal stayed on the old row and the new conversation appeared as a separate, unattached sidebar entry once its first prompt made it indexable.

Fix

The CLI rewrites ~/.claude/sessions/<pid>.json with the new sessionId on /clear (verified on live state files). cliSessionState.clearOwner(newId, ptyPid) finds the live pid naming newId and walks its /proc parent chain up to the PTY:

  • mine → re-key exactly like a fork (session-forked).
  • other → another process's file; ignored.
  • pending → state file not rewritten yet; rechecked for up to 60 s.
  • unknown (no /proc: macOS/Windows) → matched only when this is the sole live Claude PTY in the folder.

readNewSessionSignals() recognises the file by its first non-bookkeeping user record (classifyUserText). The renderer adds a pending "New session" row for the new id, since a /clear transcript is not indexed until its first prompt. The cleared conversation stays in the list as a past, resumable session.

Docs: .ai/contexts/cli-session-state.md → "Owner of a /clear transcript".

Tests

  • 8 new in test/session-transitions.test.js (mine / other / pending→mine / stale pending / unknown sole vs. two candidates / prompt-not-clear / post-fork clear / awaiting fork), 1 in test/cli-session-state.test.js (clearOwner verdicts).
  • Lint 0 errors. Full suite: failures only in the CLI-state canary (stale state file from CLI 2.1.259), sandbox-wrapper and test-pr tests — environment-bound, untouched files.

🤖 Generated with Claude Code

… it apart

/clear makes the CLI open a new jsonl under a new session id that names
nothing of the one it replaced, so fork detection never matched it: the
terminal stayed on the old row and the new conversation appeared as a
separate, unattached session. The CLI's state file switches to the new id
on /clear; resolve its pid up to the PTY's and re-key the session like a fork.
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