What the Claude Agent SDK's query() Streams: Every Message, Logged
Book: AI That Acts The series: AI in TypeScript — 5 books, from your first LLM call to agents in production — all five here My project: Hermes IDE | GitHub — an IDE for developers who ship with Claude Code and other AI coding tools Me: xgabriel.com | GitHub You wire up query() , wait for the message with type === "result" , print message.result , and ship it. Then a run takes four minutes instead…
When using the Claude Agent SDK's query() function, every message produced during the interaction is streamed, including those that are logged. This is in contrast to a normal run that might take only a few seconds and return a result with a low cost. However, if the execution takes longer, or if the cost is higher than expected, there is no record of the events that occurred in between.
The TypeScript reference for the Claude Agent SDK lists 36 different members in the SDKMessage union that query() can return. The five most important types mentioned by Anthropic's agent loop guide are the system init message, assistant messages, user messages, stream events, and the result. Other observability events, such as rate-limit status and task notifications, are also recorded.
The order and fields of these messages can be found in Anthropic's documentation for the current SDK version (v0.3.296 at the time of writing). To demonstrate the streaming behavior, a simple agent with a single tool is created and installed. The tool is a function that looks up order status in a Map, returning an error for unknown IDs.
The server is created using createSdkMcpServer, with the tool registered and the name of the server becoming part of the tool's full name.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.