Omniscio

OmniscioGuidesCLAUDE.md examplesGo (Golang)

CLAUDE.md for a Go project

Go (Golang) has more convention than the compiler enforces, and two of the ones that matter most are where code lives and how an error travels. The layout is documented, not guessed: the Go team's own module guide recommends internal/ for packages other modules should not import, and cmd/ for commands.

The file below writes those conventions down with the call that satisfies them, so a session has something checkable rather than a reminder to write idiomatic Go. Each block is explained underneath, with what was left out and why.

Checked against Anthropic's Claude Code documentation and the Go project's own docs on November 25, 2026. By the Omniscio team. Updated .

The file

This one describes a notification service with an HTTP API and a Postgres database. Save it as ./CLAUDE.md or ./.claude/CLAUDE.md in the repository root.

# notifier

Notification service: sends email, SMS and webhooks from queued events.
Go 1.27, standard library HTTP, Postgres through pgx.

## Commands

go build ./...
go test ./...
go test ./internal/store -run TestCreate -v
go test -race ./...
go vet ./...
golangci-lint run

## Layout

- cmd/api/            the binary: flags, config, wiring, then serve
- internal/           everything else; other modules cannot import it
- internal/notify/    the domain: events, routing rules, templates
- internal/store/     Postgres
- internal/transport/ HTTP handlers and the JSON shapes
- migrations/         golang-migrate; append only

## Rules

- Add context as an error crosses a boundary: fmt.Errorf("send notification %s:
  %w", id, err). Return a sentinel such as ErrNotFound unchanged, so errors.Is
  still finds it.
- Never panic outside main. Return the error and let the caller decide.
- context.Context is the first parameter of every function that does I/O. It is
  never stored in a struct and never passed as nil.
- Accept interfaces, return structs. Define the interface in the package that
  uses it, not the one that implements it.
- Every goroutine has an owner: it is joined through errgroup or waited on with
  a done channel. No fire-and-forget.
- No global mutable state. Dependencies are fields on a struct built in main.
- Log with log/slog, structured. No fmt.Println, no log.Printf.

## Testing

- Table-driven tests with t.Run, and t.Parallel() where the test owns its data.
- httptest for handlers. Testcontainers for Postgres, not a mock of the driver,
  behind a build tag so go test ./... needs no Docker.
- A bug fix starts with a test that fails before the fix.

## Traps

- internal/ is enforced by the go tool: a package outside this module cannot
  import it. That is why the domain lives there.
- A migration that has run anywhere is append only.
- Share one http.Client with a Timeout, set a deadline on each request context,
  and set ReadHeaderTimeout, WriteTimeout and IdleTimeout on http.Server.

That is 52 lines. Each rule saves a review comment.

Why each block is there

The opening description

The version and the HTTP approach are in the opening description because they decide what "the standard way" means in this repository. A session that assumes a router framework will add a dependency nobody asked for.

The command block

The commands are the whole check chain, in the order a change meets them: build, test, race, vet, lint. The narrowed test command is there so a session can run one package while it works instead of the whole module every time.

The race detector gets its own line because the flag has to be named every time. A file that does not name it gets tests that pass and a race no test looked for.

The layout

The cmd and internal directories come straight from the Go team's module guide. It recommends putting supporting packages under internal, because other modules cannot import them, which leaves the API free to change without breaking anyone outside; and it describes the convention of keeping commands in a cmd directory, which it calls very useful in a mixed repository that has both commands and importable packages.

Naming cmd and internal, then mapping the three packages and the migrations directory, is the whole layout section. The guide already explains why; the file only has to say that this repository follows it, and which package owns what.

The rules

The error rule is the one that changes the most code. The Go blog's own wording is that the %w verb makes the returned error carry an Unwrap method returning the argument, which is what lets errors.Is and errors.As find the original later. A rule that says "wrap your errors" produces a new error with the old text; the rule here shows the call that keeps the chain.

The context rule is quoted from the context package's own documentation: do not store Contexts inside a struct, pass one explicitly to each function that needs it, and the Context should be the first parameter, typically named ctx. Writing that into the file is what stops a session threading a context through a struct field to avoid touching five signatures.

The goroutine rule and the global-state rule are the two that no go vet check catches. Both are phrased as a property a reviewer can check: an owner for every goroutine, and dependencies as fields on a struct built in main.

Testing

Table-driven tests are the convention this file sets, and the file names the two details that get skipped: t.Run so a failure names its case, and t.Parallel() only where the test owns its data.

The Postgres line is the concrete version of "test against something real". A mock of the driver passes while the SQL is wrong, which is the failure a database test exists to catch.

Traps

The internal/ trap is the go tool enforcing the layout, and it is worth one line because it is the reason the domain can move without a breaking change.

The other two are easy to miss: a migration rule and a timeout rule. Both are cheap to state and expensive to learn by breaking production, which is the kind of fact Anthropic says a CLAUDE.md should hold.

What was left out, and why

  • A rule that only matters in one package. That belongs in a path-scoped rule under .claude/rules/, which loads only when Claude touches a matching file.
  • The module path and the dependency list. They are in go.mod, and a copy in the CLAUDE.md goes stale on the next go get.
  • gofmt. gofmt decides formatting, and a rule restating it can only disagree with the tool.
  • The release and deploy procedure. Multi-step procedures belong in a skill, not in context every session.
  • Personal database URLs and test accounts. Those go in CLAUDE.local.md, so add that file to .gitignore and it is never committed.
  • "Write idiomatic Go." Uncheckable. The rules above say which idioms this repository means.

Adapting it

  • A CLI. Keep cmd/, drop the transport and migration blocks, and add the rule that matters for a command: what the exit codes mean and what goes to stderr.
  • A library. Drop cmd/ entirely, keep the error and context rules, and add what counts as a breaking change for the exported API.
  • A different router or database driver. Change the lines that name them and leave the rules alone; they are about behaviour, not packages.

Then prove it loaded. /context all lists the memory files read at launch, and a file that is missing from that list is not being ignored; it is not being seen.

How this page was written

The guidance on what belongs in a CLAUDE.md, how long it should be and how Claude treats it was read from Anthropic's Claude Code memory documentation on November 25, 2026. The statements about Go were read from the Go project's own documentation the same day, and every claim about them is quoted from those pages.

The example file was written for this page and was not run against a live service. Every line is meant to be checked against your own repository before it is kept, which is why the adaptation steps below are worth working through before you keep it.

Sources

Common questions

What should a CLAUDE.md for a Go project contain?

The go commands you actually run, the cmd and internal layout, the error and context rules that Go reviewers enforce, and the traps: migrations that cannot be rewritten, a shared HTTP client with no timeout, and a goroutine nobody joins. Anthropic's target is under 200 lines, so go.mod and the standard library conventions stay out.

Why put code under internal/ in the CLAUDE.md layout?

Because Go's own module guide recommends it: packages under internal cannot be imported by other modules, so the API is free to change without breaking anyone outside the repository. Writing that line in the file tells a session where the domain belongs, rather than leaving it to guess between the root package and a new top-level folder.

Should the CLAUDE.md require error wrapping?

Yes, with the verb spelled out. Since Go 1.13, fmt.Errorf supports %w, and an error wrapped that way keeps its original for errors.Is and errors.As to find. A rule that says "wrap your errors" does nothing; a rule that shows the call with %w in it is the shape a reviewer can check.

Does this file work for a CLI or a library?

The skeleton does. A CLI keeps cmd/ and drops the HTTP and migration blocks; a library drops cmd/ entirely, keeps the error and context rules, and adds what counts as a breaking change for its exported API. The four questions stay the same: how do I run it, where does the code live, what must every change obey, and what has bitten us before.

One instructions file, every agent that reads one

Omniscio keeps your canonical CLAUDE.md or AGENTS.md mirrored to the filenames Codex, Gemini, Cursor and Copilot look for, and flags a copy that was edited outside it. Any model, any harness.

The features page covers what else it does, pricing covers the plans, and you can download it for Windows, macOS or Linux.