go-defensive-coding

go-defensive-coding is a skill for Claude Code from eduardo-sl/go-agent-skills. It costs 163 tokens per session (2,682 once invoked), scanned A, original, MIT.

Guidance for making Go code safer against panics, corrupted data, and less obvious runtime bugs. It covers nil values, shared slices, number conversion, floating-point comparisons, deferred cleanup, and defensive copies.

In plain words
What is it for?
Use it when hardening new or changed Go code, reviewing nil handling and API boundaries, checking numeric conversions, and investigating subtle runtime failures.
Why use it?
These mistakes can compile and pass ordinary tests while causing crashes or incorrect results in production.

Skill for Claude Code

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

Part of the go-agent-skills plugin — 33 skills shipped together

Good fit Use it when hardening new or changed Go code, reviewing nil handling and API boundaries, checking numeric conversions, and investigating subtle runtime failures.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/eduardo-sl/go-agent-skills/go-defensive-coding
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.

Any agent
npx skills add eduardo-sl/go-agent-skills --skill go-defensive-coding
Clone the repo
git clone --depth 1 https://github.com/eduardo-sl/go-agent-skills

Made for: Claude Code.

Or install go-agent-skills, the plugin that ships this one along with the rest of its 33 skills.

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-coding

README.md
[![agentmods](https://agentmods.dev/badge/skills/eduardo-sl/go-agent-skills/go-defensive-coding/github.svg)](https://agentmods.dev/skills/eduardo-sl/go-agent-skills/go-defensive-coding)
Your own site
<a href="https://agentmods.dev/skills/eduardo-sl/go-agent-skills/go-defensive-coding"><img src="https://agentmods.dev/badge/skills/eduardo-sl/go-agent-skills/go-defensive-coding/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-coding

Your own site · 80×15
<a href="https://agentmods.dev/skills/eduardo-sl/go-agent-skills/go-defensive-coding"><img src="https://agentmods.dev/badge/skills/eduardo-sl/go-agent-skills/go-defensive-coding.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 163 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,682 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. Third-party audits
  • NVIDIA SkillSpector pass 7 Sept 2026
How audits are shown
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.00163 $0.02682
Opus 5 $0.00081 $0.01341
Sonnet 5 $0.00033 $0.00536
Haiku 4.5 $0.00016 $0.00268

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

Security

Grade A, and why

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

skills/(safety)/go-defensive-coding/SKILL.md · 320 lines

How it starts

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

Go Defensive Coding

Go has no exceptions and no null-safety in the type system. Every trap below compiles cleanly, passes review, and fails in production.

Detailed reference material, loaded on demand:

  • references/nil-and-aliasing.md — the full typed-nil rules, slice aliasing scenarios, and memory retention.
  • references/numeric-safety.md — conversion range checks, overflow detection, float and time comparison.

Read a reference file only when the section below is not enough.

Operating Modes

  • Harden — you are writing or changing code. Apply every rule as you go.
  • Review — you are auditing existing code. Report findings with severity (🔴 panic or corruption, 🟡 latent bug, 🟢 style) and cite file:line.

1. The Typed-Nil Interface Trap

A non-nil interface can hold a nil pointer. This is the single most common source of "impossible" nil checks in Go.

type NotFoundError struct{ ID string }

func (e *NotFoundError) Error() string { return "not found: " + e.ID }

// ❌ Bad — returns a non-nil error even on success
func find(id string) error {
    var err *NotFoundError // typed nil
    if id == "" {
        err = &NotFoundError{ID: id}
    }
    return err // interface is (type=*NotFoundError, value=nil) — NOT nil
}

// ✅ Good — return the untyped nil literal
func find(id string) error {
    if id == "" {
        return &NotFoundError{ID: id}
    }
    return nil
}

Rules:

  • Never declare a concrete error/pointer variable and return it as an interface. Return nil explicitly on the success path.
  • Never store a possibly-nil concrete pointer in an error, io.Reader, or any interface-typed struct field.
  • go vet's nilness analyzer catches some of these. It does not catch all.

2. Nil Map, Slice, and Channel Behaviour

Memorise this table — half of these are safe and half panic or hang.

Operation nil map nil slice nil channel
Read / receive zero value index panics blocks forever
Write / send panics append works blocks forever
len / cap 0 0 0
range zero iterations zero iterations blocks forever
close n/a n/a panics

Read the full file on GitHub · 320 lines

Files

What ships with it

2 files beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

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. 10d ago First seen · 320 lines · 163 tokens per session scan A 079704d3576c

Subscribe to this mod's changes

go-defensive-coding is a skill published in the GitHub repository eduardo-sl/go-agent-skills (71 stars, last pushed 23d ago), licensed MIT. It adds 163 tokens to every session and 2,682 once invoked, about $0.0008 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-30.

Related

Other skills, from other repositories

go-linters

Add and validate custom Go analysis linters in gh-aw.

github/gh-aw · 17 tokens

printing-press-polish

Polish a generated CLI to pass verification and become publish-ready. Runs diagnostics (dogfood, verify, scorecard, go vet, gosec), automatically fixes all issues (verify failures, static-analysis findings, dead code, descriptions, README, MCP tool quality), reports the before/after delta, and offers to publish. Use…

mvanhorn/cli-printing-press · 125 tokens

stack-trace-go-probe

Internal helper for meta-stack-trace-investigator. Use when a Go panic or stack trace needs Go-specific nil/error checks, go test reproducer guidance, and patch targets.

opensquilla/opensquilla · 42 tokens

golang-troubleshooting

Troubleshoot Golang programs systematically - find and fix the root cause. Use when encountering bugs, crashes, deadlocks, races, or unexpected behavior in Go code. Covers debugging methodology, common Go pitfalls, test-driven debugging, pprof setup and capture, Delve, race detection, GODEBUG tracing, and production…

samber/cc-skills-golang · 175 tokens

golang-error-handling

Idiomatic Golang error handling — creation, wrapping with %w, errors.Is/As, errors.Join, custom error types, sentinel errors, panic/recover, the single handling rule, structured logging with slog, HTTP request logging middleware, and samber/oops for production errors. Built to make logs usable at scale with log…

samber/cc-skills-golang · 144 tokens

sentry-go-sdk

Full Sentry SDK setup for Go. Use when asked to "add Sentry to Go", "install sentry-go", "setup Sentry in Go", or configure error monitoring, tracing, logging, metrics, or crons for Go applications. Supports net/http, Gin, Echo, Fiber, FastHTTP, Iris, Negroni, and gRPC.

getsentry/sentry-for-ai · 78 tokens