Skip to main content

Slash Command System

Slash commands (/command) let users trigger operations directly in the REPL, from /compact to compress context to /memory to manage memories.

Command Interface

type Command = {
name: string
description: string
type: 'local' | 'prompt'
call?(args, context): Promise<CommandResult> // for local commands
isEnabled?(context): boolean
isHidden?: boolean
aliases?: string[]
whenToUse?: string // for skills
source?: 'builtin' | 'plugin' | 'skill' | ...
}

Command Registration

src/commands.ts merges all sources by priority:

1. Bundled skill commands
2. Built-in plugin skill commands
3. Disk skill commands
4. Workflow commands
5. Plugin commands
6. Plugin skills
7. Built-in slash commands (/compact, /memory, etc.)

Built-in Commands (~50)

CommandDescription
/compactContext compression
/memoryMemory management
/configSettings management
/reviewCode review
/doctorEnvironment diagnostics
/mcpMCP server management
/login / /logoutAuthentication
/clearClear session
/resumeRestore previous session
/planEnter/exit plan mode
/vimToggle Vim mode
/themeChange theme
/costView usage cost
/diffView changes
/tasksView background tasks
/skillsView available skills

Each command lives in src/commands/<name>/ with an index.ts entry.

Execution Flow

Command Queue

Commands can be queued during the agent loop, drained at each iteration via getCommandsByMaxPriority(). Command lifecycle notifications (started / completed) are tracked via notifyCommandLifecycle().

Key Source Files

FileResponsibility
src/commands.tsCommand registry: getCommands(), priority merging
src/commands/~50 command implementations
src/utils/messageQueueManager.tsCommand queue management
src/utils/commandLifecycle.tsLifecycle notifications

Next

Go to 16-design-patterns.md for a summary of key design patterns.

Hands-on Experiment

This chapter has a corresponding Python experiment:

Lab 15 — Command System

Covers: slash commands, command registry, command queue

cd experiments && python -m exp_15_command_system.main --mock