/claude-code-superpowers:task-systemfrom claude-code-superpowers
Teaches Claude Code's Task system for spawning background work (local_bash, local_agent, remote_agent, in_process_teammate, local_workflow) with disk-backed output and lifecycle tracking. Use when tools need long-running operations without blocking the conversation loop.
Ships in claude-code-superpowers. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
A Task is a unit of background work that runs independently of the main conversation loop. Tasks are spawned by tools or commands, tracked in AppState.tasks by ID, write their output to a disk file (not memory), and progress through a lifecycle: pending → running → completed | failed | killed.
The key design: tasks do not block the conversation. After a task is spawned, the LLM can continue the conversation, ask the user for more input, or respond to the task's output when it's done. The user can check task status with /tasks, kill a task with /tasks kill, or watch its output live.
Some operations take seconds to minutes: running a test suite, compiling a large project, cloning a repository, running a long Temporal workflow. If these blocked the conversation loop, the user would be stuck waiting. The Task system decouples the spawn from the wait.
Disk-backed output (each task writes to a temp file, tracked by outputFile + outputOffset) is a deliberate choice over in-memory buffers. It means: (1) output is preserved across session restarts; (2) the output file can be tail -f'd externally; (3) the main process doesn't hold all output in memory; (4) partial output can be read back at any offset without re-running the task.
TaskCreateTool from the tool registry. It accepts a type, description, and type-specific configuration. The tool returns a taskId.LocalAgentTask, LocalShellTask). Don't manage it manually.context.getAppState().tasks[taskId] — it returns a TaskStateBase with status, outputFile, outputOffset, and timing.TaskStopTool with the taskId.outputFile starting at outputOffset — increment the offset with each read.endTime and update status to 'completed' or 'failed' via setAppState.// Source: src/Task.ts (task type definitions)
export type TaskType =
| 'local_bash' // Shell command running in background
| 'local_agent' // Claude subagent running locally
| 'remote_agent' // Agent running on CCR (Claude Code Remote)
| 'in_process_teammate' // Swarm mode: another agent in same process
| 'local_workflow' // Complex multi-step workflow
| 'monitor_mcp' // MCP server health monitor
| 'dream' // Speculative execution mode
export type TaskStatus = 'pending' | 'running' | 'completed' | 'failed' | 'killed'
export type TaskStateBase = {
id: string
type: TaskType
status: TaskStatus
description: string
toolUseId?: string // Which tool call spawned this task
startTime: number // Unix ms
endTime?: number // Set when terminal state reached
totalPausedMs?: number // Time spent paused (for interruptible tasks)
outputFile: string // Path to disk-backed output file
outputOffset: number // Current read position in output file
notified: boolean // Whether user was OS-notified of completion
}
// Source: src/tasks/LocalShellTask/ (task lifecycle management)
export async function runLocalShellTask(
task: LocalShellTaskState,
context: TaskContext,
): Promise<void> {
// Update status to running
context.setAppState(prev => ({
...prev,
tasks: {
...prev.tasks,
[task.id]: { ...prev.tasks[task.id], status: 'running' },
},
}))
const outputStream = fs.createWriteStream(task.outputFile, { flags: 'a' })
try {
await executeShell(task.command, {
signal: context.abortController.signal,
onData: (chunk) => {
outputStream.write(chunk)
// Increment offset so consumers can read new data
context.setAppState(prev => ({
...prev,
tasks: {
...prev.tasks,
[task.id]: {
...prev.tasks[task.id],
outputOffset: prev.tasks[task.id].outputOffset + chunk.length,
},
},
}))
},
})
// Terminal state: completed
context.setAppState(prev => ({
...prev,
tasks: {
...prev.tasks,
[task.id]: {
...prev.tasks[task.id],
status: 'completed',
endTime: Date.now(),
},
},
}))
} catch (err) {
// Terminal state: failed
context.setAppState(prev => ({
...prev,
tasks: { ...prev.tasks, [task.id]: { ...prev.tasks[task.id], status: 'failed', endTime: Date.now() } },
}))
} finally {
outputStream.close()
}
}
The notified: boolean field is subtle: it tracks whether the OS notification was sent when the task completed. Tasks that complete while the user is away from the terminal send an OS notification. This flag prevents sending the notification multiple times if AppState is re-rendered.
Before — long-running operation blocking the conversation:
async call(args, context, canUseTool) {
const permission = await canUseTool(BuildTool, args, context)
if (!permission.granted) return { type: 'error', error: permission.reason }
// Blocks conversation for 30+ seconds — user can't interact
const output = await runBuildProcess(args.target)
return { type: 'success', data: output }
}
After — operation spawned as a background task:
async call(args, context, canUseTool) {
const permission = await canUseTool(BuildTool, args, context)
if (!permission.granted) return { type: 'error', error: permission.reason }
// Generate a unique task ID
const taskId = generateId()
const outputFile = path.join(os.tmpdir(), `build-${taskId}.log`)
// Register task in AppState as pending
context.setAppState(prev => ({
...prev,
tasks: {
...prev.tasks,
[taskId]: {
id: taskId,
type: 'local_bash',
status: 'pending',
description: `Build ${args.target}`,
startTime: Date.now(),
outputFile,
outputOffset: 0,
notified: false,
},
},
}))
// Spawn in background — don't await
runBuildInBackground(args.target, taskId, outputFile, context).catch(console.error)
// Return immediately — conversation continues
return {
type: 'success',
data: `Build started (task ID: ${taskId}). Use /tasks to monitor progress.`,
}
}
call() awaits an operation that takes more than a few secondsBashTool handles short-lived commands directlydomain-model — where tasks fit in AppState and the overall systemasync-concurrency — AbortController for task cancellationobservability — how task output is logged and streamedWhat SKILL.md sets; muted values are Claude Code's defaults
16 skills in this plugin
/async-concurrencyTeaches Claude Code's concurrency model: isConcurrencySafe() for parallel tool execution, AbortController propagation for cancellation, Promise.all() for parallel initialization, and the StreamingToolExecutor for concurrent progress streams. Use this when writing tools that could benefit from parallel execution, need to respect cancellation, or must stream partial results. Read-only tools that don't declare concurrency safety are needlessly serialized.
/build-tool-factoryTeaches how to create a new Claude Code tool using the buildTool() factory from src/Tool.ts.
Use this whenever adding a new capability to Claude Code — buildTool is the only correct entry
point. It fills in safe defaults for isConcurrencySafe, isReadOnly, isDestructive,
checkPermissions, and userFacingName so you only implement what your tool actually needs.
/creating-skillsUse when extracting an engineering pattern from a codebase and packaging it as a skill for an AI assistant. Triggered when: converting a recurring code pattern into a SKILL.md, wanting your AI to apply a specific pattern automatically, or validating whether an existing skill is good enough to ship. Covers structure, the real-code requirement, the two-layer generic/specific design, and six quality tests.
/domain-modelTeaches Claude Code's core domain model: Tool, Message, Task, ToolUseContext, AppState, and Command — the six concepts every part of the system is built around. Use this before writing any new tool, command, or feature that touches the conversation loop. Essential for understanding how Claude's capability system is structured and why the abstractions exist.
/error-handlingTeaches Claude Code's error philosophy: tool call() throws typed errors, the framework catches them and formats them for the LLM as structured tool result content, and custom error types carry structured context at system boundaries. Use this whenever writing a tool, utility function, or service that can fail. The distinction between "errors the LLM should see" and "errors that crash the session" is the core insight.
/hot-pathsTeaches Claude Code's startup and runtime performance patterns: lazySchema() for deferred Zod parsing, feature() flags for build-time dead code elimination, memoize() for expensive repeated computations, parallel initialization with Promise.all(), and profileCheckpoint() for tracking load times. Use this whenever writing code that runs at startup, on every turn, or in a hot loop. Startup latency is Claude Code's most user-visible performance metric.
Generated from the plugin's indexed repository (techymt/claude-code-superpowers) — no native marketplace selected
npx claudepluginhub p/techymt-claude-code-superpowersOther plugins' skills for the same job