go

A set of rules for writing Go code, focusing on meaning and program behavior rather than formatting. Go is a programming language often used for reliable command-line tools, servers, and background services.

In plain words
What is it for?
It is for reviewing Go structs, state handling, package organization, helper reuse, review-file writes, and Git operations in command-line tools or servers.
Why use it?
It helps prevent silent data loss, incomplete state resets, unsafe shared errors, unnecessary wrappers, and disorganized changes in Go projects.

Cursor rule for Cursor

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/tomasz-tomczyk/crit/go
Clone the repo
git clone --depth 1 https://github.com/tomasz-tomczyk/crit

Made for: Cursor.

Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 389 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.00389
Opus 5 $0.00000 $0.00195
Sonnet 5 $0.00000 $0.00078
Haiku 4.5 $0.00000 $0.00039

Measured 2d ago against content hash 3cce88882bdf, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

go scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.cursor/rules/go.mdc · 32 lines

What it actually says

Go Code Rules (semantic — linters handle syntax/style)

Struct & State Integrity

  • When building structs for serialization or cross-boundary transfer, verify ALL source fields are mapped. Missing fields cause silent data loss.
  • For boolean config fields, always use presence tracking to distinguish "not set" from "set to false". Go's zero-value for bool is false, which is ambiguous.
  • When clearing/resetting state from a struct, enumerate ALL fields. Review comments, file comments, and metadata must all be cleared.
  • When storing error values in shared state (atomic.Value, channels), copy the value first: e := err; store(&e).

Code Organization

  • This is package main. Do NOT export functions/types unless required by tests in _test.go files.
  • Never create wrapper functions that just call another function with the same signature.
  • Route all review file writes through saveCritJSON(). Never write directly.
  • Before implementing logic inline, search for existing helper functions that do the same thing.
  • After replacing a function with a new implementation, delete the old function AND its tests in the same PR.

Git Operations

  • When determining file status, always diff against baseRef consistently. Don't mix git status --porcelain (working tree) with git diff --name-status (branch diff).

Daemon/Server

  • When checking if a service is alive, validate the response body, not just HTTP status.
  • Error paths in CLI subcommands must exit with non-zero status (os.Exit(1)).

Testing

  • Use table-driven tests instead of separate test functions for parameter variations.
  • When adding a new API endpoint, add tests for: happy path, error cases, not-found, method-not-allowed.
Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 32 lines · 0 tokens per session scan A 3cce88882bdf

Subscribe to this mod's changes

go is a cursor rule published in the GitHub repository tomasz-tomczyk/crit (979 stars, last pushed 3d ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 389 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.