How does the codebase parse and dispatch a slash command typed by the user, from input string to command handler invocation

en
100.0% sentence pass·20/20 cited·35/35 citations valid·93 fn·0 dec·619 sem
Command SystemPrompt InputInput Suggestions

Slash command parse and dispatch

Overview

This flow covers how a user-typed string starting with / is parsed into a command name and arguments, then dispatched to the correct handler . It is triggered from the prompt input submission path after the base user-input processor detects a slash prefix .

Steps

  1. The user submits text from the prompt input component, which routes non-bash input into the base user-input processor . That processor normalizes images and content blocks before considering slash-command handling .
  2. For bridge-origin input the base processor calls parseSlashCommand early to decide whether the command is safe to run remotely, short-circuiting unsafe commands with a local stdout message . Otherwise it hands the raw string to processSlashCommand .
  3. processSlashCommand invokes parseSlashCommand, which trims the input, verifies the leading /, splits on spaces, extracts commandName, detects an (MCP) marker, and joins the rest as args into a ParsedSlashCommand . A null result makes processSlashCommand return a synthetic "Commands are in the form /command [args]" error .
  4. processSlashCommand then checks hasCommand; if unknown it stats /commandName via the fs implementation to distinguish a file path from a typo, using looksLikeCommand as a character-class filter . Unknown-but-command-shaped input logs tengu_input_slash_invalid and returns an "Unknown skill" message .
  5. For a recognized command processSlashCommand delegates to getMessagesForSlashCommand with the parsed name, args, and ProcessUserInputContext . That function resolves the Command object via getCommand, which calls findCommand against context.options.commands and throws a ReferenceError listing available commands if missing .
  6. If the resolved command is a user-invocable prompt skill, usage is recorded before dispatch via the debounced tracker that persists through saveGlobalConfig . Commands with userInvocable === false are rejected with a message telling the user to ask Claude to invoke the skill .
  7. getMessagesForSlashCommand then switches on command.type: local-jsx commands resolve via a Promise-wrapped JSX handler, while prompt commands with context === 'fork' path into executeForkedSlashCommand which prepares a forked agent context and runs the sub-agent .
  8. Back in processSlashCommand, the returned SlashCommandResult is used to log tengu_input_command with plugin telemetry fields and to assemble the final ProcessUserInputBaseResult messages that feed the main query loop .
  9. The SkillTool path reuses the same parsing/dispatch machinery by importing processPromptSlashCommand and calling findCommand + recordSkillUsage itself when the model (not the user) invokes a skill .

State touched

Decisions

(none in whitelist)