Slash Commands for AI Coding Tools: A Practical Guide
This guide explains how to use slash commands effectively when working with AI coding tools. It covers why deterministic command entry improves efficiency, the three sources of commands (built-in, preset skills and workflows, and custom), the essential built-in capabilities for context management, model switching, change review, and commit generation, and how to design and share custom commands. It also lists common mistakes and a step-by-step path to adoption.
1. Why Slash Commands Are Worth Mastering
When collaborating with AI coding tools, the efficiency gap often comes not from model capability but from how you interact. The inefficient approach is to explain the same thing in natural language every time: clear the context, switch reasoning modes, review the current changes, compress a long session, generate a commit message. The efficient approach is to consolidate these deterministic operations into fixed entry points that trigger with a single action.
A slash command is essentially a deterministic operation entry point: type / at the beginning of the input box, and the tool lists the available functions. It solves the problem of “clear intent but verbose expression,” turning vague descriptions into precise instructions.
Two rules to remember first:
- Commands are recognized only at the beginning of a message; appearing in the middle of a sentence will not trigger them.
- Text after the command name is passed as arguments; for example, in
/model sonnet,sonnetis the argument.
2. Three Sources: Know the Difference Before Using Them
The entries in the menu are not all the same kind of thing. By source, they fall into three categories.
1. Built-in commands: Behavior implemented by the program itself, part of the tool’s runtime capabilities, such as clearing context, compressing a session, switching models, and viewing status. Their results are deterministic and do not depend on model understanding.
2. Preset skills and workflows: A set of instruction-based capabilities provided officially, such as code review and running a project. They are essentially standard instructions handed to the model for execution, so they can be invoked manually and may also be triggered automatically in appropriate scenarios.
3. Custom commands: Defined by the user, turning high-frequency instructions or workflows into /your-command-name, and shareable with the team through the project directory.
The point of this classification: built-in commands control the session and runtime, preset skills handle standard actions, and custom commands capture team conventions.
3. Built-in Capabilities You Must Master
- Context management: Long sessions accumulate irrelevant information. Clearing or compressing in time reduces interference and cost, and keeps answers more focused.
- Mode and model switching: Different tasks demand different reasoning depth and response speed. Switching by task is more economical than using one configuration throughout.
- Change review: Reviewing the files and diffs changed in the current round is a basic step before committing, avoiding mixing unrelated changes into a commit.
- Commit message generation: Having the tool produce a commit message based on the actual diff, then reviewing it manually, is more complete and consistent in style than writing it by hand.
- Help and command discovery: When you forget a command name, type
/to browse the list, which is more reliable than memory.
Practice tip: fix “session start — execute — review — commit” into a single command chain until it becomes muscle memory.
4. Custom Commands: Turn Repetitive Work into Assets
Custom commands usually live in the project’s agreed command directory, carried as Markdown files. The file name is the command name, the body is the instruction content, and frontmatter description and argument placeholders are supported.
Example (illustrative):
---description: Generate a commit message following team conventionsargument-hint: [change scope]---Generate a commit message based on the current diff, with these requirements:1. The first line must not exceed 50 characters and must use the imperative mood;2. The body explains the motivation, key changes, and impact;3. The change scope is limited to $1.
Invocation: /commit auth-module
Design points:
- Single responsibility: one command does one thing; avoid turning it into a catch-all script.
- Parameterization: make the volatile parts placeholders and keep the command name stable.
- State constraints clearly: specify the output format, prohibitions, and acceptance criteria to reduce back-and-forth confirmation.
- Layered organization: put project-level commands in the project directory and personal habits in the user-level directory to avoid polluting team configuration.
- Team sharing: version command files with the repository and review them alongside code, so conventions are truly unified.
5. Common Mistakes and Improvements
- Treating commands as chat: commands emphasize determinism; keep instructions short and constraints hard.
- Too many, too granular commands: keep natural language for low-frequency operations and only wrap high-frequency actions.
- Ignoring context: without clearing or compressing, long sessions degrade output quality.
- Missing acceptance criteria: without stating “what counts as done,” results require repeated rework.
- No version control: command files not committed to the repository cannot be reused or traced by the team.
6. Getting Started
Step one, count the three things you repeat most in a week; step two, replace descriptions with built-in commands first; step three, write a custom command for one of them and parameterize it; step four, commit it to the repository and promote it within the team; step five, review periodically, delete low-frequency commands, and merge overlapping ones.
The key to mastering slash commands is not memorizing how many there are, but building the habit of judging “use commands for deterministic operations, natural language for exploratory questions.” When high-frequency workflows are solidified into shareable command assets, human-AI collaboration truly moves from repeated communication to stable output.
