go-code-review
Use when reviewing Go code or checking code against community style standards. Also use proactively before submitting a Go PR or…
Use when working with context.Context in Go — placement in signatures, propagating cancellation and deadlines, and storing values in context vs parameters. Also use when cancelling long-running operations, setting timeouts, or passing request-scoped data, even if they don't
$ npx -y skills add cxuu/golang-skills --skill go-context --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
/go-contextContext preview
The summary Claude sees to decide when to auto-load this skill.
Use when working with context.Context in Go — placement in signatures, propagating cancellation and deadlines, and storing values in context vs parameters. Also use when cancelling long-running operations, setting timeouts, or passing request-scoped data, even if they don't
name: go-context description: Use when working with context.Context in Go — placement in signatures, propagating cancellation and deadlines, and storing values in context vs parameters. Also use when cancelling long-running operations, setting timeouts, or passing request-scoped data, even if they don't mention context.Context directly. Does not cover goroutine lifecycle or sync primitives (see go-concurrency).
> Compatibility: `context` has been in the standard library since Go 1.7.
Functions that use a Context should accept it as their **first parameter**:
func F(ctx context.Context, /* other arguments */) error func ProcessRequest(ctx context.Context, req *Request) (*Response, error)
This is a strong convention in Go that makes context flow visible and consistent across codebases.
---
Do not add a Context member to a struct type. Instead, pass `ctx` as a parameter to each method that needs it:
// Bad: Context stored in struct
type Worker struct {
ctx context.Context // Don't do this
}
// Good: Context passed to methods
type Worker struct{ /* ... */ }
func (w *Worker) Process(ctx context.Context) error {
// Context explicitly passed — lifetime clear
}**Exception**: Methods whose signature must match an interface in the standard library or a third-party library may need to work around this.
---
Do not create custom Context types or use interfaces other than `context.Context` in function signatures:
// Bad: Custom context type
type MyContext interface {
context.Context
GetUserID() string
}
// Good: Use standard context.Context with value extraction
func Process(ctx context.Context) error {
userID := GetUserID(ctx)
}---
Consider these options in order of preference:
1. **Function parameters** — most explicit and type-safe 2. **Receiver** — for data that belongs to the type 3. **Globals** — for truly global configuration (use sparingly) 4. **Context value** — only for request-scoped data
Context values are appropriate for:
Context values are **not** appropriate for:
---
Always `defer cancel()` immediately after creating a derived context:
ctx, cancel := context.WithTimeout(ctx, 5*time.Second) defer cancel()
select {
case <-ctx.Done():
return ctx.Err()
default:
// Do work
}Contexts are immutable — it's safe to pass the same `ctx` to multiple concurrent calls that share the same deadline and cancellation signal.
---
AI Agent Skills for writing idiomatic, production-quality Go code. 20 modular skills teach AI coding assistants Go best practices derived from: Google Go Style Guide Effective Go Uber Go Style Guide Go Wiki CodeReviewComments Skills are tuned following
Use when reviewing Go code or checking code against community style standards. Also use proactively before submitting a Go PR or…
Use when writing concurrent Go code — goroutines, channels, mutexes, or thread-safety guarantees. Also use when parallelizing…
Use when writing conditionals, loops, or switch statements in Go — including if with initialization, early returns, for loop…
Use when working with Go slices, maps, or arrays — choosing between new and make, using append, declaring empty slices (nil vs…
Use when declaring or initializing Go variables, constants, structs, or maps — including var vs :=, reducing scope with if-init,…
Use when hardening Go code at API boundaries — copying slices/maps, verifying interface compliance, using defer for cleanup,…