Reviews and implements safe concurrency patterns in Go: goroutines, channels, sync primitives, context propagation, and goroutine lifecycle management. Use when writing concurrent code, reviewing async patterns, checking thread safety, debugging race conditions, or designing producer/consumer pipelines.
Ships in go-agent-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Concurrency in Go is powerful and deceptively easy to get wrong. These patterns prevent goroutine leaks, data races, and deadlocks.
Detailed reference material, loaded on demand:
references/channels.md — sizing, signalling, producer shutdown.references/mutex-and-atomics.md — mutex placement, lock scope, atomics,
sync.Once, RWMutex pitfalls, sync.Map, sync.Pool, singleflight.references/goroutine-patterns.md — panic recovery at goroutine
boundaries, pipelines, bounded fan-out, timers.Read a reference file only when the section below is not enough.
Pick the mode that matches the request before starting:
go statements and shared state.-race report, deadlock). Start from "Auditing Large Codebases"
and the Race Detection section to localize it. On Go 1.27+ read the
goroutineleak profile first: it lists goroutines blocked on something
nothing can ever unblock. The go-troubleshooting skill owns the procedure.For a full concurrency audit, run these independent passes rather than one linear read:
go statement
(grep -rn "go func\|go [a-zA-Z]" --include="*.go") and verify each
has a termination path (context, closed channel, WaitGroup).context.Context.If your environment supports delegating work to parallel sub-agents or
tasks, assign each pass to one; otherwise run them in order. Findings
must cite file.go:line. Always finish with go test -race ./....
| Need | Use | Why |
|---|---|---|
| Hand data from one goroutine to another | Channel | The send transfers ownership |
| Guard fields of a shared struct | sync.Mutex / RWMutex | Short critical sections, explicit owner |
| A counter or flag | atomic.Int64, atomic.Bool | No lock, no torn reads |
| Compute once, read many | sync.OnceValue | Exactly once, even under contention |
| Collapse concurrent identical calls | singleflight.Group | One backend call per key, not N |
| Reuse short-lived buffers on a hot path | sync.Pool | Fewer allocations — only after a profile |
| Waiting for goroutines | Use |
|---|---|
| Results don't fail | sync.WaitGroup (wg.Go, Go 1.25+) |
| First error matters | errgroup.Group |
| First error cancels the rest | errgroup.WithContext |
| Cap how many run at once | errgroup + SetLimit(n) — not a hand-rolled pool |
EVERY goroutine MUST have a clear termination path. No fire-and-forget.
errgroup for coordinated goroutines:g, ctx := errgroup.WithContext(ctx)
g.Go(func() error {
return fetchUsers(ctx)
})
g.Go(func() error {
return fetchOrders(ctx)
})
if err := g.Wait(); err != nil {
return fmt.Errorf("fetch data: %w", err)
}
func (w *Worker) Run(ctx context.Context) error {
for {
select {
case <-ctx.Done():
return ctx.Err()
case job := <-w.jobs:
if err := w.process(job); err != nil {
w.logger.Error("process job", slog.Any("error", err))
}
}
}
}
// ✅ Good — caller controls lifecycle
go worker.Run(ctx)
// ❌ Bad — function secretly starts goroutine
func NewWorker() *Worker {
w := &Worker{}
go w.run() // hidden goroutine — caller has no control
return w
}
A panic in any goroutine terminates the whole process. The recover in
HTTP middleware covers the request goroutine only, not goroutines it
starts. Workers and background tasks that run input-dependent or
third-party code recover in their own deferred function, log the stack,
and turn the panic into an error. Don't recover to hide bugs in code you
own — recover where a crash would take unrelated work down with it.
Example: references/goroutine-patterns.md.
Size is one or none. Unbuffered is a synchronization point; buffer 1 is a
handoff. Any larger buffer needs a comment justifying the number — an
arbitrary 100 is a bug waiting for the day production is slower than
staging.
Signal channels carry struct{}, and close(done) broadcasts to every
receiver at once.
The producer owns the channel and is the only one that closes it, with
defer close(ch) in the producing goroutine. Every send sits in a select
against ctx.Done(), or a consumer that walks away leaks the producer.
Pipelines: each stage closes its own output; fan-out is bounded with
errgroup.SetLimit; a single-goroutine chain is an iter.Seq, not
channels.
Examples in references/channels.md and references/goroutine-patterns.md.
sync.Mutex and sync.RWMutex are ready to use. A
*sync.Mutex field is always wrong.c2 := *c1): the copy carries the
original's lock state. go vet catches most of these; trust it.sync/atomic types for counters and flags rather than a mutex around
an int64.sync.Once for lazy initialization that must happen exactly once.RWMutex cannot be upgraded or read-locked recursively; sync.Map
fits two workloads only; sync.Pool objects must be reset and size-capped;
singleflight runs on the first caller's context — detach it. Details in
references/mutex-and-atomics.md.Examples in references/mutex-and-atomics.md.
Context is always the first parameter, never a struct field, and every
blocking operation selects on ctx.Done():
// ✅ Good
select {
case result := <-ch:
return result, nil
case <-ctx.Done():
return nil, ctx.Err()
}
// ❌ Bad — blocks forever if the context is cancelled
result := <-ch
Derive a child context with its own timeout for each external call and
defer cancel() immediately. Full rules in the go-context skill.
// ❌ Bad — mutable global, not safe for concurrent access
var db *sql.DB
// ✅ Good — pass as dependency
type Server struct {
db *sql.DB
}
ALWAYS run tests with race detector during CI:
go test -race ./...
This is non-negotiable. A test suite that passes without -race proves nothing
about concurrent correctness.
context.Background() used where parent context was availableselect without ctx.Done() case in blocking operationtime.Sleep used for synchronization instead of proper signalinginit() or constructor without lifecycle controlrecoverWhat SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
35 skills in this plugin
/git-commitStructured git commit messages following Conventional Commits format for Go projects. Generates well-scoped, atomic commits with clear descriptions. Use when committing changes, writing commit messages, preparing PRs, or reviewing commit history quality. Trigger examples: "commit these changes", "create commit", "commit message", "prepare PR", "squash commits". Not for: code review (go-code-review), changelog generation.
/go-api-designHTTP/REST API design for Go services: handlers, ServeMux routing, middleware, request validation, pagination, idempotency, health checks, error responses, and graceful shutdown. Use when designing APIs, writing HTTP handlers, implementing middleware, or structuring REST endpoints. Trigger examples: "design API", "REST endpoints", "HTTP handler", "middleware pattern", "graceful shutdown", "API versioning". Not for: gRPC services (go-grpc), spec-first OpenAPI work (go-openapi), general architecture (go-architecture-review), concurrency in handlers (go-concurrency-review).
/go-architecture-reviewReview Go project architecture: package structure, dependency direction, layering, separation of concerns, domain modeling, and module boundaries. Use when reviewing architecture, designing package layout, evaluating dependency graphs, or refactoring monoliths into modules. Trigger examples: "review architecture", "package structure", "project layout", "dependency direction", "clean architecture Go", "module boundaries". Not for: code-level style (go-coding-standards), endpoint design (go-api-design).
/go-agent-skills:go-concurrency-reviewfrom go-agent-skills
npx claudepluginhub eduardo-sl/go-agent-skills --plugin go-agent-skillsOther plugins' skills for the same job