From golang-skills
Guides proper Go context.Context usage including function signatures, cancellation propagation, timeouts, request-scoped data, and common patterns.
How this skill is triggered — by the user, by Claude, or both
Slash command
/golang-skills:go-contextThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
> Compatibility: `context` has been in the standard library since Go 1.7.
Compatibility:
contexthas been in the standard library since Go 1.7.
references/PATTERNS.md - Read when deriving contexts, checking cancellation, handling HTTP request contexts, or using typed context-value keys.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:
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.
ctx.Err() cancellation errorsnpx claudepluginhub yukiteruamano/golang-skills2plugins reuse this skill
First indexed Jun 20, 2026
Guides proper Go context.Context usage including function signatures, cancellation propagation, timeouts, request-scoped data, and common patterns.
Guides idiomatic context.Context usage in Go: propagation through API boundaries, cancellation, timeouts, request-scoped values, and background work with WithoutCancel. Helps debug leaked contexts and choose between Background/TODO/WithoutCancel.
Correct usage of context.Context in Go: propagation, cancellation, timeouts, deadlines, values, and common anti-patterns. Use when: "context usage", "context.Context", "context cancellation", "timeout", "context.WithTimeout", "context.WithCancel", "context values", "context propagation". Do NOT use for: concurrency patterns beyond context (use go-concurrency-review), HTTP middleware context (use go-api-design), or error handling (use go-error-handling).