🧩abortController Option
Also known as abortController, Agent SDK abortController, Agent SDK cancel, Claude Agent SDK abortController
The option that lets your code stop a whole agent run.
Think of it like
It is like the off switch on a toy, not the pause button.
Example
A web request that started an agent times out after one minute. The server calls abort(), and the agent run ends with it.
Why it matters
A run nobody waits for still costs tokens. Cancelling it stops the spend.
Definition
Example code
typescript
const ac = new AbortController();
query({ prompt, options: { abortController: ac } });
ac.abort();Common mistake
Key takeaways
- 1Ends the call. Not just one turn.
- 2Standard AbortController. From JavaScript.
- 3TypeScript only. As an option.