How to Use Slash Commands with OpenClaude: Complete Guide with Examples
Answer: OpenClaude lets you trigger built‑in functionality directly from the chat UI by typing commands that start with a forward slash (/). These slash commands bypass the LLM response flow and invoke deterministic CLI‑style handlers for tasks like updating the tool, managing Git branches, or clearing context.
Slash commands are a core power feature in OpenClaude, the open‑source AI coding assistant. Instead of switching to a terminal, you can run repository operations, system updates, and utility functions without leaving the conversation. This article explains the parsing pipeline, shows runnable examples, and maps every key source file so you can extend commands yourself.
How Slash Commands Work in OpenClaude
The slash command system consists of three coordinated layers: parsing, routing, and execution. Each user message flows through this pipeline before any LLM processing occurs.
| Component | Role | Source File |
|---|---|---|
| Parser | Extracts command name and arguments from raw input | [src/utils/slashCommandParsing.ts](https://github.com/Gitlawb/openclaude/blob/main/src/utils/slashCommandParsing.ts) |
| Router | Detects slash prefix and dispatches to handler | [src/utils/processUserInput/processUserInput.ts](https://github.com/Gitlawb/openclaude/blob/main/src/utils/processUserInput/processUserInput.ts) |
| Executor | Runs the matched command and returns results | [src/utils/processUserInput/processSlashCommand.test.ts](https://github.com/Gitlawb/openclaude/blob/main/src/utils/processUserInput/processSlashCommand.test.ts) |
| Command Registry | Maps names like /update to implementation files |
src/commands/ |
Because commands execute before token generation, they cost nothing in your LLM budget and complete in milliseconds.
Step‑by‑Step Command Flow
- User input detection —
processUserInputchecksinput.startsWith('/') - Tokenization —
parseSlashCommandstrips the/, splits on whitespace, and returns{ command: string, args: string[] } - Registry lookup — the system searches
src/commands/for a matching handler - Execution — the handler runs with full Node.js/Bun access
- Response rendering — output appears as a system message in the chat UI
This design mirrors traditional IRC or Slack slash commands but operates entirely client‑side.
Available Slash Commands in OpenClaude
Based on the command implementations in the source tree, here are the primary slash commands you can use today:
| Command | Purpose | Implementation |
|---|---|---|
/help |
Lists all registered commands | Central registry printer |
/update |
Pulls the latest OpenClaude release | [src/commands/update/index.ts](https://github.com/Gitlawb/openclaude/blob/main/src/commands/update/index.ts) |
/branch <name> |
Creates and checks out a new Git branch | [src/commands/branch/branch.ts](https://github.com/Gitlawb/openclaude/blob/main/src/commands/branch/branch.ts) |
/clear |
Wipes conversation context from memory | [src/commands/clear/clear.ts](https://github.com/Gitlawb/openclaude/blob/main/src/commands/clear/clear.ts) |
Additional commands follow the same pattern—each is a self‑contained module under src/commands/.
Practical Code Examples
Run a system update without leaving chat
// Type in the chat input:
/update
The handler spawns the update script, streams progress, and surfaces success or failure as a system message.
Create a feature branch instantly
// Create and switch to a new branch:
/branch feature-login
Behind the scenes, this executes git checkout -b feature-login and reports the result.
Clear conversation history
// Reset context to start fresh:
/clear
The clear command nullifies the in‑memory message array, freeing context window space.
Disable slash commands entirely
Start OpenClaude with the feature flag to treat / input as plain text:
openclaude --disable-slash-commands
This flag is defined in [web/src/data/cliFlags.ts](https://github.com/Gitlawb/openclaude/blob/main/web/src/data/cliFlags.ts).
Extending Slash Commands
To add a custom command:
- Create a new folder under
src/commands/<commandName>/ - Export a default function accepting
(args: string[], context: CommandContext) => Promise<string> - The system auto‑registers your command on next startup
The test suite in [processSlashCommand.test.ts](https://github.com/Gitlawb/openclaude/blob/main/src/utils/processUserInput/processSlashCommand.test.ts) validates argument parsing and error handling, ensuring new commands integrate cleanly.
Key Implementation Files
Summary
- Prefix with
/to trigger any OpenClaude slash command from the chat UI. - Fast execution — commands run before LLM processing, saving tokens and time.
- Modular architecture — add commands by creating files in
src/commands/. - Built‑in commands include
/update,/branch,/clear, and/help. - Disable when needed via the
--disable-slash-commandsCLI flag.
Frequently Asked Questions
What happens if I type a slash command that doesn't exist?
OpenClaude returns a system message indicating the command is unrecognized and suggests running /help to see available options. No LLM call is made.
Can I pass flags or options to slash commands?
Yes. parseSlashCommand preserves all whitespace‑separated tokens after the command name as an array. Individual handlers parse flags using their own logic—check the implementation file for each command's supported options.
Are slash commands available in the programmatic API?
The core parsing and execution utilities are exported from src/utils/slashCommandParsing.ts and processUserInput.ts, so you can invoke the same pipeline programmatically. However, the intended interface is the interactive chat UI documented in web/src/pages/docs/slash-commands.astro.
Do slash commands work when offline?
Most commands work offline because they execute locally via Bun/Node.js. Exceptions like /update require network access to fetch releases. The handler returns an appropriate error if connectivity is unavailable.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →