Skip to content
BENIBIX Learn

interrupt() vs abortController

People think interrupt() and abortController do the same thing, because both stop an agent that is still at work. They do not. interrupt() stops only the turn the agent is on, and the session stays open, so you can send a new message right after. It needs streaming input mode. abortController ends the whole query() call, and nothing more comes back from it. Use the first to steer, and the second to quit.

AI🧩 Claude Agent SDK

interrupt() Method

The method that stops what the agent is doing, but keeps the chat.

interrupt() is the Agent SDK method that stops what the agent is doing right now. It only works in streaming input mode, on the query object in TypeScript or on ClaudeSDKClient in Python. The session stays open, so you can send a new message straight after. In Python, read the messages still waiting before you read the reply to the new one. It is the same as pressing Esc in Claude Code.

Example
A user clicks Stop while the agent heads the wrong way. The app calls interrupt(), then sends the user's new message.
Why it matters
Users change their minds. This lets them steer without losing the session.
Full entry
AI🧩 Claude Agent SDK

abortController Option

The option that lets your code stop a whole agent run.

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
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.
Full entry

In one line

interrupt() Method
The method that stops what the agent is doing, but keeps the chat.
abortController Option
The option that lets your code stop a whole agent run.