AGENTS.md for Go
A complete, production-ready AGENTS.md example for Go projects — token-optimized to 371 tokens, ready to drop into your repo. Plus a free generator that tailors it to your exact stack in 3 questions.
What is AGENTS.md?
AGENTS.md is a machine-readable specification file that tells AI coding assistants (Claude Code, Cursor, GitHub Copilot, Windsurf) exactly how to work in your codebase — the real commands to run, the permission boundaries, and code style rules they must follow. Unlike documentation written for humans, AGENTS.md is optimised for agents: every line prevents a concrete mistake.
AGENTS.md example for Go
Here is a complete AGENTS.md for a Go project, optimized to 371tokens using MDPilot's 5-pass optimizer:
# Role declaration
I am the primary coding assistant for this Go project.
# Environment setup
To set up the environment, run the following commands:
```go
GOPROXY=https://proxy.golang.org,direct go env -w GO111MODULE=on
git config --global --add safe.directory '*'
Go version: 1.20.0
```
# File-scoped build/test commands
Use the following commands to build and test files in this project:
* Use `go run .` to run the main package.
* Use `go build .` to build the main package.
* Use `go test ./...` to run all tests.
* Use `go mod tidy` to clean up the go.mod file.
# Code style rules
* All code must be formatted with `gofmt`.
* Table-driven tests are preferred.
* All tests should use the `context.Context` pattern.
* No circular imports are allowed.
* Interface-based design is preferred.
# Key project paths
* The main package is located in `./`.
* The go.mod file is located in `./`.
* Tests are located in `./` and subdirectories.
# Permission boundaries
## Allowed
* Auto-format code with `gofmt`.
* Run tests with `go test ./...`.
* Update the go.mod file with `go mod tidy`.
## Approve
* Manual review of all changes to the main package.
* Review of new dependencies added to the go.mod file.
## Never
* Directly push to the main branch.
* Make changes to code style or formatting that are not automatically applied by `gofmt`.
# PR format
All pull requests should include a clear description of changes made, and should be reviewed by at least one other team member.Why Go projects need AGENTS.md
In Go projects, maintaining a consistent code style and ensuring proper dependency management are crucial to avoid issues such as incorrect formatting and missing dependencies. The `go mod tidy` command helps to keep the go.mod file up-to-date, while `gofmt` ensures that all code is formatted consistently. Additionally, using table-driven tests and the `context.Context` pattern helps to write more robust and maintainable tests. By following these guidelines and using AGENTS.md, developers can reduce the risk of common mistakes and ensure that their project is well-organized and easy to maintain.
Generate your own AGENTS.md for Go
Answer 3 questions about your project and MDPilot generates a AGENTS.md grounded in your exact stack — real commands, real paths, no hallucinated scripts.
Generate AGENTS.md free →Frequently asked questions
What is AGENTS.md?
AGENTS.md is an open standard for AI coding assistant instructions that provides guidelines for coding style, dependency management, and testing.
How do I format my Go code?
You can format your Go code using the `gofmt` command, which is the standard formatting tool for Go.
Where should I place the go.mod file in my Go project?
The go.mod file should be placed in the root directory of your Go project, alongside the main package.
What is the purpose of the context.Context pattern in Go tests?
The context.Context pattern is used to provide a way to cancel tests and to handle timeouts and deadlines, making tests more robust and maintainable.