Skip to main content

Module session

Module session 

Source
Expand description

Persistent subprocess session — 3-task architecture.

reader_task — reads stdout; answers CLI control requests (hooks, can_use_tool, mcp_message), routes control responses to waiters, fans every other frame out to all subscribers (one unbounded channel each: no frame is ever dropped) writer_task — drains the stdin channel into the subprocess watchdog_task — waits for exit, marks the session dead, keeps stderr tail

Wire protocol verified against claude_agent_sdk 0.1.48 (_internal/query.py, _internal/transport/subprocess_cli.py) and a live Claude Code 2.1.329 binary.

Structs§

CanUseTool
Async tool-permission handler. Setting one makes the CLI ask the host (via can_use_tool) whenever its own permission rules would prompt.
McpCall
Options of Session::mcp_call.
OnElicitation
Answers MCP elicitations (an MCP server asking the user for input). Without one, the CLI is told the request is unsupported.
OnStderr
Receives every stderr line of the CLI as it is written.
OnUserDialog
Renders request_user_dialog dialogs and returns the user’s choice, e.g. UserDialogResponse::completed("retry_fallback") for a refusal_fallback_prompt. List the kinds it handles in Initialize::supported_dialog_kinds; the CLI sends no other kind.
ReloadPlugins
Options of Session::reload_plugins.
Session
A live Claude Code session. Cheap to clone — backed by Arc<SessionInner>.
SessionOptions
How to spawn and configure the CLI process.
WeakSession
A Session handle that does not keep the session alive.

Enums§

SessionError
Error of a session operation.

Constants§

DEFAULT_CONTROL_TIMEOUT
Default of SessionOptions::control_timeout.
MIN_CLI_VERSION
Oldest Claude Code version the wire protocol here is verified against.

Type Aliases§

EventRx
Receives every frame the CLI emits after subscribe(); None once the CLI’s stdout has ended.
Result
Result with SessionError.