Slash Commands for AI Coding Assistants: Built-in Commands and Custom Workflows

    This practical guide explains how slash commands work in AI coding assistants, which built-in commands are most useful for context, session, and model management, and how to turn recurring personal or team workflows into reusable custom commands. It also covers argument handling, subdirectory organization, team sharing, and practical adoption tips.

    When collaborating with an AI coding assistant in the command line, many people still rely on full sentences for common actions: typing a paragraph to clear context, or writing another long description to ask the assistant to summarize changes from the current round. In practice, most of these high-frequency operations have corresponding slash commands that can be invoked directly by typing /. Over time, the productivity gap between developers who use commands and those who do not can be substantial.

    This article focuses on three questions: What exactly are slash commands? Which built-in commands should you master? And how can you package your high-frequency personal workflows into reusable custom commands?

    1. How Slash Commands Work

    Slash commands are shortcuts triggered by / at the beginning of the input box. Understanding them requires only two rules:

    1. Position rule: Commands are recognized only at the start of a message. If you type / in the middle of an ordinary conversation, it is treated as plain text and does not trigger any function.
    2. Argument rule: Content after the command name is passed as arguments. For example, when switching models, you might enter something like /model sonnet, where sonnet is the argument passed to the command, and the command performs the corresponding action based on that argument.

    There is also a commonly overlooked point: the command menu that appears after typing / does not contain a single category of items. It contains commands from three different sources. Distinguishing these three categories will keep later usage and extension work from becoming confusing.

    First category: built-in commands. These are provided by the tool itself. Their behavior is fixed in the program and does not depend on any model inference, so execution results are deterministic. Typical examples include clearing context, compressing a conversation, switching models, and viewing status—system-level operations.

    Second category: bundled skills and workflows. These are a set of officially preset “skill-shaped” commands, such as code review and task execution. They are essentially structured instruction templates handed to the AI for execution, so they have two characteristics: they can be invoked manually by the user, and they can also be triggered automatically by the AI when it judges the scenario to be appropriate. The value of these commands is that they productize “best-practice prompts.” You do not need to hand-write “Please perform a code review and focus on these issues…” every time; one command gives you a standardized execution flow.

    Third category: custom commands. These are commands defined by users or teams, usually stored as files in a project’s configuration directory or a global configuration directory. This is one of the main topics of this article and will be covered separately below.

    2. Essential Built-in Commands

    There are quite a few built-in commands, but the ones used frequently in daily work cluster around a few scenarios: context management, session control, and model/configuration switching.

    1. Context clearing. Long conversations generate a large amount of historical information, which occupies the context window and may dilute the model’s attention with irrelevant content. The clear-context command resets the conversation history while keeping the current session, making it suitable for the transition point when “the previous task is complete and a new task begins.” Developing the habit of clearing proactively at task boundaries is a basic practice for controlling cost and maintaining answer quality.

    2. Conversation compression. When a task is not finished but the conversation is already long, clearing directly would lose important context. The compression command summarizes the lengthy history into a summary and rebuilds the conversation, freeing window space while preserving key task information. The trade-off between clearing and compression is simple: use clearing for task switches and compression for task continuation.

    3. Model and configuration. Parameterized commands can directly switch the currently used model, for example between complex reasoning tasks and lightweight, fast tasks. There are also query commands for viewing the current configuration, account status, and version information, which are often useful when troubleshooting environment issues.

    4. Change review. Ask the AI to show which files were modified and what changes were made in the current session. A quick check before committing code is more efficient than manually scanning the diff.

    5. Session and history. Commands for restoring historical sessions and exporting the current conversation are suitable for continuing tasks across days or preserving communication records.

    A recommended approach: open the command menu and read through the descriptions of all built-in commands, pick out the ones you expect to use every week in your own scenarios and practice them deliberately, and look up the rest as needed.

    3. Custom Commands: Freeze Workflows into One Input

    Built-in commands solve general problems, but every developer’s workflow has repetitive, personalized parts. For example, before every commit you may want the AI to “generate a commit message according to team conventions,” or before starting a new feature you may want it to “read certain directories first and then make a plan.” These fixed processes are good candidates for custom commands.

    1. Basic form. A custom command is usually a Markdown file. The filename is the command name, and the file content is the instruction template passed to the AI. Commands placed in the project configuration directory are available only in that project, while commands placed in the global configuration directory are available in all projects. This layered design naturally maps to the boundary between “project conventions” and “personal habits.”

    An example custom command for generating commit messages:

    1. # .config/ai-cli/commands/commit-msg.md
    2. Generate a commit message that follows the conventions based on the changes in the current staging area:
    3. - Format: type(scope): short description
    4. - Write the description in Chinese and keep it under 50 characters
    5. - If the changes span multiple modules, split them into multiple messages and list them

    After that, type /commit-msg in the input box to trigger the entire flow.

    2. Arguments and dynamic content. An advanced approach is to introduce placeholders into the template so the command supports arguments, for example /fix module-name, and to dynamically inject the current context at execution time, such as the current directory or the list of staged files. This upgrades the command from a “fixed prompt” to a “parameterized mini-workflow.”

    3. Subdirectory organization. As the number of commands grows, you can group them by directory and reference them in the form “directory-name: command-name” when invoking them, preventing the command menu from becoming a mess.

    4. Team sharing. Putting the project-level command directory under version control is a key step for team adoption. After new members clone the repository, they can use all the commands accumulated by the team. This effectively turns the experience of “how this project should get AI to work” into executable assets. Combined with code review processes, the commands themselves can be reviewed and evolved like code.

    4. Practical Recommendations

    • Classify before use: When you encounter a command, first determine whether it is a deterministic system operation or a prompt template. The former can be used with confidence; for the latter, you need to understand its instruction content to predict the outcome.
    • Control custom command granularity: One command should do one thing. Complex flows should be split into multiple commands and combined. This is far more maintainable than a single giant command.
    • Clean up regularly: Delete commands you no longer use in a timely manner. The cleanliness of the command menu directly affects invocation efficiency.
    • Treat commands as a team knowledge base: Every team-level command is an opportunity to write down a best practice.

    The essence of slash commands is to compress “repeated natural language descriptions” into “deterministic entry points.” Built-in commands help you manage sessions and context, bundled skills let you borrow standardized prompts, and custom commands let your personal and team workflows truly accumulate. Starting today, write the sentence you repeat most often as your first command—that is the starting point for efficiency gains.