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