go-documentation — Claude Code skill for Go doc comments
Writes and reviews doc comments for exported Go packages, types and functions. Also fires on its own when you add a new exported API.
npx skills add cxuu/golang-skills --skill go-documentation -a claude-codeWhat go-documentation does
The skill keeps Go documentation consistent: a comment opens with the name of the object, reads as a full sentence, and each package gets exactly one package comment. A script, scripts/check-docs.sh, walks exported functions, types, methods, constants and packages and reports what has no doc comment. The analysis itself lives in scripts/check-docs-ast.go, which you patch when the checking behaviour needs to change.
assets/doc-template.go gives you a starting point for a documented package or exported API. Separate references cover parameters, context behaviour, concurrency safety, cleanup, errors and named results, plus runnable examples and Godoc formatting. A table decides what deserves a comment: standard ctx.Err() cancellation and read-only thread safety are implied, so skip them, while resource release always gets documented.
Comments for unexported symbols are out of scope here — that is go-style-core. After edits the skill suggests running bash scripts/check-docs.sh and fixing the gaps before moving on. Line length sits around 80 columns, and that is advice rather than a hard limit.
What it helps with
- find exported functions and types with no doc comment
- make comments start with the object name
- document cleanup and error types in an API
- add runnable examples in
*_test.gofor Godoc - write a package comment or move a long one into
doc.go
Example prompts for the agent
- check the doc comments in this package and fill in the missing ones
- document the new exported
Clienttype following Go conventions - add a runnable example for
Config.WriteToin the test file
How to install go-documentation
1Skills CLI (Vercel)
npx skills add cxuu/golang-skills --skill go-documentation -a claude-code2Manually: put the files in place
~/.claude/skills/go-documentation/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/go-documentation/
1Skills CLI (Vercel)
npx skills add cxuu/golang-skills --skill go-documentation -a codex2Manually: put the files in place
.agents/skills/go-documentation/SKILL.mdFor all projects use ~/.agents/skills/
1Skills CLI (Vercel)
npx skills add cxuu/golang-skills --skill go-documentation -a cursor2Manually: put the files in place
.cursor/skills/go-documentation/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install cxuu/golang-skills go-documentation2Manually: put the files in place
.github/skills/go-documentation/SKILL.md1Skills CLI (Vercel)
npx skills add cxuu/golang-skills --skill go-documentation -a gemini-cli2Platform CLI
gemini skills install https://github.com/cxuu/golang-skills --path skills/go-documentationManually: put the files in place
.devin/skills/go-documentation/SKILL.mdThe legacy .windsurf/skills/ path still works
Skills CLI (Vercel)
npx skills add cxuu/golang-skills --skill go-documentation -a opencodeClaude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
Step by step, with commands for each platform: How to install skills in Claude Code: five ways
Questions about go-documentation
How do I install go-documentation in Claude?
Run npx skills add cxuu/golang-skills --skill go-documentation -a claude-code. The skill lands in ~/.claude/skills/go-documentation/SKILL.md.
What does go-documentation do?
It writes and reviews doc comments for exported Go packages, types, functions and methods. It runs scripts/check-docs.sh to surface symbols that lack documentation.
Does it cover unexported symbols?
No. Comments for unexported symbols belong to go-style-core. Unexported functions with non-obvious behaviour are still worth documenting.
Source text
SKILL.md · Apache-2.0
---
name: go-documentation
description: Use when writing or reviewing documentation for Go packages, types, functions, or methods. Also use proactively when creating new exported types, functions, or packages, even if the user doesn't explicitly ask about documentation. Does not cover code comments for non-exported symbols (see go-style-core).
allowed-tools: Bash(bash:*)
---
# Go Documentation
## Resource Routing
- `scripts/check-docs.sh` - Run when checking exported functions, types, methods, constants, and packages for missing doc comments.
- `scripts/check-docs-ast.go` - Implementation helper invoked by `check-docs.sh`; patch this when changing documentation analysis behavior.
- `assets/doc-template.go` - Use when starting a documented package or exported API.
- `references/CONVENTIONS.md` - Read when documenting parameters, context behavior, concurrency safety, cleanup, errors, or named results.
- `references/EXAMPLES.md` - Read when adding runnable examples or package examples.
- `references/FORMATTING.md` - Read when formatting Godoc lists, paragraphs, links, and code blocks.
---
## Doc Comments
> **Normative**: All top-level exported names must have doc comments.
### Basic Rules
1. Begin with the name of the object being described
2. An article ("a", "an", "the") may precede the name
3. Use full sentences (capitalized, punctuated)
```go
// A Request represents a request to run a command.
type Request struct { ...
// Encode writes the JSON encoding of req to w.
func Encode(w io.Writer, req *Request) { ...
```
Unexported types/functions with unobvious behavior should also have doc comments.
> **Validation**: After adding doc comments, run `bash scripts/check-docs.sh` to verify no exported symbols are missing documentation. Fix any gaps before proceeding.
---
## Comment Sentences
> **Normative**: Documentation comments must be complete sentences.
- Capitalize the first word, end with punctuation
- Exception: may begin with uncapitalized identifier if clear
- End-of-line comments for struct fields can be phrases
---
## Comment Line Length
> **Advisory**: Aim for ~80 columns, but no hard limit.
Break based on punctuation. Don't split long URLs.
---
## Struct Documentation
Group fields with section comments. Mark optional fields with defaults:
```go
type Options struct {
// General setup:
Name string
Group *FooGroup
// Customization:
LargeGroupThreshold int // optional; default: 10
}
```
---
## Package Comments
> **Normative**: Every package must have exactly one package comment.
```go
// Package math provides basic constants and mathematical functions.
package math
```
- For `main` packages, use the binary name: `// The seed_generator command ...`
- For long package comments, use a `doc.go` file
---
## What to Document
> **Advisory**: Document non-obvious behavior, not obvious behavior.
| Topic | Document when... | Skip when... |
|-------|-----------------|--------------|
| Parameters | Non-obvious behavior, edge cases | Restates the type signature |
| Contexts | Behavior differs from standard cancellation | Standard `ctx.Err()` return |
| Concurrency | Ambiguous thread safety (e.g., read that mutates) | Read-only is safe, mutation is unsafe |
| Cleanup | Always document resource release | — |
| Errors | Sentinel values, error types (use `*PathError`) | — |
| Named results | Multiple params of same type, action-oriented names | Type alone is clear enough |
Key principles:
- Context cancellation returning `ctx.Err()` is implied — don't restate it
- Read-only ops are assumed thread-safe; mutations assumed unsafe — don't restate
- Always document cleanup requirements (e.g., `Call Stop to release resources`)
- Use pointer in error type docs (`*PathError`) for correct `errors.Is`/`errors.As`
- Don't name results just to enable naked returns — clarity > brevity
---
## Runnable Examples
> **Advisory**: Provide runnable examples in test files (`*_test.go`).
```go
func ExampleConfig_WriteTo() {
cfg := &Config{Name: "example"}
cfg.WriteTo(os.Stdout)
// Output:
// {"name": "example"}
}
```
Examples appear in Godoc attached to the documented element.
---
## Quick Reference
| Topic | Key Rule |
|-------|----------|
| Doc comments | Start with name, use full sentences |
| Line length | ~80 chars, prioritize readability |
| Package comments | One per package, above `package` clause |
| Parameters | Document non-obvious behavior only |
| Contexts | Document exceptions to implied behavior |
| Concurrency | Document ambiguous thread safety |
| Cleanup | Always document resource release |
| Errors | Document sentinels and types (note pointer) |
| Examples | Use runnable examples in test files |
| Formatting | Blank lines for paragraphs, indent for code |
---
## Related Skills
- **Naming conventions**: See [go-naming](../go-naming/SKILL.md) when choosing names for the identifiers your doc comments describe
- **Testing examples**: See [go-testing](../go-testing/SKILL.md) when writing runnable `Example` test functions that appear in godoc
- **Linting enforcement**: See [go-linting](../go-linting/SKILL.md) when using revive or other linters to enforce doc comment presence
- **Style principles**: See [go-style-core](../go-style-core/SKILL.md) when balancing documentation verbosity against clarity and concision
© cxuu · Apache-2.0 · cxuu/golang-skills