TaskStopTool: Stop task
8/2/2026, 4:09:52 PM · Source
AI-translated on 8/2/2026, 4:10:43 PM · by Qwen3.6 35B (fast, default)
This article analyzes the core functionality and source code logic of TaskStopTool, explaining how it precisely halts running background tasks by verifying task existence and state and invoking the stopTask function.
It handles interrupting background execution, not deleting task records
TaskStopTool's goal is clear:
Stops a currently running background task.
This generally corresponds to two types of sources:
- Background shells launched by
BashTool - Background agents launched by
AgentTool
Key Source Code
const result = await stopTask(id, {
getAppState,
setAppState,
})
Before that, it first validates:
- The task exists
- The task is currently indeed
running
Call Chain
Background task running > TaskStopTool > Validate task_id > stopTask(...) > Task status changes to stopped
Summary
TaskStopTool adds the "interrupt" capability to Claude Code's background execution chain, which is an indispensable piece of a formal task system.
Learning map
Understanding the Agent Toolchain: From Task Suspension to Stop
-
Background Knowledge
- Understand the concepts of background processes generated by
BashToolandAgentTool. - Familiarize yourself with the multi-task concurrency logic within Claude Code.
- Understand the concepts of background processes generated by
-
Source Code and Logical Analysis
- Read
TaskStopTool.tsor relevant core code snippets. - Understand pre-validation mechanisms: How to ensure that a
task_idtruly exists and its status isrunningin order to prevent accidental operations.
- Read
-
Call Chain Tracing
- Trace the data flow from user intent (interruption) to the specific execution of
stopTask(appState). - Analyze state transition process: Running → Stopped (how App-States are updated).
- Trace the data flow from user intent (interruption) to the specific execution of
-
Mechanism Summary
- Master the implementation details of the 'stop' capability within Agent systems, understanding its fundamental difference from task deletion operations.
Get hands-on — step by step
- Launch background session: Run a long-running Bash command (such as
sleep 300) in the Claude Code interactive interface to create a background task in therunningstate. - Observe status: Use the toolbar or UI to confirm the task's current ID and verify that its status is displayed as "running".
- Trigger stop logic: Attempt to interrupt the task by invoking a stop command or using the corresponding interface button. Under the hood, this corresponds to sending a request to TaskStopTool and entering the precondition validation phase in its source code (validating
task_id). - Verify results: Confirm that the original process in the terminal or run list is properly terminated, and that the state machine smoothly transitions from
runningtostoppedor an ended state.
Top 3 sources
- 1Anthropic CLI (Claude Code) 官方文档
Anthropic 官方关于 Claude Code 的权威文档,涵盖其基础概念和工具系统。
https://docs.anthropic.com/en/docs/claude-code/introduction
- 2Cline vs Claude Code: Agent 架构对比
GitHub 上知名的开源 AI Agent 项目 Cline,其架构与任务管理理念(包括 TaskStop 等逻辑)常可与之进行横向参照。
https://github.com/cline/cline
- 3Anthropic Function Calling Guide
深入了解大语言模型如何调用外部工具(如 TaskStopTool)的原理与实现机制。
https://platform.anthropic.com/docs/tool-use
Links are AI-suggested — worth a quick sanity check before diving in.