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.

/all-comments - Global Comment Cleanup

The /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/commands/all-comments.md
---
description: Remove obvious and redundant comments from all files
---

๐Ÿงน Remove obvious and redundant comments from all files in the codebase.

## Comments to Remove

- Commented out code
- Comments that describe edits like "added", "removed", or "changed" something
- Obvious explanations
- Comments that are obvious because they're close to method names

## Comments to Keep

- TODO comments
- Comments preventing empty blocks
- Empty catch blocks, empty else blocks
- `// deliberately empty`
- Linter/formatter directives
- `// prettier-ignore`
- `// eslint-disable-next-line`
- `// @ts-ignore`

## Comment Position

Move end-of-line comments above the code they describe.

View on GitHub

/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
---
description: Remove obvious and redundant comments from uncommitted changes
---

๐Ÿงน Remove obvious and redundant comments from uncommitted code changes.

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

## Comments to Remove

- Commented out code
- Comments that describe edits like "added", "removed", or "changed" something
- Obvious explanations
- Comments that are obvious because they're close to method names

## Comments to Keep

- TODO comments
- Comments preventing empty blocks
- Empty catch blocks, empty else blocks
- `// deliberately empty`
- Linter/formatter directives
- `// prettier-ignore`
- `// eslint-disable-next-line`
- `// @ts-ignore`

## Comment Position

Move end-of-line comments above the code they describe.

View on GitHub

This is my preferred command because it integrates with my workflow and is perfect for cleaning up after /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
---
argument-hint: file or content to enhance
description: Add appropriate emoji to make content more engaging
---

๐Ÿ˜Š 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 /emoji command follows consistent patterns and avoids duplicates by using a two-pass approach to ensure variety and appropriateness.

Conflicts

This command systematically resolves merge conflicts during git rebases.

.claude-prompts/commands/conflicts.md
---
description: Fix all merge conflicts and continue the git rebase
---

๐Ÿ”€ Fix all merge conflicts and continue the git rebase.

ALWAYS use the `code:cli` skill.

- 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:
- Stage the resolved files with `git add`
- Continue the rebase with `git rebase --continue`
- If the rebase continues with more conflicts, run the conflict-resolver subagent (again)
- โœ”๏ธ Verify successful completion by checking git status and recent commit history

View on GitHub

Conflict Resolution Strategy

The /conflicts 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.

For more custom command examples and their implementations, check out the claude-code-prompts repository.