Tasks System Architecture
Overview
The Tasks System manages background work in Claude Code. When you run a long command or spawn a sub-agent, it runs as a task - isolated, trackable, and controllable.
Shared from "Claude-Code" on Inkdown
The Tasks System manages background work in Claude Code. When you run a long command or spawn a sub-agent, it runs as a task - isolated, trackable, and controllable.
| File | Purpose |
|---|---|
Task.ts | Task type definitions + ID generation |
tasks.ts | Task registry and getAllTasks() |
tasks/[Type]Task/[Type]Task.tsx | Individual task implementations |
tasks/stopTask.ts | Task termination logic |
tasks/types.ts | Shared task type definitions |
Purpose: Execute bash/shell commands in background.
Purpose: Spawn a sub-agent (autonomous AI worker).
Key Difference: Agents can use tools autonomously; shells just run commands.
Purpose: Spawn an agent on a remote (cloud) environment.
Purpose: Background compaction/summarization.
Why 36^8? ~2.8 trillion combinations - resists brute-force symlink attacks.
Tasks write to disk files, not memory. Reading is streaming:
| Task Type | Kill Strategy |
|---|---|
local_bash | SIGTERM โ wait โ SIGKILL |
local_agent | AbortController + signal agents |
remote_agent | Remote API call to kill |
dream | Usually no-op (background) |
The TaskGetTool retrieves task output:
Users can "foreground" a task to see its output in the main view:
Task output goes to files, not memory. This:
UI reacts to status changes. No direct process management in components.
Each task type handles its own spawning and killing. Common interface, specialized implementations.
All task state is in AppState. Anyone can observe tasks.
SIGTERM first, SIGKILL only if needed. Allows cleanup.