2 go rules available
Claude Code loads .claude/rules files whose paths frontmatter matches the files it reads, so a Go rule can stay out of context during frontend work. Two Claude rules match go: a substantive backend developer rule and a short general Go rule. The file below turns them into checks Claude can run itself with its shell access.
Claude Code loads persistent project instructions from CLAUDE.md files and from Markdown rules in .claude/rules/. Rules can be scoped to file paths with a paths frontmatter field, and CLAUDE.md can import other files with @path syntax. The rules in this directory are written as plain instruction prompts: in Claude Code, save them as CLAUDE.md or .claude/rules/ content; in Claude.ai or the Claude API, use the same text as project instructions or a system prompt instead.
.claude/rules/go.mdStarting point, not a tested configuration for your repository. Loaded when Claude Code works with files matching paths. Review the instructions, adapt the file paths and run your project's existing checks.
---
paths:
- "**/*.go"
---
# Go instructions for Claude Code
## Focus for this project
- Reproduce a reported bug with a failing test before changing code, and show the failing output.
- Run gofmt, go vet and go test -race yourself and paste the result; do not claim they pass without running them.
- Prefer the standard library; ask before adding a module dependency.
## Go conventions
- Read the go directive in go.mod before using newer standard-library APIs. With go 1.22 or later, register routes with method and wildcard patterns such as mux.HandleFunc("GET /users/{id}", h) and read the value with r.PathValue("id"); on older modules keep the router the project already uses.
- Pass context.Context as the first parameter of any function that does I/O, and stop work when ctx.Done() closes.
- Wrap errors with fmt.Errorf("...: %w", err) and compare with errors.Is or errors.As; never compare error strings.
- Write table-driven tests with t.Run subtests next to the code (foo_test.go).
## Before you finish
- Run gofmt -l . (must print nothing), go vet ./... and go test -race ./... and report the actual output. If you cannot run them, say so and list the exact commands instead of saying they pass.
- Summarize which of the rules above affected the change.
- You have shell access: run the checks yourself instead of asking the user to, unless a command needs credentials or would deploy.
Create your own Claude rules for Go and share with the community.
Ask for a small change to one matching file. Check the tool's loaded context or instruction view, inspect the diff for the requested convention, and run the relevant build or test. A well-formatted file does not guarantee the model follows every instruction.
Imports with @path can nest up to four hops deep, according to the docs. Claude Code can read AGENTS.md as project instructions without extra configuration, but by default only when there is no CLAUDE.md in the working directory or above it. The docs list this behavior for version 2.1.277 and later and describe a setting (claude-md-and-agents-md) that loads both files. If you maintain AGENTS.md for other tools, you can also import it from CLAUDE.md with @AGENTS.md.
Documentation checked 2026-11-05: Claude Code docs: Manage Claude's memory
Illustrative input and expected result. This example is a verification guide, not a recorded model run.
You ask Claude Code to fix a bug in a Go HTTP handler and want it to reproduce the bug with a test first, then make the fix pass go vet and the race detector.
GET /accounts/{id} returns 500 when the id has no account. Fix it.A new failing test showing the 500, a fix mapping the not-found error with errors.Is to 404, the test passing, and the actual go vet / go test -race output from the session.
Content reviewed 2026-11-05. Confirm instruction activation in your installed client before relying on it.
Generate idiomatic Go code