go-defensive

go-defensive is a skill for Claude Code from muratmirgun/gophers. It costs 75 tokens per session (1,743 once invoked), scanned A, original, MIT.

A set of guidelines for making Go code safer at the points where data, files, time, and dependencies enter or leave a package.

In plain words
What is it for?
Use it when reviewing or hardening Go APIs, cleanup code, time-based logic, random-value generation, and package boundaries.
Why use it?
It helps prevent accidental changes to shared data, leaked resources, invalid zero values, unsafe randomness, and panics that callers cannot handle.

Skill for Claude Code

Written for Claude Code: allowed-tools in frontmatter. Also seen: mentions Claude Code; built for openclaw.

Needs its repository: it reads a path above its own folder, which exists only inside the repository. The line is Read [references/boundary-copying.md](../../../skills/go-defensive/references/boundary-copying.md) when deciding which boundaries actually need copies (and when.

Part of the gophers plugin — 26 skills, 4 agents shipped together

Good fit Use it when reviewing or hardening Go APIs, cleanup code, time-based logic, random-value generation, and package boundaries.

Compare 6 skills from other repositories ↓
Install

Getting it into your agent

It runs from inside its repository, so the clone comes first — what it calls does not travel with the file alone.

Clone the repo
git clone --depth 1 https://github.com/muratmirgun/gophers
agentmods
npx agentmods add skills/muratmirgun/gophers/go-defensive

Made for: Claude Code.

Or install gophers, the plugin that ships this one along with the rest of its 26 skills, 4 agents.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for go-defensive

README.md
[![agentmods](https://agentmods.dev/badge/skills/muratmirgun/gophers/go-defensive/github.svg)](https://agentmods.dev/skills/muratmirgun/gophers/go-defensive)
Your own site
<a href="https://agentmods.dev/skills/muratmirgun/gophers/go-defensive"><img src="https://agentmods.dev/badge/skills/muratmirgun/gophers/go-defensive/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for go-defensive

Your own site · 80×15
<a href="https://agentmods.dev/skills/muratmirgun/gophers/go-defensive"><img src="https://agentmods.dev/badge/skills/muratmirgun/gophers/go-defensive.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 75 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,743 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
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.1 $0.00075 $0.01743
Opus 5 $0.00037 $0.00872
Sonnet 5 $0.00015 $0.00349
Haiku 4.5 $0.00007 $0.00174

Measured 8d ago against content hash aa6d42375653, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-08, from the pricing page.

Security

Grade A, and why

go-defensive 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 8d 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.

.claude-plugin/skills/go-defensive/SKILL.md · 204 lines

How it starts

The opening of the file, as written. The whole thing — 204 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Go Defensive Programming

Hardening Go code is not paranoia — it is the discipline of making your boundaries honest. Copy what crosses them, clean up what you opened, model time and randomness honestly, and never let a panic escape a package.

Core Rules

  1. Copy slices and maps at API boundaries. They are reference types — leaking the backing array leaks mutation.
  2. defer the cleanup right after the acquire. f, err := os.Open(...); defer f.Close().
  3. Verify interface compliance at compile time: var _ I = (*T)(nil).
  4. Model time and durations with time.Time and time.Duration, never raw ints.
  5. Inject now func() time.Time instead of calling time.Now() directly in production code.
  6. Enums start at iota + 1 so the zero value is invalid.
  7. crypto/rand for secrets, never math/rand.
  8. Panics never cross package boundaries. Convert to errors at the edge.
  9. Avoid mutable package-level state. Inject dependencies instead.

Boundary Hardening Checklist

When you touch an exported function or method, walk this list in order:

# Check
1 Return errors, don't panic across boundaries
2 Copy slices/maps you'll retain
3 Copy slices/maps you'll return if internal state aliases them
4 defer Close / Unlock / cancel right after the acquire
5 Compile-time interface satisfaction check
6 time.Time / time.Duration types, injected clock
7 Enum zero = invalid (iota + 1)
8 crypto/rand for any secret material

Copy at API Boundaries

// Receiving: copy a slice we'll retain
func (d *Driver) SetTrips(trips []Trip) {
    d.trips = make([]Trip, len(trips))
    copy(d.trips, trips)
}

// Returning: copy a map so callers can't mutate our state
func (s *Stats) Snapshot() map[string]int {
    out := make(map[string]int, len(s.counters))
    for k, v := range s.counters {
        out[k] = v
    }
    return out
}

Read references/boundary-copying.md when deciding which boundaries actually need copies (and when copying is wasted work).

Read the full file on GitHub · 204 lines

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. 8d ago First seen · 204 lines · 75 tokens per session scan A aa6d42375653

Subscribe to this mod's changes

go-defensive is a skill published in the GitHub repository muratmirgun/gophers (8 stars, last pushed 28d ago), licensed MIT. It adds 75 tokens to every session and 1,743 once invoked, about $0.0004 per session on Opus 5. 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-31.

Related

Other skills, from other repositories

go

Use when writing Go services, CLIs, or libraries. Covers idiomatic error wrapping, goroutine and context discipline, interface design, table-driven tests, and the race detector.

nimadorostkar/Claude-Skills-collection · 38 tokens

golang-pro

Implements concurrent Go patterns using goroutines and channels, designs and builds microservices with gRPC or REST, optimizes Go application performance with pprof, and enforces idiomatic Go with generics, interfaces, and robust error handling. Use when building Go applications requiring concurrent programming…

Jeffallan/claude-skills · 95 tokens

developing-genkit-go

Develop AI-powered applications using Genkit in Go. Use when the user asks to build AI features, agents, flows, or tools in Go using Genkit, or when working with Genkit Go code involving generation, prompts, streaming, tool calling, or model providers.

google/skills · 60 tokens

programming

Applies strict, modern language practice (typed errors, exhaustive match, TDD) for Python, Rust, TypeScript, and Go. Use for work on .py, .rs, .ts, or .go files.

code-yeongyu/oh-my-openagent · 49 tokens

authoring-go-sdk-tasks

Writes Airflow task logic in Go using the Airflow Go SDK. Use when the user wants to implement Airflow tasks in Go, asks about BundleProvider/RegisterDags, the bundlev1 Registry/Dag interfaces, registering Go tasks (AddTask/AddTaskWithName), dependency injection by parameter type (context.Context, sdk.TIRunContext…

astronomer/agents · 165 tokens

deploying-go-sdk-bundles

Builds, packs, and deploys compiled Airflow Go SDK bundles so the ExecutableCoordinator can run them. Use when the user wants to compile a Go task bundle, asks about go build, go tool airflow-go-pack, the AFBNDL01 self-contained executable bundle, packing or inspecting a bundle, placing it under executablesroot…

astronomer/agents · 146 tokens