Two APIs for two lifecycles
The SDK exposes two top-level entry points. query(prompt, options) is a one-shot async generator: spin up a subprocess, run a single prompt to completion, tear down. ClaudeSDKClient(options) is a long-lived client: connect once, send many messages, keep the subprocess alive.
When query() fits
Scripts, CI jobs, batch transformations, anything where the agent runs to completion and exits. Each query is independent. cwk-site uses query() for its build-time content generation.
When ClaudeSDKClient fits
Chat applications, long-running operators, anything where multiple messages share state. cwkPippa's Claude brain holds one ClaudeSDKClient per conversation_id — the subprocess persists, the conversation continues, the SDK replays internal history without you resending it.