/claude-code-superpowers:hot-pathsfrom claude-code-superpowers
Teaches startup and runtime performance patterns: lazySchema() for deferred Zod parsing, feature() flags for dead code elimination, memoize() for repeated computations, parallel initialization with Promise.all(), and profileCheckpoint() for tracking load times. Use when writing code that runs at startup, on every turn, or in a hot 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.
Claude Code has three hot paths: startup (module loading before first prompt), per-turn (context assembly before each API call), and per-tool-call (schema validation and permission checking for every tool use). Each has different performance constraints and different techniques.
For startup: use lazySchema() to defer Zod parsing, use feature() flags to eliminate dead code at build time, parallelize independent I/O with Promise.all(), and track timing with profileCheckpoint().
For per-turn: memoize expensive computations (git status, file system state) that don't change mid-conversation. Clear memoized values only when the underlying state actually changes.
For per-tool-call: lazySchema() ensures schema objects are built at most once per process lifetime (on first access), not once per call.
Claude Code starts a new process on every invocation. Users expect the prompt to appear in under a second. With ~512K lines of TypeScript across 1,884 files, naive module loading would be too slow. The techniques below are how the team keeps startup under a second on typical developer machines.
The per-turn hot path is also user-visible: every time the LLM needs to generate a response, Claude Code assembles a system prompt that includes git status, open file list, working directory, and recent file changes. This assembly runs before each API call. If it were slow, every turn would feel sluggish.
Startup:
lazySchema(() => z.object({...})) from utils/lazySchema.ts. The schema is built only when first accessed, not when the module loads.feature('FLAG_NAME') from bun:bundle for conditional imports. Bun evaluates these at build time and tree-shakes unused code. An unused feature flag means the code is not included in the bundle.profileCheckpoint('label') to measure time between initialization steps during development.Promise.all().Per-turn:
5. Use memoize() from lodash for functions that are expensive and called multiple times per conversation (git status, workspace file enumeration).
6. Clear memoized values via cache.clear?.() when the underlying state changes (e.g., after a file write or git commit).
Per-tool-call:
7. lazySchema() schemas are effectively memoized at module scope — no additional caching needed.
8. For permission rule matching, pre-compile patterns once and reuse them.
// Source: src/tools/FileReadTool/FileReadTool.ts (lazySchema for deferred init)
import { lazySchema } from '../../utils/lazySchema.js'
// Schema construction deferred until first tool invocation — not at module load
const inputSchema = lazySchema(() =>
z.object({
file_path: z.string(),
limit: z.number().optional(),
offset: z.number().optional(),
})
)
// Source: src/main.tsx (feature flags for dead code elimination)
// Bun evaluates feature() at build time — unused modules not in bundle
const assistantModule = feature('KAIROS')
? require('./assistant/index.js') as typeof import('./assistant/index.js')
: null
const kairosGate = feature('KAIROS')
? require('./assistant/gate.js') as typeof import('./assistant/gate.js')
: null
// Source: src/context.ts (memoize for per-conversation caching)
import { memoize } from 'lodash-es'
export const getGitStatus = memoize(async (): Promise<string | null> => {
// This runs once per conversation, not once per turn
// Five git commands parallelized — not sequential
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']),
])
// ...
})
// Cache is cleared when state changes (e.g., after git commit)
getGitStatus.cache.clear?.()
// Source: src/main.tsx (profileCheckpoint for startup profiling)
profileCheckpoint('imports_loaded')
await initializeConfig()
profileCheckpoint('config_loaded')
await Promise.all([
prefetchKeychain(),
connectMCPServers(),
])
profileCheckpoint('parallel_init_done')
The --no-optional-locks flag in git commands is a performance detail: by default git acquires a lock file before reading index state. --no-optional-locks skips that when the operation doesn't need the lock, saving ~20ms per command. On five parallel commands, this saves ~100ms.
Before — schema built at module load, expensive init not parallelized:
// Module load time: slow — Zod builds validators immediately
const inputSchema = z.object({
file_path: z.string(),
content: z.string(),
encoding: z.enum(['utf-8', 'base64']).optional(),
})
// Sequential initialization
async function initWorkspace() {
const config = await readConfig() // 50ms
const gitStatus = await getGitStatus() // 120ms
const files = await listOpenFiles() // 30ms
// Total: ~200ms sequential
return { config, gitStatus, files }
}
After — lazy schema, parallel init:
// Schema deferred — no cost at module load time
const inputSchema = lazySchema(() =>
z.object({
file_path: z.string(),
content: z.string(),
encoding: z.enum(['utf-8', 'base64']).optional(),
})
)
// Parallel initialization — total time = slowest operation (~120ms)
async function initWorkspace() {
const [config, gitStatus, files] = await Promise.all([
readConfig(), // 50ms — runs concurrently
getGitStatus(), // 120ms — runs concurrently (bottleneck)
listOpenFiles(), // 30ms — runs concurrently
])
return { config, gitStatus, files }
}
inputSchema is a bare z.object({...}) at module scope (not wrapped in lazySchema)Promise.all()-edfeature('FLAG') is not used for optional large features (assistant mode, voice mode, remote mode)memoize() with no cache key returns the same result for all inputslazySchema() for schemas used in tests or utilities — the startup savings are irrelevant thereasync-concurrency — Promise.all() for parallel I/Omodule-organisation — which modules are lazily loadedtypes-and-interfaces — lazySchema() wraps Zod schema definitionsWhat SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
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