Speed Up Your Agents with Cursor Slash Commands

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.
Share with a coworker

Transcript

[00:00] We'll first ask cursor to make a list of tools you currently have available and use their exact tool names and hit enter. It will first list its own tools, then follow it up with your currently installed MCPs. So if we focus on one like codebase search, I'll copy that to my clipboard and go up into my rules, scroll down to the bottom, and set up a section called slash commands. Then I can define a slash s and then a placeholder for the term. Then I'll say this equals use the code base search tool to search for term.

[00:31] Then if I start a new conversation I can say slash s and type in handle, hit enter, and it will fire off a code base search for the word handle. And you'll see all of these references that it found along the way. So if we go back to our list of available tools, If I use a tool like edit file I'll go back to our settings, scroll down, I'll give this one a slash L, and I'll say then this equals use the, I'll paste in edit file tool, to update the cursor rules project.mdc with the most important things learned during this conversation. Then you could include language like make this look like a reference sheet or a cheat sheet based on your preference here, But I'll just go to a previous conversation. Let's go to this UI adjustments.

[01:20] I'll say slash L, hit enter, and then it says it wants me to update the cursor rules. And now it's firing off the edit after gathering everything I learned. I'll go ahead and accept this. And now sidebar UI editor focus is available inside of our project.mdc file. We can accept that.

[01:38] Then going back to our available tools I'll grab run terminal command, copy this, scroll down, then add a new line for slash C, and say use the run terminal command tool to create a commit based on this conversation. Use fix, beep, refactor, chore, etc syntax. Then I'll just go back to this conversation for UI adjustments. I'll say slash C, hit enter, and then it realizes it wants a commit. And we get a commit of implement editor focus on new doc, and we did that all in two characters.

[02:15] Now it's debatable whether the slash is the best character to use for this, and it's also highly debatable that you might want to put each of these into a template from a separate tool. I personally use ScriptKit, other people use a wide variety of tools for keyboard expansion, or There are many tools that support snippets and pasting snippets, because if you extract all of these, then they don't have to be included in the context every time you make a request. But for the sake of convenience, it's easy to drop these in your project, share them around your team. The key takeaway is that it's trivial to create these aliases to trigger fairly complex sequences of things, and using the exact name of the tool saves the AI a lot of thinking about what it should do. Instead, you'll notice a lot more speed in how quickly it jumps to making those edits and running the tools.