Tooluck logoTooluck
SKILL.md

golang-safety

Agent skill fromsamber/cc-skills-golang

Defensive Golang coding against accidental bugs — nil panics, typed-nil interfaces, `append` backing-array aliasing, silent int64-to-int32 truncation, float `==` comparison, `defer` inside loops, defensive copies of slices and maps, and usable zero values. Use when a Go program panics on a nil map write or nil pointer dereference, when reviewing code for nil-safety, numeric conversion overflow, or resource lifecycle, or when designing a type whose zero value must be safe. Not for designing concurrent access with goroutines, channels, or sync primitives (→ See `samber/cc-skills-golang@golang-concurrency` skill), not for exploitable vulnerabilities such as injection, weak crypto, or leaked secrets (→ See `samber/cc-skills-golang@golang-security` skill), and not for debugging an already-failing program (→ See `samber/cc-skills-golang@golang-troubleshooting` skill).

How to install golang-safety

install golang-safety
# install the cc-skills-golang pack with the skills CLI
npx skills add samber/cc-skills-golang

# or add only this skill to Claude Code: copy the folder

skills/golang-safety/

# into

~/.claude/skills/golang-safety/ (all projects)

.claude/skills/golang-safety/ (one project)

skills/golang-safety/SKILL.md

MITFull file
1**Persona:** You are a defensive Go engineer. You treat every untested assumption about nil, capacity, and numeric range as a latent crash waiting to happen.
2
3# Go Safety: Correctness & Defensive Coding
4
5Prevents programmer mistakes — bugs, panics, and silent data corruption in normal (non-adversarial) code. Security handles attackers; safety handles ourselves.
6
7## Best Practices Summary
8
91. **Prefer generics over `any`** when the type set is known — compiler catches mismatches instead of runtime panics
102. **Always use safe type assertions** — for normal interfaces use comma-ok (`v, ok := x.(T)`); for reflection in Go 1.25+ prefer `reflect.TypeAssert[T](value)` over `value.Interface().(T)`.
113. **Typed nil pointer in an interface is not `== nil`** — the type descriptor makes it non-nil
124. **Writing to a nil map panics** — always initialize before use
135. **`append` may reuse the backing array** — both slices share memory if capacity allows, silently corrupting each other
146. **Return defensive copies** from exported functions — otherwise callers mutate your internals
157. **`defer` runs at function exit, not loop iteration** — extract loop body to a function
168. **Integer conversions truncate silently** — `int64` to `int32` wraps without error
179. **Float arithmetic is not exact** — use epsilon comparison or `math/big`
1810. **Design useful zero values** — nil map fields panic on first write; use lazy init
19…

Excerpt shown under the repository's MIT license.

More skills in cc-skills-golang

Keep exploring

Similar skill repositories

thedotmack /

claude-mem
116k

Persistent Context Across Sessions for Every Agent – Captures everything your agent does during sessions, compresses it with AI, and injects relevant context back into future sessions. Works with Claude Code, OpenClaw, Codex, Gemini, Hermes, Copilot, OpenCode + More

CCCXGHGM+135 skills

Newsletter

Join the Community

Subscribe to our newsletter for the latest news and updates