StreamSession
The Session facet of the Claude Code stream transport: one claude -p process per live session, with stream-json on standard input and standard output (trove-parts §TPN-4).
| Inherits | octomy::llm::driver::ISession |
| Group | libllmsession |
In the namespace octomy::llmsession. Declared in src/libs/libllmsession/llmsession/StreamSession.hpp.
Detailed description
The process starts with the first prompt and stays while the session is live. Each further prompt goes to its standard input as one stream-json line. A prompt that arrives during a turn waits in Claude Code and starts the next turn, in order (§TPR-7), so the operator can send text at any time (TPX-29).
Each stream-json object becomes events of the part's own types (§TPN-3) through the signal streamEvent(): system, text, thinking, tool_use, tool_result, usage, limit, error and turn_end. The session id, the usage and the rate limits come from the stream (TPX-34). The session also gives the ISession signals, so that SessionManager can drive it as it drives the PTY transport: a limit gives limitReached(), and the Trove scheduler parks the job for the reset through the same path (TPX-35).
interrupt() stops the process and ends the open turns (TPX-30). The next prompt starts a new process with --resume <provider session>, so the conversation continues. switchModel() lets the current turns end and closes standard input; the next prompt starts a process with the new --model (TPX-36). finish() does the same for a door host that hands over, and then starts no process again (TPX-31).
The child gets its environment from ChildEnvironment, without ANTHROPIC_API_KEY, so that it bills the subscription of the machine.
What the OPAL chat gets
The OPAL chat runs its Claude Code turns on this class, one live process per chat session (trove-parts §TPN-9b):
- Each turn ends with promptCompleted(): the answer, or the reason of a failure. A process that dies or does not start fails its turns after the session faults, so that a Trove worker fails its job first.
- A turn whose provider session is lost fails with the text of Claude Code. The prompt of a failed turn leaves history(), so that the caller can send it again on a new session.
- adoptSession() with a history and no provider session: the first message of the new Claude Code session carries that history.
- A
limitgives limitReached(), and a signed-out Claude Code gives authRequired(), before the turn fails. The chat picks its message from them. - An image file over kMaxInlineImageBytes goes by its path, and its folder becomes an
--add-dirof the next process. - objectReceived() gives each object of the stream to the client that keeps the measured facts of the model.
StreamSettings::refusalfails each prompt at once, for example when no Claude Code is installed.- With
StreamSettings::checkVersionFloor, the first process waits for the version read of ClaudeCodeVersion, and the GUI thread never waits for it. The prompts wait in order, and go when the answer arrives. Below the floor, each prompt fails with a message that names both versions (§TPN-4). A handover (finish()) lets the prompts that wait run when the answer arrives.
See also octomy::llmsession::StreamDriver, octomy::llmsession::SessionProfile, octomy::llmsession::SessionRunner.