Command System
How slash commands work — the command registry, command types, and the execution flow.
Command Types
Every slash command is one of three types:
PromptCommand
Content is injected into the conversation as a message, and the model processes it. Used for skills and AI-powered commands.
type PromptCommand = {
type: 'prompt'
getPromptForCommand(args: string, context: CommandContext): ContentBlockParam[]
}
Examples: Skills (/commit, /review-pr), any command that needs the model to act.
LocalCommand
Executes immediately without involving the model. Used for configuration and navigation.
type LocalCommand = {
type: 'local'
load(): Promise<{ call(args: string, context: CommandContext): void }>
}
Examples: /help, /clear, /model, /config.
LocalJSXCommand
Renders a React component inline in the REPL. Used for interactive UI elements.
type LocalJSXCommand = {
type: 'local-jsx'
load(): Promise<{ call(onDone: Function, context: CommandContext, args: string): ReactNode }>
}
Examples: /mcp (shows MCP server status UI), /memory (shows memory browser).
Command Registry
Commands are registered from multiple sources during initialization:
Registration
The command registry uses eager imports — built-in commands are imported at the top of src/commands.ts, not lazily loaded. This means all command modules are evaluated at startup:
import { clearCommand } from './commands/clear.js'
import { helpCommand } from './commands/help.js'
import { modelCommand } from './commands/model.js'
import { commitCommand } from './commands/commit.js'
// ... 60+ imports
// Some commands are environment-gated
// (e.g., agents-platform only loads when USER_TYPE === 'ant')
Skills and plugin commands are added dynamically after initialization:
// Skills become PromptCommands
for (const skill of loadedSkills) {
registry.set(skill.name, {
type: 'prompt',
name: skill.name,
description: skill.description,
getPromptForCommand: (args) => skill.getContent(args),
})
}
Command Base Interface
All commands share a base:
type CommandBase = {
name: string
description: string
aliases?: string[]
isEnabled?(): boolean // Dynamic enable/disable
isHidden?: boolean // Hide from /help
availability?: ('claude-ai' | 'console')[] // Platform-specific
}
Built-in Commands (100+)
Commands are organized by function:
| Category | Commands | Type |
|---|---|---|
| Session | /clear, /resume, /continue | Local |
| Config | /model, /config, /permissions | Local |
| Memory | /memory, /forget | Local/JSX |
| Development | /commit, /review-pr | Prompt (Skills) |
| MCP | /mcp, /mcp-servers | Local/JSX |
| Debug | /debug, /verbose, /cost | Local |
| Navigation | /help, /commands | Local |
| Task | /tasks, /background | Local/JSX |
That table is only the architectural overview. The real registry in src/commands.ts is broader and also merges bundled skills, user skill-directory commands, plugin commands, workflow-generated commands, and dynamic skills discovered during execution.
See the Command Catalog appendix for the categorized source-backed map.
Workflow-Generated Commands
When the WORKFLOW_SCRIPTS feature is enabled, the command registry also merges workflow-generated commands:
const workflowCommands = feature('WORKFLOW_SCRIPTS')
? await getWorkflowCommands(cwd)
: []
return [...baseCommands, ...workflowCommands]
The recovered source proves two architectural points:
| What Exists | Evidence |
|---|---|
| Workflow commands are generated dynamically | src/commands.ts loads getWorkflowCommands(cwd) instead of hardcoding names |
| They are tagged as a distinct command kind | formatDescriptionWithSource(cmd) appends (workflow) when cmd.kind === 'workflow' |
| There is also a top-level workflow command surface | src/commands.ts conditionally loads ./commands/workflows/index.js |
The recovered source tree does not include the full workflow-command implementation, so this page only documents the registry integration that is directly visible in src/commands.ts and src/tools/WorkflowTool/.
Execution Flow
Key Source Files
| File | Purpose |
|---|---|
src/commands.ts | Command registry and loaders |
src/types/command.ts | Command type definitions |
src/skills/ | Bundled skill commands added to the registry |
src/tools/WorkflowTool/ | Workflow-generated command support when enabled |
src/commands/ | 60+ command implementations (207 files) |