/effective-go:effective-gofrom effective-go
Guides writing idiomatic Go code with rules from Effective Go, Google Style Guide, and Go Proverbs. Covers errors, testing, style, comments, and simplification.
Ships in effective-go. 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.
Write Go the way the Go community writes it, with a few house preferences that win when the sources disagree. The sources, in the order they are consulted: this skill's house rules, then Effective Go, the Google Go Style Guide, the Go Proverbs, and the Gruntwork style guide.
When two rules conflict, resolve in this order — clarity, simplicity, concision, maintainability, consistency. Clarity to a reader who did not write the code beats every other consideration. Consistency with the surrounding package is real, but it never justifies spreading a mistake.
This skill is a specification, not advice. "The code compiles and the tests pass" does not make it done; it is done when the checklist at the end is true.
SKILL.md carries the rules and a short summary of each topic; five files beside it carry the full text:
errors.md — how to construct, wrap, check and handle errorstesting.md — table tests, assertions, the Fn-field mock patternstyle.md — naming, layout, receivers, interfaces, concurrency, context, logging, dependenciescomments.md — doc comments and inline comments: what earns a line, what never doessimplification.md — reshaping working code without changing behavior: nesting, splits, merges, dead codeThe first time you use this skill in a session, read all five before doing anything else — before opening the target code, before writing a line, before answering a question. The summaries below are reminders of text you have already read, not a substitute for it. Re-read the named file at the step that names it. If a file is missing, say so; do not proceed as if the summary were the whole skill.
use-modern-goThis skill covers idiom and discipline; it does not know what changed in the Go release you are targeting. JetBrains ships a skill for exactly that: use-modern-go (plugin modern-go-guidelines, from github.com/JetBrains/go-modern-guidelines) runs a CLI that lists version-specific guidelines for the Go in go.mod — newer than any model's knowledge cutoff. It is not distilled here on purpose; it is used live.
At step 2 of the process, check whether use-modern-go is among your available skills.
list for the file you are about to edit, and treat its output as authoritative for which language and library features to use (for range n, slices/maps, min/max, sync.WaitGroup.Go, testing/synctest, and whatever it adds later). The house rules in this skill still govern error wording, mocks, comments and process; where the two disagree on an idiom, use-modern-go wins because it knows the toolchain.use-modern-go would let you use Go features newer than your training data, with the install commands:
/plugin marketplace add JetBrains/go-modern-guidelines then /plugin install modern-go-guidelines@goland-claude-marketplacecodex plugin marketplace add JetBrains/go-modern-guidelines then codex plugin add modern-go-guidelines@goland-codex-marketplacePATH (it go installs a small CLI on first use). Then carry on with this skill; do not block on the answer, and do not repeat the recommendation later in the session.mainNot for choosing an architecture or a library — this skill governs how Go is written once the decision is made.
Work through these in order for every change. Each step names the file to re-read when it applies.
go.mod — never a feature it does not have, never a bump without being asked, and leave the go directive exactly as go mod init or the project wrote it. Prefer the standard library to a dependency; prefer copying a small helper to adding a module. If use-modern-go is installed, invoke it now for the file you are about to touch; if it is not, note that you will recommend it once at the end of this reply (see Companion).ctx context.Context first, error last, accept interfaces / return concrete types, zero value useful, no any where a real type exists.else after a return; no nesting the success case inside if err == nil.errors.md. failed to <verb> <object> [%q detail]: %w; errors.New for any message with no % in it — in main and in tests too. Handle each error exactly once.testing.md. Red → green: a new test fails before the code exists and passes after; a refactor's pinning test passes before and after, unmodified. Append to the existing _test.go; a new file only when none exists or a separate tier (smoke, e2e, journey) needs a build tag. Table-driven, t.Context(), got-before-want messages, hand-written Fn-field mocks whose nil fields fail loudly. For a feature, propose user journeys and write the ones the user picks.comments.md. Doc comments on every exported identifier, starting with its name, ending with a period. Nothing that restates the next line; nothing about how the code got here.simplification.md: one change at a time, each pinned by a test that predates it.gofmt -l . (or goimports), go vet ./..., go build ./..., go test -race ./..., and the project's linter if it has one (make lint, golangci-lint run). Run them non-interactively with stdin closed; for a slow test or analyzer run, monitor its log and process state every three minutes at most — keep waiting while it is making real progress, and if it deadlocks, stalls, or loops, inspect the target PID/command in a separate read-only check first and stop only the verified literal PID(s) (never inline $(...), unverified $VAR, pkill -f, killall, or touching unrelated session services; apply the same read-then-execute-with-literals rule to rm, git clean, and any other destructive command) before reporting the last output. Paste or report actual results; a claim without output is not a result.The user has the last word on when work becomes permanent.
errors.md)| Rule | Write | Never |
|---|---|---|
| Operational messages | fmt.Errorf("failed to open config file %q: %w", path, err) | "open %q: %w", "opening file: %w", "error: %w" |
| Sentinels are states | errors.New("customer not found") | errors.New("failed to find customer") |
| Validation quotes the value | fmt.Errorf("unknown tier %q", tier) | "unknown tier", "failed to validate tier" |
| Wrapped error last | "...: %w" | "%w: ...", %v for an error you mean to wrap |
No directives → errors.New | errors.New("BUCKET is required") | fmt.Errorf("BUCKET is required") |
| Quote strings | %q | '%s', "%s" |
| Casing | lowercase start; proper nouns/acronyms allowed ("AWS region is unset") | "Failed to ...", trailing period |
| Compare | errors.Is / errors.As | err.Error() == ..., strings.Contains(err.Error(), ...) |
| Callers decide | exported sentinel or typed error | in-band -1/""/nil |
| Handle once | return or log or exit | log-and-return |
Close | defer f.Close() for readers; check Close on writers | ignoring a writer's Close |
| Panics | programmer errors and Must* at init with literal input | anything a user can trigger |
| Prefixes | context added per layer | "pkg: " on every message |
A chain must read as a sentence: failed to load configuration: failed to parse "config.yaml": yaml: line 3: mapping values are not allowed.
testing.md)Test… function; a new kind of assertion is a new column, not a new function.t.Context() (Go 1.24+; the pre-1.24 equivalent is in testing.md), t.TempDir(), t.Setenv(), t.Cleanup(), t.Helper(), t.Parallel() where safe.t.Errorf("Func(%v) = %v, want %v", in, got, want) — got before want. t.Fatalf only when continuing is meaningless.errors.Is/errors.As, never by string.want is a literal, never built with the code's own formula, helper, or exported constant. Assert what a caller observes and the spec fixes, never call order, a count of queries or calls no consumer or upstream dependency is promised (for work that must not grow with input, assert equal counts on one row and on many), a constant's own value, or a whole output where one fact matters. Existing tests that cover code you edit or review get the same check: report each tautological want, change detector, test that no edit to the code can turn red, or copy of another test with its fix, fix a row you are already changing, and leave the rest unedited unless asked. A bug fix corrects the wrong table row in place or adds a behavior-named row for a genuine gap; no TestIssue…, no second test on an input already covered.Fn field per method. A nil Fn returns errors.New("mockT.Method: methodFn not implemented"); a method without an error return panics with the same text. Add call counters when the code under test swallows errors.httptest for HTTP; real or in-memory implementations for stores; no mocking or assertion libraries added to a project that has none; no sqlmock._test.go. A new test file only when (a) none exists for that source file or package, or (b) a separate tier — unit / smoke / e2e / journey — needs a build tag, a black-box package, or infrastructure the unit tests must not touch.go vet ./... and go test -race ./... before claiming green.style.md)Naming. MixedCaps, never underscores. Initialisms keep one case: userID, ServeHTTP, xmlAPI. Name length scales with scope: i in a loop, pendingUploads at package level. No Get prefix on getters. No type in the name (users, not userList). Package names short, lowercase, singular, no util/common/helpers; don't repeat the package name in its exports (widget.New, not widget.NewWidget). Receivers are one or two letters, the same on every method of the type.
Layout. gofmt/goimports clean, always. Imports in groups: stdlib, third-party, local. cmd/<binary>/main.go for entrypoints; internal/ for everything not meant to be imported by other modules; a top-level package or pkg/ only for code deliberately published. Start flat; split packages by responsibility (billing, auth), never by kind (models, utils). Flags only in main; libraries take config through their API.
Functions. Small, one job, named for it. Parameters: ctx first, options struct or functional options once there are more than a few, error last. Prefer returning a value to mutating through a pointer. Named results only when they add clarity; no naked returns outside tiny functions. No else after return; switch over long if/else if chains.
Types. Make the zero value useful. Pointer receivers when the method mutates, the type holds a mutex, or the struct is large — and when in doubt; never mix pointer and value receivers on one type. Use any, not interface{}, and only when no concrete or narrow type will do. Field names in struct literals for types from other packages. len(s) == 0 for emptiness, never s == nil.
Interfaces. Defined by the consumer, next to the code that calls them, with only the methods it calls. Accept interfaces, return structs. No interface "in case"; no interface whose only purpose is to mock a type you own. Compile-time check when it matters: var _ Storage = (*S3)(nil).
Concurrency. Every goroutine has an owner and a documented exit; prefer a synchronous function and let the caller add go. Channels orchestrate, mutexes serialize. ctx is always first, never stored in a struct, never a custom context type; forward the caller's ctx, don't invent one. context.WithValue only for request-scoped data crossing API boundaries, never for loggers or dependencies. -race on anything concurrent.
Logging. log/slog with key-value attributes, injected — never pulled from a context or a global. Errors are logged once, at the top of the stack, never by a layer that also returns them. A library may emit Info/Debug progress lines through an injected logger when its caller gave it one for that purpose; it never Fatals.
Dependencies. Standard library first. A small helper is copied, not imported. Pin versions; run the Go version in go.mod.
comments.md)A comment earns its place by carrying information the code does not, about the code as it is now, in as few lines as that takes. Doc comment on every exported identifier: a sentence, starting with the name, ending with a period, written for the caller. Two lines above a declaration is the working limit; a rule is a caller obligation or guarantee, never rationale or the body restated, and prose over four lines is a question for the user, not a keep. Never name a field the body reads or a helper it calls; the lock to hold and the neighbour differed from are fine. Cover test: hide the comment — if the code lost nothing, delete it. Subject test: the comment is about these lines (usually why they differ from their neighbours), not the feature. Present tense only; no "used to", "per review", finding numbers, pass labels, task IDs, phase names. No counts of things that live elsewhere ("the 7 tests", "both fields") — name the set so the comment grows with it. A regression is pinned by a test named after the invariant, not by a warning comment, and so is every comment addressed to a future editor ("never", "always", "keep in step", "needs review before"): a comment enforces nothing, so the rule becomes an assertion in the existing test that already runs the code (a new Test… only when none performs the steps), the why goes above the assertion, and one line of fact stays in the code. Go's own code keeps non-doc comments to one or two lines; over three is foreign. Verify every name a comment mentions. Never touch //go:build, //go:generate, //nolint directives.
simplification.md)Reshape only the code in scope, with behavior preserved exactly and proven by a test that existed before the change and passes after it, unmodified. Understand why code exists before removing it (git history, callers, edge cases). One change at a time, gates run after each; a failing test means revert the change, never the test. Cyclomatic complexity = 1 + each if/else if/case/for/&&/||; over 10, split along decision clusters into pure, named, tested functions — never into once-called fragments. Two functions with the same shape are diffed, their callers counted, and a merge is proposed, never done by reflex. No tests in the repo → ask before adding any; declined → report the change as unproven. Prefer the stdlib idiom (slices, maps, errors.Join) to a hand-rolled loop.
| Proverb | Do this |
|---|---|
| Don't communicate by sharing memory; share memory by communicating | Hand data off over a channel instead of two goroutines touching one variable under a lock |
| Concurrency is not parallelism | Add goroutines to structure independent work, not because "it could run at once" |
| Channels orchestrate; mutexes serialize | A mutex guards a field; a channel coordinates a pipeline — don't swap them |
| The bigger the interface, the weaker the abstraction | One to three methods, defined where they are used |
| Make the zero value useful | var b Buffer works without a constructor |
interface{} says nothing | Reach for a concrete type, a narrow interface, or a type parameter first |
| Gofmt's style is no one's favorite, yet gofmt is everyone's favorite | Run it; never argue with it |
| A little copying is better than a little dependency | Twenty lines of helper are copied, not imported |
| Syscall / cgo must always be guarded with build tags; cgo is not Go | OS-specific and C code lives behind //go:build; avoid cgo when a pure-Go path exists |
| With the unsafe package there are no guarantees | Don't; if forced, isolate it and document why |
| Clear is better than clever | The boring version wins |
| Reflection is never clear | Type switches, generics or explicit code before reflect |
| Errors are values | Build helpers around them; they are not exceptions |
| Don't just check errors, handle them gracefully | Wrap with context, retry, degrade, or surface — a bare return err is the minimum, not the goal |
| Design the architecture, name the components, document the details | Names first; a good name shrinks the doc comment |
| Documentation is for users | Write doc comments for the caller, not the maintainer |
| Don't panic | error for anything a user can cause |
| Excuse | Reality |
|---|---|
"The Google guide says open %q: %w is fine" | The house rule wins where they disagree. failed to open file %q: %w. |
| "Short error messages are more idiomatic" | Terse chains are unreadable at the top. Every layer names what it tried to do. |
| "Logging it here too gives more context" | It gives the same failure twice. Put the context in the wrap and log once at the top. |
"fmt.Errorf with a constant string is harmless" | It is errors.New. Linters flag it; reviewers flag it; write it right the first time. |
"A struct-field mock is simpler than Fn fields" | A struct-field mock passes silently when the code calls a method the test forgot about. Nil Fn must fail. |
"context.Background() in a test is fine" | t.Context() cancels when the test ends and kills leaked goroutines. Use it, or WithCancel + t.Cleanup(cancel) before Go 1.24. |
| "I'll add an interface so it's mockable later" | Interfaces are defined by consumers when they need them. Later is later. |
| "This helper deserves its own package / dependency" | A little copying beats a little dependency. Copy it. |
| "The package already does it this other way" | Match the package where it is right; write new code correctly where it isn't. Consistency doesn't spread mistakes. |
| "It compiles and the tests pass, it's done" | Done is the checklist below being true, with the gate output in hand. |
"I'll skip -race, there's no concurrency here" | If there's a goroutine, channel, or shared map anywhere in the package, run it. It's cheap. |
| "The comment helps explain what this line does" | If the line needs explaining, rename or split; comments carry why. |
| "I'll push so the user can see it in the PR" | Pushing publishes. Say it's ready; the user decides when it leaves the machine. |
| "The commit was approved, so pushing is implied" | Two approvals. Commit means commit. |
| "A new test file keeps things organized" | The existing file's bottom is the organization. A new file is for a missing file or a separate tier, nothing else. |
| "This case deserves its own test function, the table would get busy" | Count the setup and action steps. At 60% shared it is a row: however many rows a table has, it still has one setup block and one call. |
| "No existing test checks the file on disk, so this one is new" | The assertion is new. The arrange and act are not. Add the check after the call the existing test already makes. |
| "Tests after the refactor prove it works" | They prove the new code does what the new code does. The pinning test predates the change. |
| "That test already covers it, so it's pinned" | Only if it can fail. A want computed with the code's own formula passes whatever the code does. Check it, and report it if it can't. |
| "Journeys are the user's job" | Proposing them is yours. Writing the picked ones is yours. |
| "Reading the companion files is overkill for a one-line change" | One-line changes are where error strings and '%s' slip in. Read them. |
| "The comment explains the history of this fix" | The reader sees today's code. State the constraint; the story goes in the commit. |
| "The count is accurate, I just checked" | Accurate today; nothing re-checks it when the next one lands. Name the set instead. |
| "The tests need a small tweak after my refactor" | You changed behavior. Revert the refactor, not the test. |
| "I'll fix the error wording while I'm refactoring" | That's a behavior change hiding in a refactor. Separate step, stated in the report — or leave it. |
| "Those two functions are basically the same, I'll merge them" | Diff, count callers, propose. A near-duplicate is sometimes two things that change for different reasons. |
error, or a package name%w first, %v on an error you meant to wrap, '%s' anywherefmt.Errorf with no % in iterr.Error() compared to a string, or err == ErrX on a wrapped errorlogger.Error(...) immediately followed by return fmt.Errorf(...)context.Background() in a test; a ctx stored in a structFn fields; a mock method that returns zero values when unwiredinterface{}, GetFoo(), snake_case, utils package, Url/IdWaitGroup/errgroup, no ctx.Done() pathpanic reachable from input; a Must* fed runtime datavet/test -race outputTest… written to back it when an existing test already runs the code_test.go beside an existing one for the same source file, with no build tag and no separate tierTest… function that repeats 60% or more of the setup and action steps an existing test on the same function already performswant or asserts call order or an unpromised call count, and your report does not mention itgit push in your plan without a user message approving that push; a commit the user has not asked foruse-modern-go is available, or you are recommending it for the second time this sessionerrors.md, testing.md, style.md, comments.md and simplification.md this sessionerrors.md, testing.md, style.md, comments.md and simplification.md this sessionuse-modern-go invoked if installed, recommended once if notgo.mod; no new dependency that the stdlib or twenty copied lines could replaceMixedCaps, consistent initialisms, scope-sized, no Get, no type suffixes, singular lowercase packagesctx first, error last, accept interfaces / return structs, no any where a type existselse after returnfailed to <verb> <object> [%q]: %w; sentinels are noun phrases; errors.New when nothing is formatted; %q not '%s'errors.Is/errors.Asctx forwarded, never storedt.Context(), got-before-want messages, errors.Is assertions, Fn-field mocks that fail loudly, t.Parallel() where safewant or change-detector assertion; each one found reported with its fix, none rewritten unasked except a row already being changed_test.go; a new file only for a missing file or a separate build-tagged tierTest… functionsgofmt/goimports, go vet ./..., go build ./..., go test -race ./..., project linter — run, and the output reportedWhat SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub patrickdappollonio/claude-plugins --plugin effective-goOther plugins' skills for the same job