Agent skill
code-commenter
Add detailed comments explaining WHY code works, its context, edge cases, and performance implications. Use when user mentions "add comments", "document", "explain code", "improve readability", or "maintainability". Supports C++, Python, Java, JavaScript, Go, Rust, SQL.
Install this agent skill to your Project
npx add-skill https://github.com/luohaha/oh-my-skills/tree/main/skills/code-commenter
SKILL.md
Code Commenter
Add high-quality comments that explain WHY code works, not just WHAT it does.
Core Principles
1. Explain WHY, not WHAT
Explain reasoning and business context, not just what the code does.
// Bad: Increment counter
counter++;
// Good: Track failed connection attempts for exponential backoff
counter++;
2. Document Non-Obvious Decisions
Explain performance trade-offs, algorithm choices, constraints.
// Use bloom filter for memory efficiency: 10x memory savings, false positives acceptable
// for duplicate detection. Hash set would be more accurate but needs 10x more RAM.
3. Highlight Edge Cases and Gotchas
// IMPORTANT: Don't call from within a transaction - opens its own tx, causing deadlock
// NOTE: This mutex must be held when accessing sharedCache (race condition otherwise)
4. Document Assumptions
// ASSUMES: Input already sanitized, max 1000 chars
// CONSTRAINT: Parser doesn't handle nested parens beyond depth 3
Comment Types
File/Module Level: Purpose, dependencies, constraints Function/Method: Purpose, parameters, side effects, performance notes Inline: Explain specific lines when non-obvious Section: Break long functions into logical sections TODO/FIXME: Track technical debt
See EXAMPLES.md for detailed examples of each type.
Language-Specific Guidelines
C/C++: Doxygen style, explain memory/thread safety
Python: Docstrings (PEP 257), type hints, examples
Java: JavaDoc, thread safety, exceptions
JavaScript/React: Props, state, performance notes
Go: Exported symbols, concurrency, context
Rust: Doc comments, ownership, lifetimes
SQL: Join logic, performance, business rules
For detailed examples, see LANGUAGE_GUIDE.md.
What NOT to Comment
Don't state the obvious: x = 5; doesn't need a comment saying "set x to 5"
Don't comment bad code - refactor it: Make code self-documenting with good names
Don't maintain outdated comments: Delete rather than keep misleading comments
Output Format
- Preserve original code structure (don't reformat unless requested)
- Add comments naturally where they make logical sense
- Match existing comment style in the codebase
- After commenting, provide brief summary of what was documented
Example:
I've added comments to explain:
- Algorithm complexity and trade-offs
- Edge case handling for empty inputs
- Memory management strategy
- Non-obvious performance optimizations
Best Practices
✅ DO:
- Explain WHY and provide context
- Document assumptions, constraints, edge cases
- Use clear, concise language
- Keep comments close to relevant code
- Update comments when code changes
❌ DON'T:
- State the obvious
- Comment bad code instead of fixing it
- Write novels - be concise
- Leave outdated comments
- Comment out code (use version control)
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
naming-reviewer
Expert code naming review and refactoring. Reviews variables, functions, and classes to improve readability and maintainability using master-level naming principles. Use when: (1) User asks to review naming/variable names in code, (2) User wants to improve code readability, (3) User requests naming suggestions or refactoring, (4) User mentions code quality or maintainability concerns related to naming, (5) User asks to apply best practices to naming
pr-description
Generate comprehensive pull request descriptions that help reviewers understand code changes. Use when the user asks to "generate PR description", "create PR summary", "write PR intro", or needs help documenting their code changes for review. Analyzes git diffs or specified files to create structured descriptions covering why changes were made and what was implemented.
scaffold-exercises
Create exercise directory structures with sections, problems, solutions, and explainers that pass linting. Use when user wants to scaffold exercises, create exercise stubs, or set up a new course section.
handoff
Compact the current conversation into a handoff document for another agent to pick up.
setup-pre-commit
Set up Husky pre-commit hooks with lint-staged (Prettier), type checking, and tests in the current repo. Use when user wants to add pre-commit hooks, set up Husky, configure lint-staged, or add commit-time formatting/typechecking/testing.
obsidian-vault
Search, create, and manage notes in the Obsidian vault with wikilinks and index notes. Use when user wants to find, create, or organize notes in Obsidian.
Didn't find tool you were looking for?