One-Line Summary: Slash commands are user-typed shortcuts (/review, /test, /explain) that inject a parameterized prompt or invoke a workflow inside an active harness session — they are the keyboard-first surface for harness-extension UX, sitting alongside hooks (system-driven) and tools (model-driven).
Prerequisites: What is an AI harness, hooks and lifecycle events
What Are Slash Commands?
A slash command is a string the user types — /foo arg1 arg2 — that the harness interprets as a known shortcut rather than as a model prompt. The harness expands the command into a richer prompt (often with the user's args interpolated), or runs a programmatic action, then resumes the agent loop.
Slash commands are the harness's keyboard-driven UI. They are how a user invokes an extension without leaving the chat: instead of opening a panel or running a separate CLI, the user types /review and the harness composes the right prompt for a code review and dispatches it. Compared to hooks (system-triggered) and tools (model-triggered), slash commands are user-triggered — and that's the whole point: they give the user agency without breaking the conversational flow.
How They Work
In Claude Code, a slash command is a markdown file under .claude/commands/ with frontmatter declaring its name, description, and argument schema, followed by a templated prompt that uses the user-provided args. When the user types /foo bar baz, the harness:
- Parses
fooas a command name andbar bazas positional args. - Loads
.claude/commands/foo.md. - Substitutes the args into the prompt template.
- Sends the resulting prompt to the model as if the user had typed it.
Other harnesses follow similar shapes. Cursor uses inline commands and rules. Ruflo extends Claude Code's command system with marketplace-distributed plugins.
Why It Matters
Without slash commands, every harness extension would either need a separate CLI or expect the user to remember the right phrase to trigger the right behavior. The first option is friction; the second is unreliable. Slash commands solve both: they give extensions a discoverable, autocompletable surface inside the conversation. They are also the entry point for users who do not want to write code — typing /review is approachable; configuring settings.json is not.
Key Technical Details
- Argument schemas: Most harnesses support positional args; some support named args (
--strict,--scope=file). - Discoverability: Typing
/typically opens an autocomplete menu listing available commands with their descriptions. - Composability: A slash command can invoke sub-agents, MCP tools, or run shell commands — it is essentially a prompt with side-effecting hooks attached.
- Scoping: Project-local commands (
.claude/commands/) override or extend user-global commands (~/.claude/commands/). - Templating: Most use simple variable substitution (
{{arg1}}); a few support full templating engines. - Built-ins vs custom: Harnesses ship a small set (
/help,/clear,/compact,/model); the user defines the rest.
How Harnesses & Frameworks Implement This
| Harness / Framework | Slash command surface | Definition format |
|---|---|---|
| Claude Code | Native | Markdown in .claude/commands/ with frontmatter |
| Claude Agent SDK | Programmatic | Register Command instances |
| ruflo | Native + marketplace | Same as Claude Code, plus plugin-distributed |
| LangGraph | N/A — UI-layer concern | DIY |
| AutoGen | N/A | DIY |
| CrewAI | N/A | DIY |
| OpenAI Agents SDK | Limited | Closer to handoffs than slash commands |
| Codex CLI | Partial | Built-ins only; less extensible than Claude Code |
| Cursor | Native | Inline commands + custom rules |
Connections to Other Concepts
hooks-and-lifecycle-events.md— The system-triggered counterpart.skills-vs-tools.md— Skills overlap with slash commands but expose model-callable capabilities, not user-typed shortcuts.plugin-and-marketplace-systems.md— How slash commands ship as part of plugins.settings-and-configuration-files.md— Where slash commands live on disk.
Further Reading
- Anthropic, Claude Code: Slash Commands — Reference documentation.