Skip to content

fix(cli): bind the cleaner entry point to a session instead of guessi… - #85

Merged
trancefornow merged 2 commits into
mainfrom
ry03-cleaner-session-binding
Sep 26, 2026
Merged

trancefornow merged 2 commits into
mainfrom
ry03-cleaner-session-binding

Conversation

@wwwaken

@wwwaken wwwaken commented Sep 26, 2026

Copy link
Copy Markdown
Collaborator

…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

@wwwaken
wwwaken force-pushed the ry03-cleaner-session-binding branch from 2797f29 to a5bf6a7 Compare September 26, 2026 08:47
wwwaken and others added 2 commits September 26, 2026 16:47
…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
@trancefornow
trancefornow merged commit bc0fbf7 into main Sep 26, 2026
1 check passed
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.

2 participants