/claude-code-superpowers:async-concurrencyfrom claude-code-superpowers
Teaches 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.
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.
Claude Code's tool execution is mostly sequential — one tool at a time — but read-only tools can run in parallel when isConcurrencySafe() returns true. Cancellation is propagated via AbortController passed through ToolUseContext. Parallel initialization uses Promise.all(). Streaming partial results uses onProgress callbacks fed into a StreamingToolExecutor.
The key design: concurrency safety is a per-call decision, not a per-tool constant. A bash tool reading git status is safe to run concurrently. The same bash tool running npm install is not. The tool knows its own input and can make the right call.
In a developer session, the LLM often requests several read operations in sequence (read file A, read file B, check git status). If these were strictly sequential, the user would wait for three round-trips to disk. isConcurrencySafe: true tells the scheduler it can run these in parallel, reducing perceived latency.
Cancellation is critical for long-running tools (bash commands, web fetches). When the user presses Ctrl+C, the AbortController's signal fires and all in-flight tool calls must stop promptly. A tool that ignores context.abortController.signal will keep running after the user cancelled, blocking the next turn.
Git status is a concrete example: Claude Code parallelizes five git commands — branch, default branch, status, recent log, and user name — with a single Promise.all(). This collapses what would be ~500ms of sequential I/O into a single ~100ms concurrent batch.
isConcurrencySafe(input): return true only for operations that don't mutate state. File reads, globs, searches, and git status commands are safe. File writes, bash mutations, and agent spawns are not.isReadOnly(input): return true for operations that make no persistent changes. Used to determine if the tool can be skipped in speculation mode.context.abortController.signal to all async I/O: fetch(), execFile(), file streams. This ensures immediate cancellation on user interrupt.signal.aborted at checkpoints in long-running loops.Promise.all() — don't await them sequentially.onProgress(progressData) as work proceeds. The UI subscribes to these calls to show live output.// Source: src/context.ts (parallel git status — five concurrent commands)
export const getGitStatus = memoize(async (): Promise<string | null> => {
const isGit = await getIsGit()
if (!isGit) return null
// Five independent git commands run in parallel with Promise.all
// Sequential would take ~500ms; parallel takes ~100ms
const [branch, mainBranch, status, log, userName] = await Promise.all([
getBranch(),
getDefaultBranch(),
execFileNoThrow(gitExe(), ['--no-optional-locks', 'status', '--short']),
execFileNoThrow(gitExe(), ['--no-optional-locks', 'log', '--oneline', '-n', '5']),
execFileNoThrow(gitExe(), ['config', 'user.name']),
])
// ... format and return
})
// Source: src/Tool.ts (isConcurrencySafe is input-dependent for BashTool)
export const BashTool: Tool<typeof inputSchema> = {
isConcurrencySafe(input) {
// Only safe if the command is classified as search/read
const classification = isSearchOrReadBashCommand(input.command)
return classification.isSearch || classification.isRead
},
isReadOnly(input) {
const classification = isSearchOrReadBashCommand(input.command)
return classification.isSearch || classification.isRead
},
async call(args, context, canUseTool) {
// AbortController signal passed to shell execution
const result = await executeShell(args.command, {
signal: context.abortController.signal,
cwd: getCwd(),
})
return { type: 'success', data: result.stdout }
},
}
// Source: src/Tool.ts (onProgress for streaming output)
async call(args, context, canUseTool, parentMessage, onProgress) {
const proc = spawnProcess(args.command)
proc.stdout.on('data', (chunk: Buffer) => {
// Stream partial output to UI as it arrives
onProgress?.({
type: 'output',
content: chunk.toString(),
})
})
const exitCode = await proc.exitCode
return { type: 'success', data: proc.collectedOutput }
}
The memoize() on getGitStatus is subtle: git status is called at conversation start and might be called again if a tool triggers re-evaluation. Memoizing prevents running all five git commands twice. The cache is cleared when state changes (e.g., branch switch).
Before — read-only tool that blocks concurrent execution unnecessarily:
export const SearchTool: Tool<typeof inputSchema> = {
// Wrong: returns false for a read-only operation, forcing serialization
isConcurrencySafe: (_input) => false,
isReadOnly: (_input) => false,
async call(args, context, canUseTool) {
// No signal passed — ignores cancellation
const results = await searchFiles(args.pattern, args.directory)
return { data: results }
},
}
After — tool correctly declares concurrency and respects cancellation:
import { AbortError } from '../../utils/errors.js'
export const SearchTool: Tool<typeof inputSchema> = {
// Search is always read-only — safe to run in parallel with other searches
isConcurrencySafe: (_input) => true,
isReadOnly: (_input) => true,
async call(args, context, canUseTool, _parentMessage, onProgress) {
const results: string[] = []
for await (const match of streamSearchResults(args.pattern, args.directory)) {
// Check cancellation at each result — don't process after user cancelled
if (context.abortController.signal.aborted) {
throw new AbortError('Search was cancelled.')
}
results.push(match)
// Stream partial results to UI for responsive feedback
onProgress?.({ type: 'partial_results', count: results.length })
}
return { data: results }
},
}
isConcurrencySafe: () => falsecontext.abortController.signal to their I/O operationsPromise.all()-edisConcurrencySafe: true — there are no legitimate parallel-mutation patterns herePromise.all() for operations that depend on each other's outputonProgress is optional — don't emit progress for instant operations; the overhead is not worth ittool-definition — where isConcurrencySafe and isReadOnly are declarederror-handling — handling AbortError from cancelled async operationshot-paths — parallel initialization as a startup performance patternWhat SKILL.md sets; muted values are Claude Code's defaults
16 skills in this plugin
/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.
/module-organisationTeaches Claude Code's module organization: tools/ for capabilities, commands/ for user-facing slash commands, services/ for business logic, state/ for AppState, utils/ for pure utilities, hooks/ for React state, and components/ for TUI rendering. Use this when deciding where to put new code or when tracing an unfamiliar behavior to its source. The division is by responsibility boundary, not by feature.
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