Why this matters
Commands solve a simple problem: they give the person using Claude Code a clear, predictable way to ask for named actions without needing to know the internal wiring.
Commands are the user-facing control surface. Tools are the model-facing action surface. A person types a slash command; the runtime turns that into one of the command kinds; the result changes the session in a specific way.
user slash command -> command kind -> effect on session
The rest of this subtree is about the command side of that split. The child pages study each execution style separately, but this root page keeps the shared shape and the registry in view.
One control surface, three execution styles
The command vocabulary lives in types/command.ts. That file defines the
shared contract first, then narrows the actual work into three execution styles:
prompt commands, local commands, and local JSX commands.
export type LocalCommandResult =
| { type: 'text'; value: string }
| {
type: 'compact'
compactionResult: CompactionResult
displayText?: string
}
| { type: 'skip' } // Skip messages
export type PromptCommand = {
type: 'prompt'
progressMessage: string
contentLength: number // Length of command content in characters (used for token estimation)
argNames?: string[]
allowedTools?: string[]
model?: string
source: SettingSource | 'builtin' | 'mcp' | 'plugin' | 'bundled'
pluginInfo?: {
pluginManifest: PluginManifest
repository: string
}
disableNonInteractive?: boolean
// Hooks to register when this skill is invoked
hooks?: HooksSettings
// Base directory for skill resources (used to set CLAUDE_PLUGIN_ROOT environment variable for skill hooks)
skillRoot?: string
// Execution context: 'inline' (default) or 'fork' (run as sub-agent)
// 'inline' = skill content expands into the current conversation
// 'fork' = skill runs in a sub-agent with separate context and token budget
context?: 'inline' | 'fork'
// Agent type to use when forked (e.g., 'Bash', 'general-purpose')
// Only applicable when context is 'fork'
agent?: string
effort?: EffortValue
// Glob patterns for file paths this skill applies to
// When set, the skill is only visible after the model touches matching files
paths?: string[]
getPromptForCommand(
args: string,
context: ToolUseContext,
): Promise<ContentBlockParam[]>
}
/**
* The call signature for a local command implementation.
*/
export type LocalCommandCall = (
args: string,
context: LocalJSXCommandContext,
) => Promise<LocalCommandResult>
/**
* Module shape returned by load() for lazy-loaded local commands.
*/
export type LocalCommandModule = {
call: LocalCommandCall
}
type LocalCommand = {
type: 'local'
supportsNonInteractive: boolean
load: () => Promise<LocalCommandModule>
}
export type LocalJSXCommandContext = ToolUseContext & {
canUseTool?: CanUseToolFn
setMessages: (updater: (prev: Message[]) => Message[]) => void
options: {
dynamicMcpConfig?: Record<string, ScopedMcpServerConfig>
ideInstallationStatus: IDEExtensionInstallationStatus | null
theme: ThemeName
}
onChangeAPIKey: () => void
onChangeDynamicMcpConfig?: (
config: Record<string, ScopedMcpServerConfig>,
) => void
onInstallIDEExtension?: (ide: IdeType) => void
resume?: (
sessionId: UUID,
log: LogOption,
entrypoint: ResumeEntrypoint,
) => Promise<void>
}
export type ResumeEntrypoint =
| 'cli_flag'
| 'slash_command_picker'
| 'slash_command_session_id'
| 'slash_command_title'
| 'fork'
export type CommandResultDisplay = 'skip' | 'system' | 'user'
/**
* Callback when a command completes.
* @param result - Optional user-visible message to display
* @param options - Optional configuration for command completion
* @param options.display - How to display the result: 'skip' | 'system' | 'user' (default)
* @param options.shouldQuery - If true, send messages to the model after command completes
* @param options.metaMessages - Additional messages to insert as isMeta (model-visible but hidden)
*/
export type LocalJSXCommandOnDone = (
result?: string,
options?: {
display?: CommandResultDisplay
shouldQuery?: boolean
metaMessages?: string[]
nextInput?: string
submitNextInput?: boolean
},
) => void
/**
* The call signature for a local JSX command implementation.
*/
export type LocalJSXCommandCall = (
onDone: LocalJSXCommandOnDone,
context: ToolUseContext & LocalJSXCommandContext,
args: string,
) => Promise<React.ReactNode>
/**
* Module shape returned by load() for lazy-loaded commands.
*/
export type LocalJSXCommandModule = {
call: LocalJSXCommandCall
}
type LocalJSXCommand = {
type: 'local-jsx'
/**
* Lazy-load the command implementation.
* Returns a module with a call() function.
* This defers loading heavy dependencies until the command is invoked.
*/
load: () => Promise<LocalJSXCommandModule>
}
/**
* Declares which auth/provider environments a command is available in.
*
* This is separate from `isEnabled()`:
* - `availability` = who can use this (auth/provider requirement, static)
* - `isEnabled()` = is this turned on right now (GrowthBook, platform, env vars)
*
* Commands without `availability` are available everywhere.
* Commands with `availability` are only shown if the user matches at least one
* of the listed auth types. See meetsAvailabilityRequirement() in commands.ts.
*
* Example: `availability: ['claude-ai', 'console']` shows the command to
* claude.ai subscribers and direct Console API key users (api.anthropic.com),
* but hides it from Bedrock/Vertex/Foundry users and custom base URL users.
*/
export type CommandAvailability =
// claude.ai OAuth subscriber (Pro/Max/Team/Enterprise via claude.ai)
| 'claude-ai'
// Console API key user (direct api.anthropic.com, not via claude.ai OAuth)
| 'console'
export type CommandBase = {
availability?: CommandAvailability[]
description: string
hasUserSpecifiedDescription?: boolean
/** Defaults to true. Only set when the command has conditional enablement (feature flags, env checks, etc). */
isEnabled?: () => boolean
/** Defaults to false. Only set when the command should be hidden from typeahead/help. */
isHidden?: boolean
name: string
aliases?: string[]
isMcp?: boolean
argumentHint?: string // Hint text for command arguments (displayed in gray after command)
whenToUse?: string // From the "Skill" spec. Detailed usage scenarios for when to use this command
version?: string // Version of the command/skill
disableModelInvocation?: boolean // Whether to disable this command from being invoked by models
userInvocable?: boolean // Whether users can invoke this skill by typing /skill-name
loadedFrom?:
| 'commands_DEPRECATED'
| 'skills'
| 'plugin'
| 'managed'
| 'bundled'
| 'mcp' // Where the command was loaded from
kind?: 'workflow' // Distinguishes workflow-backed commands (badged in autocomplete)
immediate?: boolean // If true, command executes immediately without waiting for a stop point (bypasses queue)
isSensitive?: boolean // If true, args are redacted from the conversation history
/** Defaults to `name`. Only override when the displayed name differs (e.g. plugin prefix stripping). */
userFacingName?: () => string
}
export type Command = CommandBase &
(PromptCommand | LocalCommand | LocalJSXCommand)
commands.ts assembles the visible slash-command list from several sources.
First it defines the memoized registry, then it filters and augments that
registry for the current workspace.
const COMMANDS = memoize((): Command[] => [
addDir,
advisor,
agents,
branch,
btw,
chrome,
clear,
color,
compact,
config,
copy,
desktop,
context,
contextNonInteractive,
cost,
diff,
doctor,
effort,
exit,
fast,
files,
heapDump,
help,
ide,
init,
keybindings,
installGitHubApp,
installSlackApp,
mcp,
memory,
mobile,
model,
outputStyle,
remoteEnv,
plugin,
pr_comments,
releaseNotes,
reloadPlugins,
rename,
resume,
session,
skills,
stats,
status,
statusline,
stickers,
tag,
theme,
feedback,
review,
ultrareview,
rewind,
securityReview,
terminalSetup,
upgrade,
extraUsage,
extraUsageNonInteractive,
rateLimitOptions,
usage,
usageReport,
vim,
...(webCmd ? [webCmd] : []),
...(forkCmd ? [forkCmd] : []),
...(buddy ? [buddy] : []),
...(proactive ? [proactive] : []),
...(briefCommand ? [briefCommand] : []),
...(assistantCommand ? [assistantCommand] : []),
...(bridge ? [bridge] : []),
...(remoteControlServerCommand ? [remoteControlServerCommand] : []),
...(voiceCommand ? [voiceCommand] : []),
thinkback,
thinkbackPlay,
permissions,
plan,
privacySettings,
hooks,
exportCommand,
sandboxToggle,
...(!isUsing3PServices() ? [logout, login()] : []),
passes,
...(peersCmd ? [peersCmd] : []),
tasks,
...(workflowsCmd ? [workflowsCmd] : []),
...(torch ? [torch] : []),
...(process.env.USER_TYPE === 'ant' && !process.env.IS_DEMO
? INTERNAL_ONLY_COMMANDS
: []),
])
export async function getCommands(cwd: string): Promise<Command[]> {
const allCommands = await loadAllCommands(cwd)
// Get dynamic skills discovered during file operations
const dynamicSkills = getDynamicSkills()
// Build base commands without dynamic skills
const baseCommands = allCommands.filter(
_ => meetsAvailabilityRequirement(_) && isCommandEnabled(_),
)
if (dynamicSkills.length === 0) {
return baseCommands
}
// Dedupe dynamic skills - only add if not already present
const baseCommandNames = new Set(baseCommands.map(c => c.name))
const uniqueDynamicSkills = dynamicSkills.filter(
s =>
!baseCommandNames.has(s.name) &&
meetsAvailabilityRequirement(s) &&
isCommandEnabled(s),
)
if (uniqueDynamicSkills.length === 0) {
return baseCommands
}
// Insert dynamic skills after plugin skills but before built-in commands
const builtInNames = new Set(COMMANDS().map(c => c.name))
const insertIndex = baseCommands.findIndex(c => builtInNames.has(c.name))
if (insertIndex === -1) {
return [...baseCommands, ...uniqueDynamicSkills]
}
return [
...baseCommands.slice(0, insertIndex),
...uniqueDynamicSkills,
...baseCommands.slice(insertIndex),
]
}
types/command.ts defines the vocabulary. commands.ts assembles the command
surface that people actually see. The child pages take those two ideas apart
one execution style at a time.
How this part breaks down
command-contracts-and-three-command-kindsStart with the shared contract: every command has the same outer shape, but the work happens in one of three styles:prompt,local, orlocal-jsx.command-data-structures-and-result-typesRead this appendix early if the command objects feel abstract. It introduces the recurring fields before later pages depend on them.command-registry-availability-and-dynamic-loadingSee howcommands.tsassembles built-ins, skills, plugins, workflows, and dynamic skills into one visible slash-command list.local-jsx-commands-and-ui-handoffsFollow the UI-heavy path where a slash command opens a screen, toggles a mode, or hands control to a React component.local-commands-and-session-side-effectsLearn the non-UI path where a command runs local code immediately and returns a concrete result to the session.prompt-commands-and-tool-bounded-instructionsStudy the third path: commands that return a prompt block, restrict tools, and ask the model to continue the work safely.