Slash Command System
Relevant source files
The following files were used as context for generating this wiki page:
The Slash Command System is a core architectural component of the Autohand CLI designed to provide users with direct control over the agent's state, configuration, and session management. By using the / prefix, users can bypass the natural language processing loop to execute specific, deterministic actions such as switching models, managing memories, or resetting conversations.
This system is built on a modular, lazy-loaded architecture where individual commands are isolated into separate files for better maintainability and testability. It integrates deeply with the CLI's interactive loop, providing a unified framework for command detection, auto-completion, and execution.
Sources: prd/command-ux-spec.md:5-11, src/commands/README.md:1-12
System Architecture
The architecture consists of three primary layers: the registry, the handler, and the individual command modules. The system is designed to be extensible, allowing developers to add new commands by defining metadata and implementation functions.
Components
| Component | Responsibility |
|---|---|
Registry (SLASH_COMMANDS) | A collection of metadata objects defining command names, descriptions, and implementation status. |
Processor (slashCommandProcessor) | Detects the / prefix and manages the execution pipeline, including optional confirmation modals. |
Handler (SlashCommandHandler) | Orchestrates the execution logic by mapping command strings to their respective implementation modules. |
Context (SlashCommandContext) | A shared interface providing commands access to system managers (Session, Memory, Permission, etc.). |
Sources: src/core/slashCommands.ts:31-62, src/core/slashCommandTypes.ts:14-39, prd/command-ux-spec.md:13-23
Architecture Overview
This diagram illustrates the high-level flow from user input detection to command execution.
The flow starts with input capture and ends with a specific action executed by a command module using the system context.
Sources: prd/command-ux-spec.md:61-66, src/commands/README.md:37-45
Core Data Structures
SlashCommand Metadata
Each command must define a metadata object of type SlashCommand. This is used for discovery and documentation.
export interface SlashCommand {
command: string;
description: string;
implemented: boolean;
prd?: string; // Optional reference to requirement document
}
Sources: src/core/slashCommandTypes.ts:42-47
SlashCommandContext
The context object provides commands with the necessary interfaces to interact with the broader system. Key managers included in the context are:
sessionManager: Handles session persistence and loading.memoryManager: Manages project and user-level memories.permissionManager: Controls tool execution approvals.llm: Access to the underlying LLM provider for model-related tasks.skillsRegistry: Management of specialized agent skills.
Sources: src/core/slashCommandTypes.ts:16-39
Command Execution Flow
When a user submits a command, the system follows a specific sequence to resolve and execute the logic.
The system uses dynamic imports to ensure that command code is only loaded into memory when explicitly invoked by the user.
Sources: src/commands/README.md:37-45, src/core/agent.ts:489-497
Command Categories and Implementation
The system supports a wide array of commands categorized by their functional domain.
Session and State Management
| Command | Purpose |
|---|---|
/new | Resets the conversation context and starts a fresh session. |
/undo | Reverts the last file mutation performed by the agent. |
/session | Displays details of the currently active session. |
/resume | Resumes a previously saved session by its ID. |
Sources: src/core/slashCommands.ts:37-49, src/commands/README.md:15-26
Configuration and System
| Command | Purpose |
|---|---|
/model | Triggers the model selection UI to switch LLM providers or models. |
/status | Shows workspace status, token usage, and context window limits. |
/permissions | Manages tool execution permissions and white/blacklists. |
/hooks | Configuration for lifecycle hooks (session-start, stop, etc.). |
Sources: src/core/slashCommands.ts:38-58, src/core/agent.ts:1146-1153
Skills and Agents
| Command | Purpose |
|---|---|
/skills | Lists, installs, or activates specialized agent skills. |
/skills new | Launches a wizard to generate a new skill from a description. |
/agents | Manages sub-agents for delegation and parallel execution. |
Sources: src/core/slashCommands.ts:45-60, src/commands/skills-new.ts:24-30
Implementation Details in AutohandAgent
The AutohandAgent class initializes the SlashCommandHandler within its constructor, passing it a context object that maps agent-level methods to the SlashCommandContext interface.
this.slashHandler = new SlashCommandHandler({
promptModelSelection: () => this.promptModelSelection(),
createAgentsFile: () => this.createAgentsFile(),
sessionManager: this.sessionManager,
memoryManager: this.memoryManager,
permissionManager: this.permissionManager,
// ... other context properties
}, SLASH_COMMANDS);
Sources: src/core/agent.ts:352-371
Command Normalization
The agent handles multi-word commands (e.g., /skills new) by normalizing the input before passing it to the handler. This ensures that sub-commands are correctly identified as single units.
Sources: src/core/agent.ts:480-488
Conclusion
The Slash Command System provides a robust and extensible control plane for the Autohand CLI. Its design prioritizes developer experience through modular command files and user experience through fast, lazy-loaded execution and a context-aware handler. By separating deterministic commands from the natural language reasoning loop, the system ensures reliable management of the agent's operating environment.