Repository navigation
Conversation
… 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.
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.
Problem
/clearmakes the CLI open a new jsonl under a new session id. Nothing in it names the session it replaced (noforkedFrom; every record carries the new id), sodetectSessionTransitions()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>.jsonwith the newsessionIdon/clear(verified on live state files).cliSessionState.clearOwner(newId, ptyPid)finds the live pid namingnewIdand walks its/procparent 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/cleartranscript 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
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 intest/cli-session-state.test.js(clearOwnerverdicts).🤖 Generated with Claude Code