go-concurrency
Skill9 starsChanged 8 months agoMITView on GitHub
Use when writing, reviewing, or debugging concurrent Go code. Covers goroutine lifecycle management, channels, errgroup, mutexes, atomics, sync.Map, and synchronous-first design. Based on Google and Uber style guides.
7 other projects use a version of this.
Adopted by
Most recently taken up by
- AllThingsSmitty/proven-skillstheir own version, first seen Oct 6, 2026
- 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
Used with
Projects with it also use go-interfaces.
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.
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
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
- inference-gateway/skills★ 3same name
- CasLubbers/code-design-skills★ 2same name
- AllThingsSmitty/proven-skills★ 1same 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 repository8 other files it gives its agents.
- golangSkill
- go-code-reviewSkill
- go-error-handlingSkill
- go-lintingSkill
- go-performanceSkill
- go-project-layoutSkill
- go-securitySkill
- go-testingSkill
The file
We split this skill into the rules it gives an agent
4 rules. 0 are common, 2 are distinctive, and 2 are very specific to this project.
0
Common
Most of the 6 edited versions we read keep these.
2
Distinctive
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 34
Document when and how goroutines exit.
- Very specific: line 51
Prefer errgroup.Group over manual sync.WaitGroup for error-returning goroutines.
- Distinctive: line 118
Use the standard library's typed atomics.
- Very specific: line 139
Always select on ctx.Done() in long-running goroutines to allow clean cancellation.
“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
Go Concurrency
Patterns for safe, efficient concurrent Go code.
Channel Size
Channels should have size zero (unbuffered) or one. Any other size requires justification about what prevents filling under load.
// Wrong: arbitrary buffer
c := make(chan int, 64)
// Correct
c := make(chan int) // unbuffered: synchronous handoff
c := make(chan int, 1) // buffered: allows one pending sendGoroutine Lifetimes
Document when and how goroutines exit. Goroutines blocked on channels will not be garbage collected even if the channel is unreachable.
func (w *Worker) Run(ctx context.Context) error {
for {
select {
case <-ctx.Done():
return ctx.Err()
case job := <-w.jobs:
w.process(job)
}
}
}Use errgroup for Concurrent Operations
Prefer errgroup.Group over manual sync.WaitGroup for error-returning goroutines.
import "golang.org/x/sync/errgroup"
func processItems(ctx context.Context, items []Item) error {
g, ctx := errgroup.WithContext(ctx)
for _, item := range items {
g.Go(func() error {
return process(ctx, item)
})
}
return g.Wait() // returns first error, cancels others via ctx
}
// With concurrency limit
func processItemsLimited(ctx context.Context, items []Item) error {
g, ctx := errgroup.WithContext(ctx)
g.SetLimit(10) // max 10 concurrent goroutines
for _, item := range items {
g.Go(func() error {
return process(ctx, item)
})
}
return g.Wait()
}Prefer Synchronous Functions
Synchronous functions are easier to reason about and test. Let callers add concurrency when needed.
// Wrong: forces concurrency on caller
func Fetch(url string) <-chan Result
// Correct: caller can wrap in goroutine if needed
func Fetch(url string) (Result, error)Zero Value Mutexes
The zero value of sync.Mutex is valid. Do not use pointers to mutexes or embed them in exported structs.
// Wrong
mu := new(sync.Mutex)
// Wrong: exposes Lock/Unlock in API
type SMap struct {
sync.Mutex
data map[string]string
}
// Correct
type SMap struct {
mu sync.Mutex
data map[string]string
}Atomic Operations (Go 1.19+)
Use the standard library's typed atomics.
import "sync/atomic"
type Counter struct {
value atomic.Int64
}
func (c *Counter) Inc() { c.value.Add(1) }
func (c *Counter) Value() int64 { return c.value.Load() }
// Also available: atomic.Bool, atomic.Pointer[T], atomic.Uint32, etc.sync.Map Performance (Go 1.24+)
The sync.Map implementation was significantly improved in Go 1.24. Modifications of disjoint sets of keys are much less likely to contend on larger maps, and there is no longer any ramp-up time required to achieve low-contention loads.
Context Cancellation
Always select on ctx.Done() in long-running goroutines to allow clean cancellation.
func longOperation(ctx context.Context) error {
resultCh := make(chan result, 1)
go func() {
// Note: if ctx is canceled, this goroutine still runs to completion
// and sends to the buffered channel (then gets GC'd).
// Pass ctx into the work function if it supports cancellation.
resultCh <- expensiveWork()
}()
select {
case <-ctx.Done():
return ctx.Err()
case r := <-resultCh:
return r.err
}
}For graceful server shutdown patterns, see references/patterns.md.
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.

