Build a client
Launch an agent and own its process lifecycle.
Use the complete client example as a starting point.
Implement the client interface
Section titled “Implement the client interface”Handle RequestPermission and SessionUpdate. Filesystem, terminal, and other optional capabilities should only be advertised after their handlers are implemented.
The minimal example declines permission requests and advertises no filesystem or terminal capabilities.
Start a process
Section titled “Start a process”transport/stdio.StartClient takes an executable and an argument slice. It launches the executable directly, drains stderr, and connects the typed protocol client.
After starting, call Initialize and check the negotiated protocol version before NewSession and Prompt.
Close deliberately
Section titled “Close deliberately”Use Process.Shutdown(ctx) with a bounded deadline to close protocol input, wait for a graceful exit, then terminate the owned process tree if necessary. Close is the immediate-stop operation.
Do not replace lifecycle handling with a delay or assume that a prompt’s completion means the child process has exited.