Repository navigation
fix(cli): bind the cleaner entry point to a session instead of guessi… - #85
Merged
Merged
Conversation
wwwaken
force-pushed
the
ry03-cleaner-session-binding
branch
from
September 26, 2026 08:47
2797f29 to
a5bf6a7
Compare
…ng one maybeResolveLatestSessionId merged two different guarantees behind one name: the Codex host first resolves CODEX_SESSION_ID/CODEX_THREAD_ID through the alias index, which is a real binding to the session the user is in, and only then falls back to whichever session wrote state most recently, which is a guess. The clean command consumed both, so with several Host windows open it could analyze a conversation the user was not looking at, and that is not recoverable from the CLI. Split the two on CliHostRuntime: resolveCurrentSessionId returns only a session the Host can vouch for, and maybeResolveLatestSessionId keeps the old behaviour for commands where a guess is acceptable. clean --session, a session named in this invocation's argv, and resolveCurrentSessionId bind the analyze path in that order. Stored CLI context no longer counts, because an earlier latest-session guess can have written it. When nothing binds, the command refuses and prints how to name the session, showing the most recent one for reference only. Claude Code exposes no environment channel for the live session, but it does keep the process tree: a command it runs for a skill is a descendant of the `claude` process that owns the session. host-process.ts walks up to the nearest such ancestor, the hook records that pid on the session snapshot, and the two meet at a pid nobody had to guess. A CLI the user starts from their own shell after suspending Claude Code is the host's sibling, not its descendant, and correctly resolves to undefined. That sibling case is the interactive one, because Claude Code's Bash tool gets no pseudo-terminal and the arrow-key selector cannot open there. A non-interactive Claude plan now prints the one command that does reach a real terminal, carrying the session explicitly, with --require-tty in the leading position parseCleanArgs requires. Codex behaviour is unchanged. OpenClaw has no channel yet and refuses rather than guesses. --plan/--status/--cancel address a stored plan by id and are unaffected. Refs: RY-03 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UbPqchSVkeQW4ZaEH4jhVf
This was referenced Sep 29, 2026
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.
…ng one
maybeResolveLatestSessionId merged two different guarantees behind one name: the Codex host first resolves CODEX_SESSION_ID/CODEX_THREAD_ID through the alias index, which is a real binding to the session the user is in, and only then falls back to whichever session wrote state most recently, which is a guess. The clean command consumed both, so with several Host windows open it could analyze a conversation the user was not looking at, and that is not recoverable from the CLI.
Split the two on CliHostRuntime: resolveCurrentSessionId returns only a session the Host can vouch for, and maybeResolveLatestSessionId keeps the old behaviour for commands where a guess is acceptable.
clean --session, a session id named in this invocation's argv, and resolveCurrentSessionId now bind the analyze path, in that order. Stored CLI context no longer counts, because an earlier latest-session guess can have written it. When nothing binds, the command refuses and prints how to name the session, showing the most recent one for reference only.
Codex behaviour is unchanged. Claude Code and OpenClaw expose no channel for the live session yet and return undefined, so they refuse rather than guess. For Claude Code that is a Host limitation: processes it spawns are detached from the controlling terminal and carry no session id, and a CLI started from the user's shell is its sibling, not its child.
--plan/--status/--cancel address a stored plan by id and are unaffected.
Refs: RY-03
Claude-Session: https://claude.ai/code/session_01UbPqchSVkeQW4ZaEH4jhVf