Loading...
Loading...
Adds and enhances comments and documentation comments in code. Use with requests like 'add comments', 'write comments', 'enhance comments', 'add JSDoc', 'add docstring', 'add documentation comments'. Preserve role boundaries from the package/service perspective, prerequisites and contracts between callers and callees, and context from other files/services in a 'readable on the spot' format. Do not modify the code itself (for implementation changes, use implement-issue). Refer to code-comment-style for detailed rules, create-commit for commit creation, and update-docs for CLAUDE.md synchronization.
npx skill4agent add fandhe-ai/agent-cli-skills comment-codecomment-code <target file or directory> [--lang <language>]git diff HEAD--langgit diff HEAD# Without arguments: List recent diff files (compare both staged/unstaged with HEAD)
git diff HEAD --name-only
# To include untracked (new uncommitted) files
git ls-files --others --exclude-standard# Search for callers by symbol name (e.g., exported function name)
grep -rn "target symbol name" --include="*.ts" --include="*.js" .# List import statements
grep -n "^import\|^from\|require(" target-filepackage.jsongo.modCargo.toml.claude/rules/code-comment-style.md| Aspect | Content to write |
|---|---|
| Role/responsibility boundaries | "This module handles the boundary of ~ service", "Functions as the public interface of ~ package" |
| Caller context | Which layers/services call it. The state/permissions assumed by the caller |
| Contract with callee | What is guaranteed to be returned. Conditions and meanings of errors/exceptions (whether to return null or throw an exception, etc.) |
| Dependencies with other files/services | External dependencies, configurations, shared states that cannot be found without cross-referencing files |
| Non-obvious constraints/background/why | Why the implementation is structured this way. Background, context, and specification limitations |
/** ... */"""..."""/////!// FuncName .../** ... *//**
* Receives a user ID and returns user information.
* @param userId User ID
* @returns User information
*/
function getUser(userId: string): User | null { ... }/**
* Public interface of the authentication layer. Called from API handlers,
* assuming only calls with validated sessions (unauthenticated requests are blocked by upstream middleware).
*
* Delegates to UserRepository and returns values retrieved from the DB.
* Returns null if the user does not exist (does not throw exceptions)——
* Callers must perform null checks.
*
* Note: Soft-deleted users are also treated as null (specification: issue #142).
*/
function getUser(userId: string): User | null { ... }## comment-code Completion Report
### Target Files
- `path/to/file.ts` (Added: N, Enhanced: M)
### Perspectives of Added Comments
- Caller: [Location where caller information is specified]
- Contract with callee: [Location where return value/error conditions are specified]
- Non-obvious constraints/background: [Location where "why" is described]
### Security Check
- Result: ✅ No issues / ⚠️ Warnings (details)
### Next Actions
- To commit: Use the create-commit skill
- To update CLAUDE.md: Use the update-docs skillcreate-commitgit diff HEAD| Issue | Mitigation |
|---|---|
| Writing verbose content that is obvious from the signature/type (paraphrasing "what") | Only write non-obvious information such as "why the implementation is this way" or "caller prerequisites" |
| Writing comments based on speculation without investigating callers | Always confirm callers using grep in Step 2 before writing |
| Including secrets/PII in comments | Confirm no secrets/PII exist during the Step 4 security check |
| Modifying code logic while "organizing" | Leave a TODO comment where implementation changes are needed and redirect to |
implement-issue.claude/rules/code-comment-style.md--no-verify