Typing repetitive or complex instructions for Cursor's AI agent can slow down your workflow. This lesson teaches you how to create custom slash commands (e.g., /s term
, /l
, /c
) using Cursor's "Rules" feature. Learn how to map these simple shortcuts to specific AI actions, instructing the agent to use precise tools like codebase_search
, edit_file
, or run_terminal_cmd
based on your command and the current conversation context.
Workflow demonstrated in this lesson:
- List available AI tools (built-in and MCP) to get their exact names.
- Navigate to Cursor Settings -> Rules.
- Define custom rules under a heading (e.g.,
## Slash Commands
). - Create rules mapping a slash command pattern (like
/s <term>
) to a detailed instruction specifying which tool to use and how (e.g., "Use the codebase_search tool to search for"). - Define rules that leverage conversation context (e.g., for summarizing notes or creating commit messages).
- Save the rules (potentially in
.cursor/rules/project.mdc
for team sharing). - Invoke the custom slash commands (e.g.,
/s handle
,/l
,/c
) in the chat/agent window. - Observe the AI understanding the shortcut and executing the intended tool call.
Key benefits:
- Creates efficient, reusable shortcuts for common AI interactions.
- Reduces the need for typing lengthy, detailed prompts repeatedly.
- Allows mapping simple commands to specific Cursor tool invocations.
- Enables commands that leverage the ongoing conversation context.
- Improves workflow speed and consistency when working with the AI agent.