← Claude Docs

TypeScript SDK V2 interface (preview) - Claude Code Docs

Claude Docs · April 17, 2026
The V2 Claude Agent TypeScript SDK simplifies multi-turn conversations by eliminating async generators and replacing them with separate send()/stream() cycles for each interaction. The API reduces to three core concepts: createSession()/resumeSession() to start or continue conversations, session.send() to dispatch messages, and session.stream() to retrieve responses. Sessions persist context across multiple exchanges, support resumption by ID for long-running workflows, and can be closed either manually or automatically using TypeScript 5.2+ resource cleanup features.

Detailed Analysis

Anthropic has released a preview of the V2 interface for its Claude Agent TypeScript SDK, a significant redesign that eliminates the async generator and yield coordination patterns required in the prior version. The updated API consolidates multi-turn conversational logic into three core concepts: session creation or resumption via `unstable_v2_createSession()` and `unstable_v2_resumeSession()`, message dispatch via `session.send()`, and response consumption via `session.stream()`. The SDK is distributed through the existing `@anthropic-ai/claude-agent-sdk` npm package, meaning developers do not need to install a separate dependency to access the preview. The `unstable_` prefix on all V2 functions signals that the interface remains subject to breaking changes before a stable release, a common pattern Anthropic uses to let developers experiment with emerging APIs without implying production-readiness guarantees.

The architectural shift from generator-based orchestration to an explicit send/stream separation addresses a well-documented pain point in conversational AI SDK design. Async generators, while powerful, entangle state management with iteration logic, making it difficult to inject processing steps between turns — such as parsing a model response before deciding what to send next. By decoupling `send()` and `stream()` into discrete awaitable operations, the V2 interface allows developers to insert arbitrary logic between a dispatch and the consumption of its response, a pattern better suited to agentic workflows where intermediate reasoning, tool calls, or conditional branching may occur. The addition of `unstable_v2_prompt()` as a one-shot convenience function further acknowledges that a meaningful portion of use cases are single-turn and do not benefit from session overhead at all.

Session persistence and resumability represent one of the more consequential features in the V2 design. Every streamed message carries a `session_id` field, allowing applications to capture and store conversation identifiers across restarts, service boundaries, or asynchronous workflows. The `unstable_v2_resumeSession()` function accepts a stored ID and reconstructs conversational context, enabling long-running agentic pipelines that span multiple application lifecycles. This design aligns with patterns common in enterprise software where conversational state must survive infrastructure events, and it positions the SDK for use cases beyond simple chatbots — including automated coding assistants, multi-step research workflows, and background processing agents that may be interrupted and resumed.

The SDK's integration of TypeScript 5.2's `await using` syntax for automatic resource cleanup reflects a deliberate alignment with the latest language ergonomics. The `Symbol.asyncDispose` protocol, which underpins `await using`, ensures that sessions are properly closed when execution leaves a block scope, reducing the risk of resource leaks in long-running services. Anthropic's decision to support both automatic and manual cleanup patterns acknowledges that not all production environments have adopted TypeScript 5.2, a pragmatic concession to the heterogeneous state of the TypeScript ecosystem. This dual-path approach is consistent with how major SDK vendors handle language feature adoption curves.

Placed in the broader context of AI developer tooling, the V2 interface preview reflects an industry-wide maturation in how AI companies think about SDK ergonomics for agentic applications. The first generation of LLM SDKs largely treated models as stateless completion endpoints; the explicit session management, resumability, and streaming separation in this V2 design acknowledge that production AI applications require the same lifecycle and state management primitives that developers expect from databases or network connections. Anthropic's use of an `unstable_` naming convention for the preview also signals a more collaborative release methodology, inviting developer feedback before API surfaces are locked. As competitors including OpenAI and Google DeepMind continue iterating on their own agent-oriented SDKs, the architectural decisions embedded in this V2 interface will likely influence how the broader ecosystem converges on conventions for managing conversational AI state.

Read original article →