🧩query() Function
Also known as query(), Agent SDK query, Claude Agent SDK query()
The main function of the kit. Give it a prompt, and it runs the agent and sends back each step.
Think of it like
It is like giving a helper a job. They tell you each step.
Example
Leo calls query() with the prompt find and fix the bug in utils.py. His loop prints each tool Claude uses, then the result.
Why it matters
It is the one way in to the agent, so most programs start here.
Definition
Example code
typescript
for await (const m of query({ prompt: "Fix the failing test" })) {
if (m.type === "result") console.log(m.result);
}Common mistake
Key takeaways
- 1Prompt and options in. Messages out.
- 2Runs the whole loop. Many turns.
- 3Read it in a loop. async for.