Slash Commands Deep Dive
Master every Claude Code slash command — from /review to /commit — with real-world usage examples and pro tips.
Master every Claude Code slash command — from /review to /commit — with real-world usage examples and pro tips.
Slash commands are typed directly at the > prompt. They trigger predefined workflows with Claude's full context of your current file and working directory.
| Command | What it does |
|---|---|
| /review | Audit the current file for bugs, style, and security issues |
| /fix | Apply Claude's suggested fix to the highlighted problem |
| /explain | Explain a selected piece of code in plain language |
| /commit | Generate a conventional commit message from git diff |
| /test | Generate unit tests for the current file or function |
| /bug | Paste an error and get a targeted fix |
| /clear | Reset the conversation context |
| /exit | Quit the REPL |
/review — Code ReviewOpen a file by telling Claude which one to read:
> open src/auth/login.ts
> /review
Claude will respond with a numbered list of issues grouped by severity:
[HIGH] Line 23: Password compared without constant-time function — timing attack risk
[MEDIUM] Line 41: Missing input validation on email field
[LOW] Line 67: Unused import 'crypto' at top of file
Each item includes the line number, a short description, and a suggested fix. You can then run /fix to apply any of them.
/fix — Auto-Apply FixesAfter /review surfaces issues, apply a specific fix:
> /fix line 23
Claude will show you a diff and ask for confirmation:
--- a/src/auth/login.ts
+++ b/src/auth/login.ts
@@ -21,7 +21,7 @@ async function verifyPassword(input, stored) {
- return input === stored;
+ return crypto.timingSafeEqual(Buffer.from(input), Buffer.from(stored));
}
Apply this change? (y/n)
Type y to write the change to disk.
/fix reads the current file state — if you made manual edits since /review, run /review again first so Claude has the up-to-date context.
/explain — Code ExplanationPaste code or reference a line range:
> /explain lines 15-35
Or paste a snippet inline:
> /explain
const memoize = fn => {
const cache = new Map();
return (...args) => {
const key = JSON.stringify(args);
if (cache.has(key)) return cache.get(key);
const result = fn(...args);
cache.set(key, result);
return result;
};
};
Claude will return a plain-English breakdown — useful for onboarding teammates or understanding unfamiliar codebases.
/commit — Generate Commit MessagesStage your changes first, then let Claude write the message:
git add -p # interactively stage changesThen in the Claude REPL:
> /commit
Claude reads git diff --staged and produces a conventional commit:
feat(auth): replace timing-unsafe password comparison with crypto.timingSafeEqual
Previously the login function used strict equality (===) to compare passwords,
which is vulnerable to timing attacks. This change uses Node's constant-time
comparison function to prevent side-channel leakage.
Closes #142
Copy it into git commit -m "..." or pipe directly:
claude --print /commit | git commit -F -/test — Generate Unit Tests> /test src/utils/format.ts
Claude inspects the module's exports and generates a test file matching your existing test framework (Jest, Vitest, or Mocha — detected automatically):
import { formatCurrency, formatDate } from './format';
describe('formatCurrency', () => {
it('formats positive amounts', () => {
expect(formatCurrency(1234.5, 'USD')).toBe('$1,234.50');
});
it('handles zero', () => {
expect(formatCurrency(0, 'EUR')).toBe('€0.00');
});
});Pro tip: run /fix after /test to let Claude fix any type errors in the generated tests before you run them.
/bug — Debug an ErrorPaste the full error stack trace:
> /bug
TypeError: Cannot read properties of undefined (reading 'map')
at renderList (src/components/List.tsx:12:24)
at renderApp (src/App.tsx:45:10)
Claude identifies the likely cause (rendering before data is loaded) and suggests a guard clause. It will then offer to apply the fix with /fix.
/clear — Reset ContextWhen you switch to a different problem area, clear the conversation so Claude does not carry over stale context:
> /clear
Context cleared. Starting fresh.
The seven core slash commands cover most of a developer's daily workflow. The recommended pattern is: /review → /fix → /test — review changes, auto-fix issues, then generate tests to lock in the correct behaviour. The next module covers how to persist knowledge about your project across sessions with CLAUDE.md.