Agent Friendly Code

What to put in an AGENTS.md for a Go repo

Agents know the go tool. What they can't see is which files are generated, which linters you run, and whether the repo is one module or a workspace. Say those, and how to run one test.

Which commands should it list?

  • go build ./...every package; ./... skips testdata/, vendor/ and dot or underscore directories
  • go test -race ./...all tests with the race detector; -count=1 bypasses the test cache
  • go test ./pkg/foo -run '^TestBar$'one test; -run is a regex, X/Y matches subtests
  • go vet ./...go test runs only a high-confidence subset of vet's checks
  • golangci-lint runreads .golangci.yml (or .yaml, .toml, .json); pin the version
  • gofmt -l .lists unformatted files; or goimports, which also fixes imports
  • go generate ./...never run by go build or go test; rerun after changing its inputs
  • go mod tidyafter adding or removing an import; syncs go.mod and go.sum

Write them as your repo runs them, with its package manager and flags, plus how to run one test.

What layout should it explain?

  • The module path in go.mod, and whether a go.work ties several modules together (go env GOWORK shows the one in use).
  • Where commands live, usually cmd/<name>/, and what is under internal/: only code below its parent can import it.
  • Which files are generated, and the //go:generate line or tool that makes each.

What do agents get wrong?

  • A file that starts with // Code generated … DO NOT EDIT. is overwritten by the next go generate; edit its input instead.
  • Commit generated files: clients build without running go generate.
  • go.work is usually left out of git, so CI tests each module as others will use it; say so if yours is committed.

From the official docs: pkg.go.dev/go (new tab) · go.dev/layout (new tab) · go.dev/mod (new tab) · go.dev/generate (new tab) · golangci-lint.run/file (new tab) · pkg.go.dev/goimports (new tab). The rest of the file is the same for any project: what goes in an AGENTS.md.

Go repos with an AGENTS.md or CLAUDE.md (23)

23 of the 40 Go repos on the leaderboard have an AGENTS.md or CLAUDE.md at the root, and 21 are long enough to pass the AGENTS.md check in full. Most-starred first; each file name links to the file.

Go repos on the leaderboard with an AGENTS.md or CLAUDE.md
RepoFileLength
ollama/ollamaAGENTS.md 357
kubernetes/kubernetesAGENTS.md 1,884
gohugoio/hugoAGENTS.md 1,711
caddyserver/caddyAGENTS.md 9,429
moby/mobyAGENTS.md 553
prometheus/prometheusAGENTS.md 6,664
traefik/traefikAGENTS.md 14,368
go-gitea/giteaAGENTS.md 3,435
cli/cliAGENTS.md 5,858
milvus-io/milvusAGENTS.md 11,250
pingcap/tidbAGENTS.md 14,515
labstack/echoCLAUDE.md 3,132
cockroachdb/cockroachCLAUDE.md 5,664
charmbracelet/crushAGENTS.md 10,951
vitessio/vitessAGENTS.md 1,237
nats-io/nats-serverAGENTS.md 2,185
weaviate/weaviateCLAUDE.md 5,912
google/osv-scannerAGENTS.md 4,648
inngest/inngestAGENTS.md 2,782
gitlab-org/gitlab-runnerAGENTS.md 12,818
gitlab-org/cliAGENTS.md 7,602
gitlab-org/gitalyAGENTS.md 2,362
privy-io/go-sdkAGENTS.md 3,533

More examples