/golang:golangfrom golang
Writes and reviews Go code covering idioms, error handling, concurrency, testing, project structure, and the toolchain. Activates when touching Go code or diagnosing goroutine leaks, race conditions, or test flakes.
Ships in golang. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Simplicity is the highest Go virtue. Three biases decide most calls:
go directive decides what may be written, not the installed toolchain.The go directive in go.mod sets the language version a module may use. Read it before writing code and never reach
for a feature above it. The stdversion analyzer reports a standard-library symbol newer than the directive: Go 1.27
and later fail go test on it, earlier toolchains report it under go vet.
Floor version per feature. Anything older than 1.21 is available in every supported module.
min, max, clear builtins; slices, maps, cmp, log/slog; context.WithoutCancel;
errors.ErrUnsupported; sync.OnceValuefor range int; math/rand/v2; method and wildcard patterns in
net/http.ServeMuxiter; iterator functions in slices and maps; unique; unbuffered timer
channelsos.Root; testing.B.Loop; t.Context; runtime.AddCleanup; omitzero struct
tag; tool directives; iterator functions in stringstesting/synctest; sync.WaitGroup.Go; container-aware GOMAXPROCSnew(expr); self-referential type constraints; errors.AsType; go fix modernizersencoding/json/v2; uuid; strings.CutLastRead [${CLAUDE_SKILL_DIR}/references/versions/go1.NN.md] — one file per version, go1.21.md through go1.27.md —
when writing against a feature near the module's floor, and whenever raising the directive. Each carries what its
version added, which behavior changes the go directive gates, and the traps it introduced.
util, common, misc, shared, helpers, or types as a package name. Name a package for what it
provides; one that resists naming is holding unrelated things.widget.New(), never widget.NewWidget().user-service.go, http-handler.go.var _ http.Handler = (*Handler)(nil).cmp.Ordered when it compares, any when it only moves values. A constraint
listing methods the function never calls is noise.any plus a type switch when callers know the type. It moves the failure to compile
time and removes the assertion.any. Drop the parameter.context.Context in a struct or an option struct. Pass it as the first parameter.context.Background() only in main() and test setup.context.WithoutCancel(r.Context()).var s []string, tested with len(s) == 0. Use []string{} only where the
JSON encoding must be [] rather than null. Pre-allocate when the size is known: make([]T, 0, n).&T{} for a pointer to a struct, new(expr) for a pointer to any other value — new(expr) replaces the
hand-rolled ptr(v) helper.iota at 1 unless the zero value carries meaning: const ( StatusActive Status = iota + 1; ... ).fmt.Errorf("get user: %w", err). Lowercase, no
trailing punctuation, no "failed to" prefix, %w last so the chain reads newest to oldest.%v instead of %w when the wrapped error is an implementation detail — %w commits your API to the
dependency that produced it.errors.Is and errors.As, never == or a bare type assertion. errors.AsType[T] is the generic
form and needs no pre-declared target.==.errors.Join only where every operation must be attempted — closing a set of resources, validating every field.
Never as a substitute for returning at the first failure on a sequential path._ = f.Close() where the drop is deliberate.MustXxx panics only in package-level initialization and test helpers, never in a request path.ErrNotFound.Wrap(err), e.NewFrom("context", err) — over
fmt.Errorf wherever one is in use, and use it for every error in that project.Read [${CLAUDE_SKILL_DIR}/references/conventions/errors.md] when the project uses golib/e, when designing a new error
type, or when a package needs internal panic/recover — it carries the golib/e API, the creation decision tree, and the
recover-at-the-boundary pattern.
:= in an inner block silently shadows the outer variable, err most often. Assign with = when the target is
an outer variable.defer evaluates its arguments immediately. Capture later values in a closure: defer func() { notify(s) }().defer fires at function return, not at the end of a loop iteration. Extract the loop body into a function.append to a slice with spare capacity mutates the shared backing array, and every slice over that array sees it.
Cap with s[:len(s):len(s)] or copy.nil from a function whose result type is an
interface, never a typed nil.sync.Mutex or a struct holding one. Copy slices and maps at API boundaries so callers cannot mutate
your state.int. Sized integer types overflow silently, and only a protocol, a binary format, or a measured
constraint justifies one.+= in a loop is O(n²). Use strings.Builder with Grow.if cacheHit := err == nil; cacheHit {. A name is read at
the branch and cannot go stale.Read [${CLAUDE_SKILL_DIR}/references/conventions/gotchas.md] when one of these bites and the obvious fix does not hold
— it carries an annotated reproduction and fix for each.
init(). Spawn them from a constructor that owns the lifecycle.context.Context is the default cancellation mechanism. Explicit stop and done channels belong only in code that
predates it.wg.Go(f) over wg.Add(1) plus defer wg.Done() — the pair is where counter mistakes come from.errgroup.WithContext over a hand-rolled WaitGroup and error collection.<-chan, chan<-) and close only from the sending side.select picks a ready case at random, not in source order. Drain the work channel after the stop signal where
priority matters.nil to a channel to remove its case from a select at runtime.defer mu.Unlock() unless nanoseconds are measured. Reach
for atomic.Bool and atomic.Int64 for flags and counters.fmt.Errorf("%v", obj) can deadlock — it may call obj.String(), which may take the mutex you already hold.
Format from fields you have already read.maps.Clone inside the critical section. Assigning a map or a slice shares the backing storage, so
both variables see every write.Read [${CLAUDE_SKILL_DIR}/references/conventions/concurrency.md] when building a pipeline, a fan-out, a fan-in, or a
bounded worker pool — it carries the full pattern for each and the worker-with-lifecycle template.
tests, case named tt, inputs prefixed give, expectations prefixed want, every
case under t.Run with a descriptive name. Every row must exercise every field.require for anything that makes the rest of the test meaningless — error checks, nil guards. assert for
independent value checks. require.Equal for structs and slices, never reflect.DeepEqual.errors.Is or errors.As, and require.ErrorContains only where no
sentinel exists.t.Fatal only from the goroutine running the test. Use t.Errorf and return in a spawned goroutine.
t.Parallel() does not spawn one, so t.Fatal stays safe in a parallel subtest.t.Helper() in setup helpers, never in an assertion wrapper — there it hides the line that failed.t.TempDir(), t.Setenv(), t.Chdir(), t.Context(), t.Cleanup(). A
test that writes into its source directory or mutates the environment poisons the build cache, which keys on both.time.Sleep. For behavior that depends on time, run the test in a synctest bubble:
synctest.Test(t, func(t *testing.T) { ... }) gives it a fake clock that jumps forward the moment every goroutine in
the bubble blocks, so a one-hour timeout resolves instantly. synctest.Wait blocks until the others are blocked.-race on every run of concurrent code, locally and in CI.json.Marshal field order is not a contract.Test_TypeName for type-level tests, with t.Run per method or scenario. Black-box package foo_test by
default; package foo in foo_internal_test.go where internals must be reached. Benchmarks in
foo_benchmark_test.go.test — creditcardtest — with plain type names
(Stub, Fake) where one type is doubled and prefixed names (StubService) where several are.for b.Loop() for a benchmark loop. The body runs once per -count, so setup outside it runs once, and arguments
and results stay alive without a package-level sink.Read [${CLAUDE_SKILL_DIR}/references/conventions/testing.md] when writing the first test in a package, or when a test
needs httptest or iotest — it carries the table-test template, the parallel-with-teardown shape, and the utility
catalog.
internal/ by default. Everything not deliberately part of the public API goes there, where it can be refactored
without breaking anyone.cmd/<name>/ per binary, holding package main and nothing else.main packages and tests only; dot imports in test files only.Read [${CLAUDE_SKILL_DIR}/references/conventions/structure.md] when creating a package or making a
backward-incompatible change — it carries the staged workflow and the package-naming examples.
For a constructor with three or more optional parameters, pick one shape and hold it across the package.
type Option interface{ apply(*options) }, and give every option
a parameter: rpc.FailFast(true), never rpc.EnableFailFast().Read [${CLAUDE_SKILL_DIR}/references/conventions/idioms.md] when the choice is contested, or when a naming,
declaration, or embedding decision needs a worked example — it carries the decision table across both shapes.
var buf bytes.Buffer is ready to write to. Add a constructor only where a
non-zero default is required.type UserID string does, type MyString string does not.Run blocks until the work is done; Start returns immediately and owns a goroutine. Start takes a context
first.slices and maps over hand-written loops. slices.Contains, slices.SortFunc, slices.BinarySearch,
slices.Compact, maps.Clone, maps.DeleteFunc. A loop reimplementing one of these is a defect, not a style choice.
Comparison helpers come from cmp.log/slog for structured logging. Reserve log for a binary's fatal path.iter.Seq[V] or iter.Seq2[K, V] where the caller consumes elements one at a
time and the whole set need not exist at once; return a slice where it is small and already materialized. Collect with
slices.Collect, slices.Sorted, or maps.Collect — maps.Keys yields an iterator, so the ordered key slice is
slices.Sorted(maps.Keys(m)).yield returns false, and release resources with defer inside the iterator
function.os.Root for any path that comes from outside the program. Its methods refuse to escape the directory, symlinks
included. filepath.Clean does not.math/rand/v2 over math/rand for non-cryptographic randomness; crypto/rand where a value must be
unpredictable.doc.go.gopls is configured for .go files. Use LSP tools rather than Grep or Glob for anything that is a Go identifier —
they resolve imports, aliases, embedded types, and interface satisfaction, which text search cannot.
goToDefinitionfindReferenceshoverdocumentSymbol; across the module — workspaceSymbolgoToImplementationincomingCalls, outgoingCallsGrep and Glob stay correct for comments, string literals, log messages, build tags, config values, and file-name patterns. Subagents exploring Go code reach the same LSP server — instruct them to use it.
golangci-lint run must pass before a commit, and golangci-lint fmt formats — never run gofmt or
goimports separately.govulncheck ./... must exit 0 before a commit that changes go.mod. It traces calls only from the packages in
its pattern, so a narrower pattern hides reachable vulnerabilities. -json and the json, sarif, and openvex
formats exit 0 whatever they report, so none of them is a gate.go fix after raising the go directive. It applies the modernizers mechanically; review the diff as a normal
change.tool directives in go.mod track executable dependencies. Add with go get -tool, run with go tool <name>.
Never reintroduce a tools.go blank-import file.When writing Go, apply these conventions silently — do not narrate a rule while following it. Where existing code contradicts one, follow the codebase and flag the divergence once.
When reviewing Go, cite the violation and show the fix inline. Do not lecture.
Bad: "According to Go conventions, error strings should be lowercase..."
Good: errors.New("Not found.") -> errors.New("not found")
The coding skill governs workflow — discovery, planning, verification. This skill governs Go implementation choices, and wins on any question of how Go code should read. Both are active at once.
The templ, zog, and charm-tui skills own their library stacks and defer to this skill for language conventions.
When in doubt, write boring code.
references/conventions/concurrency.md (opens in a new tab)references/conventions/errors.md (opens in a new tab)references/conventions/gotchas.md (opens in a new tab)references/conventions/idioms.md (opens in a new tab)references/conventions/structure.md (opens in a new tab)references/conventions/testing.md (opens in a new tab)references/versions/go1.21.md (opens in a new tab)references/versions/go1.22.md (opens in a new tab)references/versions/go1.23.md (opens in a new tab)references/versions/go1.24.md (opens in a new tab)references/versions/go1.25.md (opens in a new tab)references/versions/go1.26.md (opens in a new tab)references/versions/go1.27.md (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Invoke whenever Go code is touched at all — writing, reviewing, refactoring, debugging, or exploring a Go project, or raising a module's `go` directive. Also invoke on the symptoms: a goroutine leaks or races, an error loses its context, a test flakes on timing, `go test` rejects a standard-library symbol, or a package resists naming. Covers the language, its standard library, and its toolchain; templ templates, Zog schemas, and Charm TUIs have their own skills, and language-agnostic workflow belongs to the coding skill.
npx claudepluginhub xobotyi/cc-foundry --plugin golang4 skills in this plugin
/charm-tuiWrite and review Charmbracelet v2 terminal UIs in Go: Bubble Tea programs, Bubbles components, Lip Gloss styling and layout, Huh forms, Glamour markdown, fang CLI entry, and TUI testing./templWrite and review templ templates: syntax, components, attributes, styling, JavaScript data passing, escaping and sanitization, code generation, and testing./zogWrite and review Zog schema validation in Go: schema shape, Parse against Validate, required and default semantics, tests and transforms, issue handling, and the zhttp, zjson, and zenv adapters.Other plugins' skills for the same job