Skip to main content

Claude Code: Custom Slash Commands

ยท 3 min read
Craig P. Motlin
Software Engineer

Utility commands I use with Claude Code for code maintenance and cleanup, particularly for handling the LLM's tendency to over-comment code.

This post is part of my Claude Code setup series.

Commentsโ€‹

LLMs write obvious comments. Despite clear instructions not to in the system prompt and in my global configuration, Claude consistently adds comments like:

// Calculate elapsed time
const elapsedTimeMs = Date.now() - startTime

I've come to accept that comments are crucial to how LLMs "think" and I cannot stop the LLM from writing them, at least in the first draft. Instead, I use these commands to clean them up after the fact.

/user:all-comments - Global Comment Cleanupโ€‹

The /user:all-comments command asks the LLM to clean up redundant comments across the entire codebase. After Claude deletes all the comments, I run git absorb and it's as if the comments never existed in git history.

.claude-prompts/shared/comment-removal-rules.md
- Look for comments that are obvious or redundant and remove them. Examples of comments that can be removed include:
- Commented out code.
- Comments that describe edits like "added", "removed", or "changed" something.
- Explanations that are just obvious because they are close to method names.
- Do not delete all comments:
- Don't remove comments that start with TODO.
- Don't remove comments if doing so would make a scope empty, like an empty catch block or an empty else block.
- Don't remove comments that suppress linters or formatters, like `// prettier-ignore`
- If you find any end-of-line comments, move them above the code they describe. Comments should go on their own lines.

View on GitHub

/user:comments - Local Comment Cleanupโ€‹

The comments prompt is identical to all-comments except it adds the sentence "Look at the local code changes that are not yet committed to git" turning it into a local edit.

.claude-prompts/commands/comments.md
๐Ÿงน Remove obvious and redundant comments from uncommitted code changes.

๐Ÿ“ Only consider and only edit local code changes that are not yet committed to git.

@../shared/comment-removal-rules.md

View on GitHub

This is my preferred command because it integrates with my workflow and is perfect for cleaning up after /user:todo.

While I can't get the LLM to stop writing comments during initial implementation, these commands are extremely effective at cleaning them up after the fact.

Emojiโ€‹

This command adds emoji!

.claude-prompts/commands/emoji.md
Add appropriate emoji to the content we're working on to make it more engaging and easier to scan.

$ARGUMENTS

## ๐Ÿ“ Placement
- Add emoji at the beginning of headers before the text
- Include emoji in lists and navigation elements
- Code comments

## ๐Ÿ”„ Two-pass approach
1. First pass: Add the most fitting emoji for each element
2. Second pass: Replace duplicates with suitable alternatives

# ๐ŸŽฏ Patterns for consistency
- Match emoji to content's tone and purpose (๐ŸŽ‰ celebrations, ๐Ÿ”ง technical, ๐Ÿ“š documentation)
- Use emoji for status indicators (โœ… complete, โณ in progress, โŒ error, โš ๏ธ warning)
- Establish patterns for consistency (๐Ÿ“ for "Notes", ๐Ÿ”— for "Links", etc.)

View on GitHub

Usage Patternsโ€‹

The /user:emoji command follows consistent patterns and avoids duplicates by using a two-pass approach to ensure variety and appropriateness.

Learnโ€‹

When we solve tricky problems, this command helps document the solution for future reference.

.claude-prompts/commands/learn.md
๐Ÿ“š Document tricky problems in CLAUDE.local.md

$ARGUMENTS

- Think about whether we ran into any tricky problems and figured out a solution
- CLI commands that failed that we had to try about 3 times
- Ordering requirements or prerequisites that had to be set up
- But we eventually figured it out and know a solution
- ๐Ÿ“ Add a brief summary of the problem and its solution in CLAUDE.local.md

View on GitHub

Knowledge Persistenceโ€‹

The /user:learn command documents solutions in CLAUDE.local.md so the knowledge persists for future sessions, especially useful for CLI commands that required multiple attempts or specific ordering requirements.

Rebaseโ€‹

This command systematically resolves merge conflicts during git rebases.

.claude-prompts/commands/rebase.md
๐Ÿ”€ Fix all merge conflicts and continue the git rebase.

- Check `git status` to understand the state of the rebase and identify conflicted files
- For each conflicted file:
- Read the file to understand the conflict markers (`<<<<<<<`, `=======`, `>>>>>>>`)
- Analyze what changes are in HEAD vs the incoming commit
- Resolve conflicts by choosing the appropriate version or combining changes
- Remove all conflict markers after resolution
- โœ… After resolving all conflicts:
- If project memory includes a precommit check then run it and ensure no failures
- Stage the resolved files with `git add`
- Continue the rebase with `git rebase --continue`
- If the rebase continues with more conflicts, repeat the process
- โœ”๏ธ Verify successful completion by checking git status and recent commit history

View on GitHub

Conflict Resolution Strategyโ€‹

The /user:rebase command follows a structured approach to understand and fix each conflict, ensuring the rebase completes successfully without missing any issues.

Next Stepsโ€‹

These utility commands complement the main development workflow and work best with proper Claude Code configuration.