Defensive Golang coding to prevent panics, silent data corruption, and subtle runtime bugs. Use when encountering nil panics, append aliasing, map concurrent access, float comparison pitfalls, or zero-value design questions. Also use when reviewing code for nil-safety, numeric conversion overflow, resource lifecycle issues (defer in loops), or defensive copying of slices and maps.
The `golang-safety` skill is designed to help developers write defensive and reliable Go code, preventing common runtime errors such as panics, silent data corruption, and subtle logic bugs. It focuses on areas where Go's language semantics can lead to unexpected behavior, including nil pointer handling, slice and map aliasing, concurrent map access, float comparison issues, and zero-value design pitfalls. By emphasizing defensive coding practices, this skill aims to reduce crashes and unintended side effects in normal, non-adversarial code. It complements security-focused approaches by addressing mistakes programmers may make themselves rather than attacks from outside sources.
Key features of the skill include guidance on using generics safely, performing type assertions without risk, understanding the nuances of nil interfaces, ensuring safe slice and map operations, returning defensive copies from exported functions, and correctly managing resource lifecycles using `defer` and `sync.Once`. It also provides best practices for integer and float arithmetic, designing useful zero values, and handling concurrency safely. The skill is compatible with Golang projects and AI coding agents like Claude Code, helping developers catch common pitfalls before they become runtime issues.
This skill is particularly useful for Go engineers, code reviewers, and anyone maintaining production-grade Go code who wants to enforce safety and correctness. It is ideal when encountering nil-related panics, subtle bugs in slice or map handling, numeric conversion overflow risks, or challenges in designing zero-value-safe data structures. Users seeking to improve code robustness and prevent latent crashes in their Go applications will find this skill valuable, especially when reviewing or refactoring code for safety and reliability.
Invoke the skill when writing or reviewing Go code to check for nil-safety, slice/map aliasing, numeric conversion issues, and other common runtime pitfalls. Follow the provided best practices to prevent crashes and data corruption.
The skill is designed for use with Claude Code or similar AI coding agents, and it is intended for Golang projects. It requires the Go binary to be available.
The skill assumes familiarity with Go and its runtime behaviors. It does not handle adversarial security issues and focuses on programmer errors. It also requires that Go is installed and available in the environment.
The skill provides guidance, best practices, and examples, but it does not inherently modify code. It can be used alongside tools that read, edit, or lint Go code.
Yes, the skill includes guidance on safe initialization with `sync.Once` and handling concurrent map access, helping prevent race conditions and data corruption.
Quick Setup:
.claude/skills/Repository
samber/cc-skills-golang