/claude-code-superpowers:domain-modelfrom claude-code-superpowers
Teaches Claude Code's six core domain concepts: Tool, Message, Task, ToolUseContext, AppState, and Command. Essential before writing tools, commands, or features that touch 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 well-designed AI agent system separates three concerns: (1) capability objects — typed schemas declaring what the agent can do, with permission gates controlling access; (2) runtime injection — a context object passed to every capability invocation, carrying state, abort signals, and callbacks (so capabilities are independently testable, no global singletons); (3) atomic state — an immutable global store updated via reducer functions, so UI renders consistently and state transitions are traceable.
Claude Code names these: Tool (capability), ToolUseContext (injection), and AppState (state store). The other three concepts — Message, Task, and Command — complete the model: A Tool is a named capability with a typed input schema, a permission check, and an execution function. A Message is an immutable turn in the conversation — user input, assistant response, or system event. A Task is an optional background process that a tool can spawn. A ToolUseContext is the runtime environment injected into every tool call — it carries state, abort signals, callbacks, and configuration. AppState is the mutable global state store that the UI and tools read from and write to. A Command is a user-facing slash command that resolves to either a prompt template (injected into the conversation) or a local function.
Without understanding these six, you will model Claude Code incorrectly — treating it as a plain CLI instead of a React-driven state machine with a structured capability system.
Claude Code must bridge an LLM (which communicates via structured JSON tool calls) with a local developer environment (file system, shell, git). The Tool abstraction provides a single contract: the LLM produces a tool_name + input JSON block, the runtime validates the input against a Zod schema, checks permissions, and calls tool.call(). The result is returned to the LLM as a tool result block.
The ToolUseContext solves a layering problem: tools need access to state, permissions, callbacks, and configuration without those being global singletons. Every tool call receives the full context, making tools independently testable and the dependency graph explicit.
AppState uses a Zustand-like pattern in a React TUI. State transitions happen atomically via setAppState(prev => next) — the same pattern as React's setState, but available outside React components via the context object.
buildTool({...}) from src/Tool.ts with a get inputSchema() getter. Define your Zod schema first — it drives the LLM's JSON schema, the validation, and the TypeScript type. Return { data: ... } from call().PromptCommand (for prompt injection) or LocalCommand (for local execution) in src/commands/. Register it in src/commands.ts.context.getAppState() for reads. Use context.setAppState(prev => ({...prev, field: newValue})) for writes. Never use module-level globals.TaskCreateTool or spawn a local agent task. Tasks are tracked in AppState.tasks and live in disk-backed output files.// Source: src/Tool.ts
export type Tool<
Input extends AnyObject = AnyObject,
Output = unknown,
P extends ToolProgressData = ToolProgressData,
> = {
aliases?: string[]
call(
args: z.infer<Input>,
context: ToolUseContext,
canUseTool: CanUseToolFn,
parentMessage: AssistantMessage,
onProgress?: ToolCallProgress<P>,
): Promise<ToolResult<Output>>
description(
input: z.infer<Input>,
options: {
isNonInteractiveSession: boolean
toolPermissionContext: ToolPermissionContext
tools: Tools
},
): Promise<string>
readonly inputSchema: Input
isConcurrencySafe(input: z.infer<Input>): boolean
isReadOnly(input: z.infer<Input>): boolean
isDestructive?(input: z.infer<Input>): boolean
interruptBehavior?(): 'cancel' | 'block'
}
canUseTool is passed into call() rather than called before it — this lets tools that spawn sub-tools forward the permission function to their children. onProgress is optional, used for streaming partial results to the UI while the tool runs. isConcurrencySafe() and isReadOnly() are per-call decisions (they receive the input), not per-tool constants.
Before — a tool written as a plain function:
async function readFile(path: string, maxLines?: number): Promise<string> {
const content = await fs.readFile(path, 'utf-8')
return content
}
After — same capability as a proper Tool:
// Source: src/tools/FileReadTool/FileReadTool.ts
// inputSchema drives LLM JSON schema, validation, and TypeScript types simultaneously
const inputSchema = lazySchema(() =>
z.strictObject({
file_path: z.string().describe('Absolute path to the file to read'),
limit: z.number().int().positive().optional().describe('Max lines to read'),
offset: z.number().int().nonnegative().optional().describe('Line to start reading from'),
})
)
export const FileReadTool = buildTool({
name: FILE_READ_TOOL_NAME,
// isConcurrencySafe: reading never mutates, safe to run in parallel
isConcurrencySafe() { return true },
isReadOnly() { return true },
async checkPermissions(input, context) {
return checkReadPermissionForTool(FileReadTool, input, context.getAppState().toolPermissionContext)
},
async call({ file_path, limit, offset }, context, _canUseTool?) {
const content = await readFileInRange(file_path, offset, limit)
// Return data to the LLM as a structured tool result block
return { data: { type: 'text', file: { filePath: file_path, content } } }
},
async description(input) {
// Description is shown to the user (not the LLM) in permission prompts
return `Read ${input.file_path}`
},
get inputSchema() { return inputSchema() },
})
context.getAppState()tool-definition — the complete guide to implementing a Tool correctlypermission-system — how canUseTool works and how to define permission rulestask-system — how to spawn and track background work from a Toolasync-concurrency — how isConcurrencySafe affects parallel executionWhat SKILL.md sets; muted values are Claude Code's defaults
Generated from the plugin's indexed repository (techymt/claude-code-superpowers) — no native marketplace selected
npx claudepluginhub p/techymt-claude-code-superpowers16 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-skillsOther plugins' skills for the same job