This is a Cursor slash command.
You're going to learn how to use Slash commands to automate tasks, chain them, and pass inputs.
You might be thinking: "I don't need this. I'll just use Cursor rules." But this article will also show you exactly how Slash commands are different from Cursor rules.
BTW, I'm Jan, CTO of ReactSquad. Our teams use Cursor every day. And I'm also trained in AIDD by Eric Elliott the author of "The Art of Effortless Programming".
You're going to learn some secret techniques to get the most out of Slash commands.
For example, here is how you can write that Slash command for auto-generating a changelog for your repository.
# log
Act as a senior software engineer to log changes to the repository using this template:
## $date
- $emoji - $change1
- $emoji - $change2
# Emojis
Use the following emoji to represent the change:
- 🚀 new feature
- 🐛 bug fix
- 📝 documentation
- 🔄 refactor
- 📦 dependency update
- 🎨 design
- 📱 UI/UX
- 📊 analytics
- 🔒 security
Constraints {
Always use reverse chronological order.
Add most recent changes to the top.
Never log about logging. Avoid logging meta-work; log salient, user-visible changes.
For each change, follow conventional commit messages, including a body. Example:
feat(scope): short title
Body explaining what changed and why.
}
gitChanges() {
git add .
git --no-pager diff --cached
}
planChanges() {
// Check the plan diff to detect recently completed plan tasks.
}
detectChanges() {
gitChanges |> planChanges |> logDetectedChanges
}
This command is written in SudoLang.
SudoLang is a programming language specifically designed to collaborate with AI language models.
Using SudoLang saves tokens and improves how accurately LLMs follow your instructions.
And remember, keep your Slash commands short to manage your context efficiently. Aim for fewer than 150 lines of code.
There is really a lot more to writing good prompts, so if you want a SudoLang crash course article, send me a DM on X.
You can also chain Slash commands together.
Let's create another Slash command for committing your changes to the repository.
# commit
Act as a senior software engineer to commit changes to the repository in this format:
"$type${[(scope)]}{[!]}: $description"
# Notes:
# - Square brackets [] indicate optional parts.
# - "!" marks a breaking change.
Types: fix | feat | chore | docs | refactor | test | perf | build | ci | style | revert | other
If we haven't logged the latest changes yet, use @log.md to log changes before committing.
Constraints {
When committing, don't log about logging in the commit message.
Use multiple -m flags, one for each log entry.
Limit the first commit message line to 50 characters.
Use conventional commits with a scope, title, and body.
}
If you now run this /commit
command in the same window where you ran the /log command, it will commit your changes to the repository for you with a beautiful commit message.
You might be asking yourself:
"Is there any difference in invoking a slash command vs @'ing the file?"
The slash command is a user-defined prompt, which could include references to different files or folders.
Slash commands are also different from Cursor rules.
The agent appends Cursor rules automatically. But Slash commands are your prompt, so they carry more weight and the LLM will follow them more closely.
You can also pass things to your Slash commands.
For example, if you have a slash command for writing tests, you can pass it the file containing the function implementation