Repository navigation
feat: a structured claude agent opens in claude code's own terminal and comes back - #77
Merged
Merged
Conversation
…nd comes back
POST /v1/sessions/{name}/switch {"to":"terminal"|"chat"} (driver.switch)
moves an idle structured session between its chat and Claude Code's own
screen, one process at a time, on the same conversation:
- to the terminal: the host stops Claude, and the pane is respawned as
`claude --resume <id>`, with berthd's hooks back on and the session's
bypass carried over as --permission-mode where Claude allows it
- back to the chat: Claude Code is told /exit, the turns typed there are
copied from its transcript into berthd's log, and the host starts again
with --resume on the same log and socket. It works from a terminal that
was already left, too
The pane's Terminal | Conversation switch does it for these sessions.
Also: the Claude driver says what it reads in order, from one queue per
session, and a prompt's start waits for the send that opened its turn. A
write waits for a host that is still starting.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This branch was successfully deployed
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.
Phase 4a of
design/structured-agents/plan.md(Labs, structured Claude agents only).What it does
POST /v1/sessions/{name}/switchwith{"to": "terminal" | "chat"}(capabilitydriver.switch) moves an idle structured session between its chat and Claude Code's own screen. It keeps the same conversation and runs one process at a time:agenthost.Stop(Claude ends at its stdin's end)respawn-pane -kasclaude --resume <id>, withBERTH_DRIVERcleared so berthd's hooks drive the turn ledger again--permission-mode bypassPermissionsunless running as rootbeginStartupwatches for Claude's startup questions/exitis typed as keys, then wait for the pane to endoutentries, so the chat reads on in order--resumeon the same log and socket, and wait for it to listen/exit, or "No, exit" at the trust question)@berth_conv/@berth_sockthroughout.Session.switchsays where it can go:terminalwhile structured,chatwhile in its terminal.Fixes in the Claude driver found while testing
finishedcould overtakestarted. They now go through one ordered queue per session.startedcould reach the ledger beforesession.sentopened its turn, leaving the turn stuck running. The driver now waits briefly (Turns.AwaitSent).Tests
TestAStructuredSessionGoesToItsTerminalAndBack, with a stand-in that also plays Claude's TUI when run without-p:driverterminal,switchchat, its screen shows the resumed session)echo: hello | answered in the terminal | echo: back again-race, together with the structured-session testTestALiveClaudeSessionWorks(opt-inBERTH_LIVE_CLAUDE=1) now also switches real Claude Code to its terminal (answering its trust question for the temporary folder) and back, and Claude still remembers the first reply. It passed locally in 16s.go test -race ./...,go vet ./..., app checks and build,tsc -p e2eand the docs build all pass.Next (4b)
Resuming a structured conversation after its session is gone, and the SQLite conversation index that lists them.
🤖 Generated with Claude Code