Skip to content
BENIBIX Learn

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

abortController is the TypeScript Agent SDK option that lets you cancel a query() call. You make a standard AbortController, pass it in, and call abort() on it when you want the run to end. The SDK then stops the work and ends that call. If you leave it out, the SDK makes one of its own. Use interrupt() to stop one turn and go on, and abortController to end the whole call.

Example code

typescript
const ac = new AbortController();
query({ prompt, options: { abortController: ac } });
ac.abort();
Cancel the run from your own code.
abort() ends the whole call, so nothing more comes back.

Common mistake

Using it to stop one turn. That ends the whole call, so use interrupt() instead.

Key takeaways

  1. 1
    Ends the call. Not just one turn.
  2. 2
    Standard AbortController. From JavaScript.
  3. 3
    TypeScript only. As an option.

Compare