Repository navigation
fix(agents): resume the claude session a tab moved to with /clear (#306) - #307
Merged
simion merged 1 commit intoSep 16, 2026
Merged
Conversation
…mion#306) termic stores one session id per tab and resumes it on relaunch. `/clear` starts a new session inside the running claude, and `/resume` switches to another, so everything after either landed under an id the tab never stored. The next relaunch resumed the session from before the `/clear`, and the agent said it had never worked on what the tab was doing. claude's READY hook (SessionStart) now also reports the session id over the `session <id>` OSC codex and devin already use, but only when the session moved. Measured on claude 2.1.273: `source` is `clear` with a new id on every /clear, `resume` with the resumed id, `compact` with the same id, and `startup` at launch, which is skipped because termic passed that id itself. The report also requires CLAUDE_CODE_ENTRYPOINT=cli: a nested `claude -p` inherits TERMIC_PTY but runs as `sdk-cli`. On the frontend a reported id supersedes the id the spawn minted. That one is only held after the spawn survives RESUME_FAILURE_MS and only persisted on the first prompt, so a /clear before either was undone by the next Enter. Control: the e2e case for it fails without the guard. The id lands on the tab whose pty it arrived on, keyed by tab id, so several agent tabs in one task, in any order, keep their own. SCHEMA bumps to 10 so existing installs pick the script up. Closes simion#306 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
simion
approved these changes
Sep 16, 2026
simion
left a comment
Owner
There was a problem hiding this comment.
Reviewed with Opus. Clean fix: extends the existing OSC session <id> mechanism (already used by codex/devin) to also cover claude's SessionStart hook for clear/resume/compact sources, gated correctly (never fires on startup, checks entrypoint == cli, validates uuid). The timing race on the frontend side (spawn vs. first-prompt persistence) is handled for both orderings, and per-tab id routing is correct for multiple agent tabs in one task. Solid test coverage (Rust + e2e) plus manual verification. Thanks for the second contribution!
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.
Closes #306
Problem
termic stores one session id per claude tab and resumes it on relaunch.
/clearstarts a new session inside the running claude, and/resumeswitches to another, so everything after either landed under an id the tab never stored.The next relaunch resumed the session from before the
/clear, and the agent said it had never worked on what the tab was doing.Fix
agent_hooks.rs). claude's READY script (itsSessionStart) now also reports the session id over thesession <id>OSC codex and devin already use, but only when the session moved:sourceisclear,resumeorcompact. Neverstartup: termic passed that id itself.CLAUDE_CODE_ENTRYPOINTiscli. A nestedclaude -pinheritsTERMIC_PTYbut runs assdk-cli.--resume <id>command line.SCHEMA_VERSIONbumps to 10 so existing installs get the script on the next sync.TerminalPane.tsx). A reported id supersedes the id the spawn minted. That one is only held after the spawn survivesRESUME_FAILURE_MSand only persisted on the first prompt, so a/clearbefore either was undone by the next Enter (sessionReportedRef).Measurements behind the guard (claude 2.1.273,
SessionStarthook logging stdin and env) are in #306 and now indocs/agent-hooks.md.Tests
cargo test: 1032 passed. New: the id is reported forclear/resume/compactwith aclientrypoint, and not forstartup,sdk-cli, a missing entrypoint, an unknown source, or a non-uuid id. Control: without claude in the emit branch the reporting test fails.npm test: 2180 passed.agent.e2e.ts, new describe (3 cases): threefakeclaudetabs in one task, reordered first, each storing the id replayed over the hook OSC on its own tab only; a relaunch spawning--resume <id>for all three (asserted on the spawned argv); a/clearinside the first two seconds, before the first prompt, surviving it. Control: that last case fails withoutsessionReportedRef.agent.e2e.tsrun has 5 failures that are identical on a cleanmainbuild in two full runs (IIP redraw, pending-work done badge, two-agent footer chips, and bothfakecaptureresume cases), so they are pre-existing and unrelated.Manual verification
Exercised by hand in a
tauri devbuild with real claude 2.1.273:/clear, another message, Termic closed and reopened; the tab spawned--resume <post-clear id>and the agent had the post-clear conversation;/clearin the second: after a restart each resumed its own session.🤖 Generated with Claude Code