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§
- CanUse
Tool - 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.
- OnUser
Dialog - Renders
request_user_dialogdialogs and returns the user’s choice, e.g.UserDialogResponse::completed("retry_fallback")for arefusal_fallback_prompt. List the kinds it handles inInitialize::supported_dialog_kinds; the CLI sends no other kind. - Reload
Plugins - Options of
Session::reload_plugins. - Session
- A live Claude Code session. Cheap to clone — backed by
Arc<SessionInner>. - Session
Options - How to spawn and configure the CLI process.
- Weak
Session - A
Sessionhandle that does not keep the session alive.
Enums§
- Session
Error - 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.