go-concurrency
Skill1 starsChanged 56 days agoMITView on GitHub
Always use this skill when working with goroutines, channels, context, sync primitives, or concurrent Go code. Triggers include: "goroutine leak", "channel deadlock", "context cancellation", "how do I use WaitGroup", "fan-out fan-in", "worker pool", "data race", "select statement", "buffered channel", "sync.Mutex", "sync.Once", "context.WithTimeout", "goroutine exits", "channel close", "race condition", "concurrent map write". Read this skill before advising on any Go concurrency question.
7 other projects use a version of this.
Adopted by
Most recently taken up by
- inference-gateway/skillstheir own version, first seen Oct 1, 2026
- Dankosik/golang-backend-skillstheir own version, first seen Sep 8, 2026
- CasLubbers/code-design-skillstheir own version, first seen Aug 25, 2026
- muratmirgun/gopherstheir own version, first seen Aug 11, 2026
- cxuu/golang-skillstheir own version, first seen Jun 20, 2026
- saisudhir14/claude-skillstheir own version, first seen Mar 25, 2026
Used with
Projects with it also use go-performance, go-interfaces and 3 more.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
saisudhir14Skillgo-performance
Use when writing, reviewing, or optimizing Go code for performance. Covers string operations, memory allocation, preallocating slices and maps, strings.Builder, strconv, container-aware GOMAXPROCS, and runtime considerations for Go 1.25.
Also in 4 projects that use this
cxuuSkillgo-interfaces
Use when defining or implementing Go interfaces, designing abstractions, creating mockable boundaries for testing, or composing types through embedding. Also use when deciding whether to accept an interface or return a concrete type, or using type assertions or type switches, even if the user doesn't explicitly mention interfaces. Does not cover generics-based polymorphism (see go-generics).
Also in 3 projects that use this
saisudhir14Skillgo-linting
Use when setting up linting, configuring golangci-lint, or fixing linter warnings in Go projects. Provides recommended linter sets, golangci-lint configuration, CI integration, and Makefile targets.
Also in 3 projects that use this
xxxryanSkillgo-code-review
Perform a senior Go code review on a diff or files, focusing on correctness, idiomatic Go, error handling, maintainability, and performance. Use when the user asks for review, refactor feedback, or PR comments for Go services.
Also in 3 projects that use this
- +1 more from saisudhir14
Other versions7 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 7
- cxuu/golang-skills★ 165same name
- wpank/ai★ 11same name
- muratmirgun/gophers★ 9same name
- saisudhir14/claude-skills★ 9same name
- inference-gateway/skills★ 3same name
- CasLubbers/code-design-skills★ 2same name
- Dankosik/golang-backend-skills★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository25 other files it gives its agents.
- api-designSkill
- arch-reviewSkill
- db-reviewSkill
- debugSkill
- dotnet-asyncSkill
- dotnet-opsSkill
- dotnet-testingSkill
- dotnet-typesSkill
- go-opsSkill
- go-testingSkill
- go-typesSkill
- incidentSkill
- node-asyncSkill
- node-opsSkill
- perfSkill
- pr-prepSkill
- py-asyncSkill
- py-opsSkill
- py-testingSkill
- py-typesSkill
- refactorSkill
- securitySkill
- test-genSkill
- ts-testingSkill
- ts-typesSkill
The file
We split this skill into the rules it gives an agent
10 rules. 0 are common, 7 are distinctive, and 3 are very specific to this project.
0
Common
Most of the 6 edited versions we read keep these.
7
Distinctive
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 50
Use directional channel types in function signatures to make intent explicit:
- Distinctive: line 57
Only the sender should close a channel.
- Distinctive: line 120
Always pass context as the first argument.
- Very specific: line 140
Check ctx.Done() in loops and before blocking operations:
- Very specific: line 153
Mutex / RWMutex: prefer RWMutex for read-heavy workloads.
- Distinctive: line 174
Never copy a mutex; always use pointer receivers and pass structs by pointer.
- Distinctive: line 176
WaitGroup: wait for a group of goroutines to finish:
- Distinctive: line 190
Once: run initialization exactly once regardless of how many goroutines call it:
- Very specific: line 253
All goroutines blocked on channel ops causes fatal error: all goroutines are asleep.
- Distinctive: line 274
Every goroutine has an explicit exit path (context, channel close, or done signal)
“Common” is measured: kept by at least 6 in 10 of the 6 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Goroutines
Goroutines are cheap (a few KB of stack) but not free. Every goroutine must have a clear exit condition; otherwise it leaks. A goroutine leak happens when a goroutine blocks forever on a channel send, channel receive, or lock with no one to unblock it.
// Bad: no exit condition — leaks if done is never closed
go func() {
for item := range items {
process(item)
}
}()
// Good: exits on context cancellation
go func() {
for {
select {
case <-ctx.Done():
return
case item, ok := <-items:
if !ok {
return
}
process(item)
}
}
}()Channels
Unbuffered channels provide a synchronous rendezvous: sender and receiver must both be ready. Buffered channels decouple them up to the buffer size.
unbuffered := make(chan int) // blocks until receiver is ready
buffered := make(chan int, 10) // blocks only when fullUse directional channel types in function signatures to make intent explicit:
func produce(out chan<- int) { out <- 42 }
func consume(in <-chan int) { v := <-in; _ = v }Only the sender should close a channel. Closing from the receiver side or closing twice panics.
// Range exits automatically when the channel is closed
for item := range ch {
process(item)
}select
select lets a goroutine wait on multiple channel operations simultaneously.
Timeout with context:
select {
case result := <-resultCh:
return result, nil
case <-ctx.Done():
return zero, ctx.Err()
}Non-blocking check with default:
select {
case msg := <-ch:
handle(msg)
default:
// nothing ready — continue without blocking
}Fan-in (merge two channels into one):
func fanIn(ctx context.Context, a, b <-chan int) <-chan int {
out := make(chan int)
go func() {
defer close(out)
for {
select {
case v, ok := <-a:
if !ok { a = nil }
if a == nil && b == nil { return }
if ok { out <- v }
case v, ok := <-b:
if !ok { b = nil }
if a == nil && b == nil { return }
if ok { out <- v }
case <-ctx.Done():
return
}
}
}()
return out
}context.Context
Always pass context as the first argument. Never store it in a struct.
// Correct
func fetchUser(ctx context.Context, id int) (*User, error) { ... }
// Wrong — context hidden in struct, can't be updated per-call
type Service struct { ctx context.Context }Derive contexts to add deadlines or cancellation:
ctx, cancel := context.WithTimeout(parentCtx, 2*time.Second)
defer cancel() // always defer cancel to release resources
ctx, cancel = context.WithCancel(parentCtx)
defer cancel()Check ctx.Done() in loops and before blocking operations:
for _, item := range items {
if err := ctx.Err(); err != nil {
return err
}
process(item)
}sync Package
Mutex / RWMutex: prefer RWMutex for read-heavy workloads; multiple readers can hold the read lock simultaneously.
type SafeMap struct {
mu sync.RWMutex
m map[string]int
}
func (s *SafeMap) Get(key string) int {
s.mu.RLock()
defer s.mu.RUnlock()
return s.m[key]
}
func (s *SafeMap) Set(key string, val int) {
s.mu.Lock()
defer s.mu.Unlock()
s.m[key] = val
}Never copy a mutex; always use pointer receivers and pass structs by pointer.
WaitGroup: wait for a group of goroutines to finish:
var wg sync.WaitGroup
for _, item := range items {
wg.Add(1)
go func(it Item) {
defer wg.Done()
process(it)
}(item)
}
wg.Wait()Once: run initialization exactly once regardless of how many goroutines call it:
var once sync.Once
once.Do(func() { expensiveInit() })Common Patterns
Worker pool:
func workerPool(ctx context.Context, jobs <-chan Job, numWorkers int) <-chan Result {
results := make(chan Result)
var wg sync.WaitGroup
for i := 0; i < numWorkers; i++ {
wg.Add(1)
go func() {
defer wg.Done()
for {
select {
case job, ok := <-jobs:
if !ok {
return
}
results <- job.Do()
case <-ctx.Done():
return
}
}
}()
}
go func() {
wg.Wait()
close(results)
}()
return results
}Semaphore with buffered channel: limit concurrency without a full worker pool:
sem := make(chan struct{}, maxConcurrent)
for _, item := range items {
sem <- struct{}{}
go func(it Item) {
defer func() { <-sem }()
process(it)
}(item)
}
// drain semaphore to wait for all
for i := 0; i < maxConcurrent; i++ {
sem <- struct{}{}
}Common Pitfalls
Goroutine leak, no exit condition: A goroutine blocked on a channel with no sender/receiver runs forever. Fix: use context cancellation.
Channel deadlock, send with no receiver:
All goroutines blocked on channel ops causes fatal error: all goroutines are asleep. Fix: ensure every send has a matching receive path (or use buffered channels + workers).
Data race, unsynchronized shared state:
Two goroutines reading and writing the same variable without a lock is undefined behavior. Run go test -race and go run -race always. Fix: use a mutex or communicate via channels.
Capturing loop variable in goroutine closure:
// Bad: all goroutines capture the same 'v' variable
for _, v := range items {
go func() { process(v) }()
}
// Good: pass as argument
for _, v := range items {
go func(item Item) { process(item) }(v)
}
// Or in Go 1.22+, loop variable is scoped per iteration automaticallyCode Review Checklist
- Every goroutine has an explicit exit path (context, channel close, or done signal)
cancel()fromWithCancel/WithTimeout/WithDeadlineis always deferred immediately- Channels are closed only by the sender
- Mutexes are not copied (struct passed by pointer, pointer receivers used)
wg.Add(n)is called before launching goroutines, not inside them- Loop variables captured in goroutine closures are passed as arguments
go test -racepasses- No
context.Background()used inside request-scoped code: propagate the incoming context
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

