Skip to main content
Commands are user-facing actions invoked with a / prefix in the REPL (e.g., /commit, /review, /mcp). They live in src/commands/ and are registered in src/commands.ts (~25K lines).
Commands are distinct from tools. Tools are capabilities the LLM invokes autonomously during a query. Commands are actions the user invokes explicitly by typing /command-name.

Command types

Three command types cover the full range of use cases:
Sends a formatted prompt to the LLM with an injected tool allowlist. Used for AI-assisted actions like code review and commit message generation.
export type PromptCommand = {
  type: 'prompt'
  progressMessage: string
  contentLength: number
  argNames?: string[]
  allowedTools?: string[]   // Tool names or wildcard patterns
  model?: string            // Override the active model for this command
  source: SettingSource | 'builtin' | 'mcp' | 'plugin' | 'bundled'
  context?: 'inline' | 'fork'  // 'fork' runs as a sub-agent
  effort?: EffortValue
  getPromptForCommand(
    args: string,
    context: ToolUseContext,
  ): Promise<ContentBlockParam[]>
}
Example — the /insights command uses a lazy-loaded PromptCommand to defer a 113 KB module until invoked:
const usageReport: Command = {
  type: 'prompt',
  name: 'insights',
  description: 'Generate a report analyzing your Claude Code sessions',
  contentLength: 0,
  progressMessage: 'analyzing your sessions',
  source: 'builtin',
  async getPromptForCommand(args, context) {
    const real = (await import('./commands/insights.js')).default
    if (real.type !== 'prompt') throw new Error('unreachable')
    return real.getPromptForCommand(args, context)
  },
}

Command base shape

All three command types share a common CommandBase:
export type CommandBase = {
  name: string
  description: string
  aliases?: string[]
  availability?: CommandAvailability[]   // 'claude-ai' | 'console'
  isEnabled?: () => boolean              // GrowthBook / env var gating
  isHidden?: boolean                     // Hide from typeahead and /help
  argumentHint?: string                  // Displayed in gray after the command name
  whenToUse?: string                     // Usage guidance for the model
  isSensitive?: boolean                  // Args redacted from conversation history
  immediate?: boolean                    // Execute without waiting for a stop point
  userFacingName?: () => string          // Override the displayed name
}

export type Command = CommandBase & (PromptCommand | LocalCommand | LocalJSXCommand)

Defining a command

A minimal PromptCommand definition:
const command = {
  type: 'prompt',
  name: 'review',
  description: 'AI-powered code review of staged/unstaged changes',
  progressMessage: 'reviewing changes',
  contentLength: 0,
  allowedTools: ['Bash(git *)', 'FileRead(*)'],
  source: 'builtin',
  async getPromptForCommand(args, context) {
    return [{ type: 'text', text: buildReviewPrompt(args) }]
  },
} satisfies Command
allowedTools accepts the same wildcard pattern format as the permission system:
Bash(git *)      # Allow all git subcommands
FileRead(*)      # Allow reading any file
FileEdit(/src/*) # Allow edits only under src/

How commands are invoked

1

User types /command-name

The REPL input handler detects the / prefix and looks up the command by name (or alias) in the registered command list.
2

Command type dispatch

  • LocalCommandload() is called to lazy-load the module, then call() executes synchronously in-process. The text result appears in the REPL.
  • LocalJSXCommandload() is called, then call() returns a React node that the REPL renders as a full-screen overlay.
  • PromptCommandgetPromptForCommand() builds the message content, which is injected into the conversation and submitted to the Query Engine with the command’s allowedTools as the active tool filter.
3

LLM context injection (PromptCommand only)

The Query Engine receives the formatted prompt and the allowedTools list. Tools not matching the allowlist are excluded from the API call’s tool spec, restricting what the model can invoke during the command’s execution.

Feature-flag gating and conditional imports

src/commands.ts gates a number of commands behind bun:bundle feature flags. Commands inside inactive flags are completely absent from production builds:
import { feature } from 'bun:bundle'

// Dead code elimination: inactive flags strip these require() calls at build time
const proactive =
  feature('PROACTIVE') || feature('KAIROS')
    ? require('./commands/proactive.js').default
    : null

const bridge = feature('BRIDGE_MODE')
  ? require('./commands/bridge/index.js').default
  : null

const voiceCommand = feature('VOICE_MODE')
  ? require('./commands/voice/index.js').default
  : null
Environment-based conditional imports are used for internal-only commands:
const agentsPlatform =
  process.env.USER_TYPE === 'ant'
    ? require('./commands/agents-platform/index.js').default
    : null
Commands conditioned on process.env.USER_TYPE === 'ant' are Anthropic-internal and not available in public builds.

Command catalog

CommandSourceDescription
/commitcommit.tsCreate a git commit with an AI-generated message
/commit-push-prcommit-push-pr.tsCommit, push, and create a PR in one step
/branchbranch/Create or switch git branches
/diffdiff/View file changes (staged, unstaged, or against a ref)
/pr_commentspr_comments/View and address PR review comments
/rewindrewind/Revert to a previous state
CommandSourceDescription
/reviewreview.tsAI-powered code review of staged/unstaged changes
/security-reviewsecurity-review.tsSecurity-focused code review
/advisoradvisor.tsGet architectural or design advice
/bughunterbughunter/Find potential bugs in the codebase
CommandSourceDescription
/compactcompact/Compress conversation context to fit more history
/resumeresume/Restore a previous conversation session
/sessionsession/Manage sessions (list, switch, delete)
/exportexport/Export conversation to a file
/summarysummary/Generate a summary of the current session
/clearclear/Clear the conversation history
CommandSourceDescription
/configconfig/View or modify Claude Code settings
/permissionspermissions/Manage tool permission rules
/modelmodel/Switch the active model
/efforteffort/Adjust response effort level
/themetheme/Change the terminal color theme
/vimvim/Toggle vim mode for input
CommandSourceDescription
/mcpmcp/Manage MCP server connections
/pluginplugin/Install, remove, or manage plugins
/reload-pluginsreload-plugins/Reload all installed plugins
/skillsskills/View and manage skills
CommandSourceDescription
/doctordoctor/Run environment diagnostics
/statusstatus/Show system and session status
/costcost/Display token usage and estimated cost
/statsstats/Show session statistics
/versionversion.tsShow Claude Code version
CommandSourceDescription
/bridgebridge/Manage IDE bridge connections (feature-gated)
/ideide/Open in IDE
/desktopdesktop/Hand off to the desktop app
/teleportteleport/Transfer session to another device

See also

Build docs developers (and LLMs) love