Claude Code: Custom Slash Commands
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.
- 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.
/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.
๐งน 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
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!
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.)
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.
๐ 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
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.
๐ 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
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.