Skip to content
Skill

Go defensive coding

Guides Go code away from nil-interface, slice-aliasing and overflow crashes

Go defensive coding is an open-source agent skill for developer tools. It is available on Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, Windsurf and Goose.

Scripts
None
Platforms
Claude Code, Codex, Cursor
GitHub stars
90
Last commit
License
MIT
Listing updated

Similar skills

About Go defensive coding

This skill gives the agent a checklist of Go pitfalls that compile and pass review but fail at runtime: typed-nil interfaces, nil map and slice behaviour, slice aliasing, unchecked numeric narrowing, float and time comparison, defer inside loops, and copying at package boundaries. It works in two modes, hardening code while writing it or reviewing existing code and reporting findings by severity with file and line references.

The skill points to three reference files that the agent reads only when the main rules are not enough, covering nil and aliasing scenarios, numeric safety, and copy and lifecycle rules such as copylocks and noCopy markers. It also recommends running go vet, golangci-lint, staticcheck, gosec and go test with the race detector, and lists a final verification checklist to run through.

It expects a Go project with the Go toolchain installed. golangci-lint and gosec are optional and used only to enforce the rules. Bash access is limited to go, gofmt, golangci-lint and gosec commands.

When your agent uses it

Prevent panics, silent corruption, and subtle runtime bugs in Go: typed-nil interfaces, slice aliasing, integer overflow on conversion, float comparison, defer in loops, defensive copying at API boundaries, and zero-value design. Use when hardening code against crashes, reviewing for nil-safety, converting between numeric types, or deciding what to copy at a package boundary. Trigger examples: "nil pointer panic", "why is my error not nil", "slice aliasing", "integer overflow", "compare floats", "defer in a loop", "defensive copy", "make this crash-proof". Not for: data races and goroutine lifecycle (go-concurrency-review), injection and auth (go-security-audit), a panic that already happened (go-troubleshooting).

From the skill's SKILL.md. Your agent reads this description to decide when to load the skill.

What it can access

From a static check of its 4 files (22 KB) on GitHub on 3 December 2026. Nothing was run. Read the files before you install a skill: it can tell your agent to run anything its tools allow.

Check another skill before you install it.

Install

Download the skill folder from https://github.com/eduardo-sl/go-agent-skills and copy it into your agent's skills folder.

What it does

Typed-nil interface checks
Explains how a non-nil interface can wrap a nil pointer and how to return a true nil on success.
Slice aliasing guidance
Shows how append can overwrite shared backing arrays and how full slice expressions cap the view.
Defensive copying rules
Covers cloning slices and maps passed in or returned from a struct at API boundaries.
Numeric conversion safety
Describes range checks before narrowing integers and avoiding float equality comparisons.
Resource and defer review
Flags defer used inside loops and unchecked errors from deferred Close calls.
Lint and vet enforcement
Lists go vet, golangci-lint, staticcheck, gosec and race-detector commands to verify changes.

Good for

  • Check this Go service for nil pointer panics before release
  • Fix a bug where an error value is never nil on success
  • Stop append from overwriting data shared between slices
  • Add range checks before converting int64 values to int32
  • Review a Go package for defensive copies at its public API
  • Move defer Close calls out of a loop that opens many files

Go defensive coding FAQ

What does Go defensive coding need to run?

It requires the Go toolchain. golangci-lint and gosec are optional and used only for enforcing the rules.

Which problems does Go defensive coding cover?

Typed-nil interfaces, nil map and slice behaviour, slice aliasing, integer overflow on conversion, float and time comparison, defer in loops, defensive copying, and zero-value design.

What is out of scope?

Data races and goroutine lifecycle, injection and auth issues, and a panic that has already happened. The skill names other skills for those cases.

Does Go defensive coding change files on its own?

It can edit and write files when hardening code, and it reports findings with severity and file:line references when reviewing.

Does Go defensive coding run scripts?

No. It is instructions only, with no scripts. This comes from a static check of the files on GitHub; nothing was run. Read the files before you install it.

Which AI agents can use Go defensive coding?

Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, Windsurf and Goose. Each reads skills in the SKILL.md format from its own folder; the install steps on this page list them.

What are the best alternatives to Go defensive coding?

The closest alternatives to Go defensive coding are Go data structures, Go coding standards, Go code review, Go interface design and Go error handling.

Where this comes from

  • Description: from the skill's own SKILL.md.

More from eduardo-sl/go-agent-skills

  1. Guides Go agents in designing HTTP REST APIs, handlers, middleware and shutdown

    • Open source
    • 90 GitHub stars
    • Developer tools
  2. Reviews Go project structure, dependency direction and module boundaries

    • Open source
    • 90 GitHub stars
    • Developer tools
  3. Guides an AI agent to build Go command-line tools with clean flags, streams and exit codes

    • Open source
    • 90 GitHub stars
    • Developer tools
  4. Guides Go code toward constructor injection, explicit wiring and no global state

    • Open source
    • 90 GitHub stars
    • Developer tools
  5. Guides Go code toward idiomatic design patterns like functional options and factories

    • Open source
    • 90 GitHub stars
    • Developer tools
  6. Guides building Go GraphQL servers with gqlgen, covering N+1 batching and query limits

    • Open source
    • 90 GitHub stars
    • Developer tools