Go Guidelines
Detected Go Version
!grep -rh "^go " --include="go.mod" . 2>/dev/null | cut -d' ' -f2 | sort | uniq -c | sort -nr | head -1 | xargs | cut -d' ' -f2 | grep . || echo unknown
How to Use
DO NOT search for go.mod files or try to detect the version yourself. Use ONLY the version shown above.
If version detected (not "unknown"):
- Say: "This project is using Go X.XX, so I'll follow Go best practices and modern syntax up to and including this version. If you'd prefer a different target version, just let me know."
- Do NOT list features, do NOT ask for confirmation
If version is "unknown":
- Say: "Could not detect Go version in this repository"
- Use AskUserQuestion: "Which Go version should I target?" with options ... / [1.20] / [1.21] / [1.22] / [1.23] / [1.24] / [1.25] / [1.26] / ...
Reference Loading
Read ONLY the reference file(s) relevant to your current task. Do NOT load all files at once.
When reading reference files, stop at the detected Go version boundary — ignore features from newer versions.
| When you are... |
Read this reference |
| Using version-specific Go syntax or idioms |
references/modern-syntax.md |
| Optimizing performance, struct layout, escape analysis |
references/performance.md |
| Working with goroutines, channels, sync, select, false sharing |
references/concurrency.md |
| Writing HTTP servers, shutdown, health checks, middleware, interfaces, io.Reader |
references/patterns.md |
| Writing tests, mocks, benchmarks, fuzz tests |
references/testing.md |
| Handling errors, wrapping, custom error types |
references/error-handling.md |
| Working with slices, maps, append, memory leaks |
references/slices-and-maps.md |
| Using context.Context, values, cancellation, timeouts |
references/context-patterns.md |
| Using generics, type parameters, constraints |
references/generics.md |
| Debugging subtle bugs, nil traps, shadowing, sync copying, defer, time |
references/pitfalls.md |
Multiple topics may apply. For example, writing a concurrent function with tests: load modern-syntax.md + concurrency.md + testing.md.
After Making Changes
After making Go code changes, run static analysis and tests on the changed packages:
which golangci-lint >/dev/null 2>&1 && golangci-lint run ./path/to/changed/package/... || go vet ./path/to/changed/package/...
go test ./path/to/changed/package/... -race
- Prefer
golangci-lint when available, fall back to go vet
- Always run tests with the race detector
- Fix all reported issues in the changed code before finishing
- Do not fix pre-existing issues in unrelated code
- If neither linter is available, skip silently and continue
Source: mhmtszr/go-guidelines — distributed by TomeVault.
1---2name: go-guidelines3description: Go best practices for performance, modern syntax, generics, patterns, testing, error handling, and concurrency. Use when writing or reviewing Go code. Use when this capability is needed.4---56# Go Guidelines78## Detected Go Version910!`grep -rh "^go " --include="go.mod" . 2>/dev/null | cut -d' ' -f2 | sort | uniq -c | sort -nr | head -1 | xargs | cut -d' ' -f2 | grep . || echo unknown`1112## How to Use1314DO NOT search for go.mod files or try to detect the version yourself. Use ONLY the version shown above.1516**If version detected (not "unknown"):**17- Say: "This project is using Go X.XX, so I'll follow Go best practices and modern syntax up to and including this version. If you'd prefer a different target version, just let me know."18- Do NOT list features, do NOT ask for confirmation1920**If version is "unknown":**21- Say: "Could not detect Go version in this repository"22- Use AskUserQuestion: "Which Go version should I target?" with options ... / [1.20] / [1.21] / [1.22] / [1.23] / [1.24] / [1.25] / [1.26] / ...2324## Reference Loading2526**Read ONLY the reference file(s) relevant to your current task. Do NOT load all files at once.**2728When reading reference files, **stop at the detected Go version boundary** — ignore features from newer versions.2930| When you are... | Read this reference |31|---|---|32| Using version-specific Go syntax or idioms | [references/modern-syntax.md](references/modern-syntax.md) |33| Optimizing performance, struct layout, escape analysis | [references/performance.md](references/performance.md) |34| Working with goroutines, channels, sync, select, false sharing | [references/concurrency.md](references/concurrency.md) |35| Writing HTTP servers, shutdown, health checks, middleware, interfaces, io.Reader | [references/patterns.md](references/patterns.md) |36| Writing tests, mocks, benchmarks, fuzz tests | [references/testing.md](references/testing.md) |37| Handling errors, wrapping, custom error types | [references/error-handling.md](references/error-handling.md) |38| Working with slices, maps, append, memory leaks | [references/slices-and-maps.md](references/slices-and-maps.md) |39| Using context.Context, values, cancellation, timeouts | [references/context-patterns.md](references/context-patterns.md) |40| Using generics, type parameters, constraints | [references/generics.md](references/generics.md) |41| Debugging subtle bugs, nil traps, shadowing, sync copying, defer, time | [references/pitfalls.md](references/pitfalls.md) |4243**Multiple topics may apply.** For example, writing a concurrent function with tests: load `modern-syntax.md` + `concurrency.md` + `testing.md`.4445---4647## After Making Changes4849After making Go code changes, run static analysis and tests on the changed packages:5051```bash52which golangci-lint >/dev/null 2>&1 && golangci-lint run ./path/to/changed/package/... || go vet ./path/to/changed/package/...53go test ./path/to/changed/package/... -race54```5556- Prefer `golangci-lint` when available, fall back to `go vet`57- Always run tests with the race detector58- Fix all reported issues in the changed code before finishing59- Do not fix pre-existing issues in unrelated code60- If neither linter is available, skip silently and continue6162---63> Source: [mhmtszr/go-guidelines](https://github.com/mhmtszr/go-guidelines) — distributed by [TomeVault](https://tomevault.io).64<!-- tomevault:4.0:skill_md:2026-06-29 -->