Slash commands and custom commands

10 min read text
Course contents (20 lessons)
  1. Meet Claude Code
  2. What Claude Code is and how it differs from a chat window
  3. Installing Claude Code and signing in
  4. Your first session: explore, ask, change
  5. Asking well and staying in control
  6. Asking for changes: context, goal, constraints and acceptance criteria
  7. Reading and approving edits
  8. Permission modes: how much freedom to give
  9. Project memory and slash commands
  10. CLAUDE.md: teaching the tool about your project
  11. Slash commands and custom commands
  12. Everyday coding workflows
  13. The plan-first workflow
  14. Understanding unfamiliar code
  15. Debugging with Claude Code
  16. Refactoring safely
  17. Writing tests with Claude Code
  18. Git, small changes, cost and security
  19. Git workflows: branches, commits and pull request descriptions
  20. Keeping changes small and reviewable
  21. Context and cost awareness
  22. Security habits: secrets, commands and untrusted input
  23. Extending the tool, teamwork and a final project
  24. Hooks and MCP servers explained
  25. Team practices for AI-assisted coding
  26. Final project: building a small app step by step

What slash commands are

Inside a session, anything you type that starts with a slash is a command to the tool itself, not a message to the model. They control the session: show help, clear context, change settings. The set of commands grows with new versions, so the reliable way to see what you have is to type /help.

The few you will use first

CommandWhat it is for
/helpShows the commands and basic help for your version.
/initLooks at the project and creates a first CLAUDE.md.
/clearClears the conversation so the next task starts with fresh context.
/compactCondenses a long conversation into a summary, to free up space while keeping the thread.

There are more, for things like managing permissions, memory, MCP servers, hooks and choosing a model. I will not list them since the list changes. Use /help and the official documentation.

/clear between tasks

This is the habit I would teach first. When you finish one task, clear before starting the next. Old messages about the invoice bug do not help with the login feature, and they take up space and can confuse the tool. Commit your work, run /clear, and start fresh.

/compact in the middle of a task

If a task is long and you do not want to lose the thread, /compact summarises the conversation so far. You can usually add a note on what to keep. If you do, describe the important facts in plain words.

/compact Keep: the decision to use cursor pagination, the list of files already changed, and the failing test in OrdersApiTests.

Check the summary. If it dropped something important, restate it.

Custom commands

If you type the same long prompt often, save it as a custom command. The mechanism is simple: you put a markdown file in a commands folder inside the .claude folder of your project. The file name becomes the command name, and the text of the file becomes the prompt. A project folder is shared with your team if you commit it. A personal commands folder in your user configuration is for yourself. Check the official docs for exact locations in your version, since features here have been extended over time.

A command can also take arguments. In the file, a placeholder named $ARGUMENTS is replaced by whatever you type after the command name.

Review the changes on this branch compared with main.

Focus area: $ARGUMENTS

Check for: bugs, missing tests, error handling, security problems (input validation, secrets, injection) and style that does not match the project conventions.
Report findings as a list ordered by severity. For each: file, line, what is wrong, suggested fix. Do not edit any files.

If you save this as review.md in the commands folder, then typing /review the payment code would run it with that focus.

Why it works

The command bundles a good prompt: the scope, the checks, the report format and the "do not edit" rule. Everyone who uses it gets the same thorough review without remembering the details. You improve it once, and the whole team benefits.

Good ideas for custom commands

  • A code review prompt, as above.
  • A "write a pull request description" prompt that follows your team template.
  • A "write tests for this file" prompt that names your test framework and style.
  • A "explain this module for a new teammate" prompt.

Skills and other extensions

The tool has more ways to package reusable behaviour, including features sometimes called skills and plugins. They are newer and change faster. Read the current documentation if custom commands are not enough.

Do not over-engineer

Start with zero custom commands. After a week, look at your session history and find the prompts you typed three times. Those are the ones worth saving. A folder of fifty commands nobody remembers is just clutter.

The common mistake

The common mistake is never clearing context. A session that runs all day on five different tasks gets slower, costs more and gives worse answers. Clear between tasks.

Try it yourself

Create one custom command for a prompt you use often. Test it on a small change. Improve the text twice based on what it missed. Then run /clear and test that the command still works in a fresh session.

This course is free to read. Create a free account to enrol, save your progress and pick up where you left off.

Sign up free I already have an account