Agent skill

Go Generics

by cxuu in cxuu/golang-skills

A skill your agent uses when deciding whether to use Go generics, writing generic functions or types, choosing constraints, or picking between type aliases and type definitions.

Apache-2.0Auto-check passedDevelopment

Install Go Generics

skills CLI
$ npx skills add cxuu/golang-skills --skill go-generics -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install cxuu/golang-skills go-generics --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/cxuu/golang-skills.git skills-src && mkdir -p .claude/skills && cp -r skills-src/skills/go-generics .claude/skills/go-generics && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
go-generics
GitHub stars
172
Token cost
~1.2k tokens
SKILL.md length
361 words
Files
2 (incl. references)
Skills in repo
20
Repo updated
First seen
Licence
Apache-2.0

At a glance

A skill your agent uses when deciding whether to use Go generics, writing generic functions or types, choosing constraints, or picking between type aliases and type definitions.

  • Deciding whether to use Go generics
  • SKILL.md covers Resource Routing, When to Use Generics, Type Parameter Naming and Type Aliases vs Type Definitions, plus 4 more sections
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md
  • Writing generic functions

What it does

Go Generics is an agent skill from cxuu/golang-skills. Use when deciding whether to use Go generics, writing generic functions or types, choosing constraints, or picking between type aliases and type definitions. Also use when a user is writing a utility function that could work with multiple types, even if they don't mention generics explicitly. Does not cover interface design without generics (see go-interfaces).

Its SKILL.md is about 1.2k tokens, which your agent loads only when the skill is triggered. The skill folder holds 2 other files, including reference files (for example `references/CONSTRAINTS.md`).

It sits in Development, covering API design. The repository describes itself as: AI Agent Skills for idiomatic, production-ready Go code, distilled from Google, Uber, Community. The licence is Apache-2.0.

When your agent uses it

  • Deciding whether to use Go generics
  • Writing generic functions
  • Choosing constraints
  • Picking between type aliases and type definitions

Example prompts

  • “/go-generics”

What it can do on your machine

Read from SKILL.md and the folder at commit 91f0c2e. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md (its code samples are go).

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Go Generics loads about 1.2k tokens when it runs, and up to ~2.4k if it reads all its reference files. Until then it costs about 94 tokens; SKILL.md has 361 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~94
When it runs · the whole SKILL.md, loaded when a task matches
~1.2k
With references · SKILL.md plus every file in references/, read only if the agent opens them
~2.4k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from cxuu/golang-skills at commit 91f0c2e, republished under its Apache-2.0 licence (© cxuu). 361 words, ~1,230 tokens.

Download SKILL.mdSave it as .claude/skills/go-generics/SKILL.md (or your agent's skills folder). This skill also uses 1 other file; get the full folder from GitHub.
name
go-generics
description
Use when deciding whether to use Go generics, writing generic functions or types, choosing constraints, or picking between type aliases and type definitions. Also use when a user is writing a utility function that could work with multiple types, even if they don't mention generics explicitly. Does not cover interface design without generics (see go-interfaces).

Go Generics and Type Parameters

Compatibility: Generics require Go 1.18+.

Resource Routing

  • references/CONSTRAINTS.md - Read when composing constraints, using type sets, or choosing between generics and interfaces.

When to Use Generics

Start with concrete types. Generalize only when a second type appears.

Prefer Generics When
  • Multiple types share identical logic (sorting, filtering, map/reduce)
  • You would otherwise rely on any and excessive type switching
  • You are building a reusable data structure (concurrent-safe set, ordered map)
Avoid Generics When
  • Only one type is being instantiated in practice
  • Interfaces already model the shared behavior cleanly
  • The generic code is harder to read than the type-specific alternative

"Write code, don't design types." — Robert Griesemer and Ian Lance Taylor

Decision Flow
Do multiple types share identical logic?
├─ No  → Use concrete types
├─ Yes → Do they share a useful interface?
│        ├─ Yes → Use an interface
│        └─ No  → Use generics

Bad:

go
// Premature generics: only ever called with int
func Sum[T constraints.Integer | constraints.Float](vals []T) T {
    var total T
    for _, v := range vals {
        total += v
    }
    return total
}

Good:

go
func SumInts(vals []int) int {
    var total int
    for _, v := range vals {
        total += v
    }
    return total
}

Type Parameter Naming

NameTypical Use
TGeneral type parameter
KMap key type
VMap value type
EElement/item type

For complex constraints, a short descriptive name is acceptable:

go
func Marshal[Opts encoding.MarshalOptions](v any, opts Opts) ([]byte, error)

Type Aliases vs Type Definitions

Type aliases (type Old = new.Name) are rare — use only for package migration or gradual API refactoring.


Constraint Composition

Combine constraints with ~ (underlying type) and | (union):

go
type Numeric interface {
    ~int | ~int8 | ~int16 | ~int32 | ~int64 |
    ~float32 | ~float64
}

func Sum[T Numeric](vals []T) T {
    var total T
    for _, v := range vals {
        total += v
    }
    return total
}

Use the constraints package or cmp package (Go 1.21+) for standard constraints like cmp.Ordered instead of writing your own.


Common Pitfalls

Don't Wrap Standard Library Types
go
// Bad: generic wrapper adds complexity without value
type Set[T comparable] struct {
    m map[T]struct{}
}

// Better: use map[T]struct{} directly when the usage is simple
seen := map[string]struct{}{}

Generics justify their complexity when they eliminate duplication across multiple call sites. A single-use generic is just indirection.

Show full SKILL.md (140 more words)Show less
Don't Use Generics for Interface Satisfaction
go
// Bad: T is only used to satisfy an interface — just use the interface
func Process[T io.Reader](r T) error { ... }

// Good: accept the interface directly
func Process(r io.Reader) error { ... }
Avoid Over-Constraining
go
// Bad: constraint is more restrictive than needed
func Contains[T interface{ ~int | ~string }](slice []T, target T) bool { ... }

// Good: comparable is sufficient
func Contains[T comparable](slice []T, target T) bool { ... }

Quick Reference

TopicGuidance
When to use genericsOnly when multiple types share identical logic and interfaces don't suffice
Starting pointWrite concrete code first; generalize later
NamingSingle uppercase letter (T, K, V, E)
Type aliasesSame type, alternate name; use only for migration
Constraint compositionUse ~ for underlying types, `
Common pitfallDon't genericize single-use code or when interfaces suffice

  • Interfaces vs generics: See go-interfaces when deciding whether an interface already models the shared behavior without generics
  • Type declarations: See go-declarations when defining new types, type aliases, or choosing between type definitions and aliases
  • Documenting generic APIs: See go-documentation when writing doc comments and runnable examples for generic functions
  • Naming type parameters: See go-naming when choosing names for type parameters or constraint interfaces

© cxuu, Apache-2.0. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

SKILL.md and 1 other file (references) in skills/go-generics of cxuu/golang-skills.

  • SKILL.md
  • references/CONSTRAINTS.md

Open the folder on GitHubat commit 91f0c2e

Compare with similar skills

Go Generics next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Go Generics compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Go Generics this skillcxuu/golang-skills172—~1.2kAutomated safety check: PassApache-2.0
Go Pedantrychromedp/chromedp13k—~3.7kAutomated safety check: PassMIT
LangBot Core Developmentlangbot-app/LangBot18k—~1.4kAutomated safety check: NotesApache-2.0
Breaking Change Analysisruby-git/ruby-git1.8k—~1.7kAutomated safety check: PassMIT
Atomui Control OptimizationAtomUI/AtomUI842—~3.4kAutomated safety check: PassLGPL-3.0
Go Standardsasymmetric-research/solana-exporter133—~1.6kAutomated safety check: PassApache-2.0

Similar skills

  • Go Pedantry

    chromedp/chromedp

    This skill should be used when the user is writing Go code and needs guidance on Go-specific pedantry: error wrapping with fmt.Errorf and %w, interface design (accept interfaces return structs)…

    13k GitHub stars~3.7k tokensUpdated 3 days ago
    DevelopmentAuto-check passed
  • LangBot Core Development

    langbot-app/LangBot

    Covers developing the LangBot core backend and web UI: dev setup, repo layout, API auth types, adding endpoints, migrations and keeping the MCP server in step.

    18k GitHub stars~1.4k tokensUpdated yesterday
    DevelopmentAuto-check: notes
  • Breaking Change Analysis

    ruby-git/ruby-git

    Assesses what an API change would break before it is made, finds every usage, documents the impact and plans a deprecation or migration path.

    1.8k GitHub stars~1.7k tokensUpdated 7 days ago
    DevelopmentAuto-check passed
  • A skill your agent uses when optimizing, refactoring, reviewing, or fixing AtomUI controls, including control API contracts, member layout, file splitting, lifecycle, AXAML structure, correctness…

    842 GitHub stars~3.4k tokensUpdated 2 days ago
    DevelopmentAuto-check passed
  • Go Standards

    asymmetric-research/solana-exporter

    Idiomatic Go conventions — naming, error handling, concurrency, interfaces, testing, and API design.

    133 GitHub stars~1.6k tokensUpdated 2 mo ago
    DevelopmentAuto-check passed
  • Modern Csharp Coding Standards

    sketch7/FluentlyHttpClient

    Write modern, high-performance C code using records, pattern matching, value objects, async/await, Span<T/Memory<T, and best-practice API design patterns.

    121 GitHub starsUsed in 3 repos~2.7k tokens
    DevelopmentAuto-check passed

More from cxuu/golang-skills

All 20 skills in this repo
  • Go Testing

    cxuu/golang-skills

    A skill your agent uses when writing, reviewing, or improving Go test code — including table-driven tests, subtests, parallel tests, test helpers, test doubles, and assertions with cmp.Diff.

    172 GitHub starsUsed in 1 repo~1.3k tokens
    Auto-check passed
  • Go Code Review

    cxuu/golang-skills

    A skill your agent uses when reviewing Go code or checking code against community style standards.

    172 GitHub stars~2.7k tokensUpdated 3 mo ago
    Auto-check passed
  • Go Performance

    cxuu/golang-skills

    A skill your agent uses when optimizing Go code, investigating slow performance, or writing performance-critical sections.

    172 GitHub starsUsed in 1 repo~1.3k tokens
    Auto-check passed
  • Go Documentation

    cxuu/golang-skills

    A skill your agent uses when writing or reviewing documentation for Go packages, types, functions, or methods.

    172 GitHub stars~1.3k tokensUpdated 3 mo ago
    Auto-check passed
  • Go Error Handling

    cxuu/golang-skills

    A skill your agent uses when writing Go code that returns, wraps, or handles errors — choosing between sentinel errors, custom types, and fmt.Errorf (%w vs %v), structuring error flow, or deciding…

    172 GitHub stars~1.5k tokensUpdated 3 mo ago
    Auto-check passed
  • Go Interfaces

    cxuu/golang-skills

    A skill your agent uses when defining or implementing Go interfaces, designing abstractions, creating mockable boundaries for testing, or composing types through embedding.

    172 GitHub stars~1.4k tokensUpdated 3 mo ago
    Auto-check passed

Questions about Go Generics

What does Go Generics do?

A skill your agent uses when deciding whether to use Go generics, writing generic functions or types, choosing constraints, or picking between type aliases and type definitions. Go Generics is an agent skill from cxuu/golang-skills. Use when deciding whether to use Go generics, writing generic functions or types, choosing constraints, or picking between type aliases and type definitions.

When should I use Go Generics?

Go Generics fits situations like: deciding whether to use Go generics; writing generic functions; choosing constraints; picking between type aliases and type definitions.

How do I install Go Generics in Claude Code?

Run `npx skills add cxuu/golang-skills --skill go-generics -a claude-code`. Or copy the skill folder (skills/go-generics in cxuu/golang-skills) into .claude/skills/go-generics in your project. Claude Code loads it when a task matches its description.

How do I install Go Generics in Codex?

Run `npx skills add cxuu/golang-skills --skill go-generics -a codex`. Or copy the skill folder (skills/go-generics in cxuu/golang-skills) into .agents/skills/go-generics in your project. Codex loads it when a task matches its description.

Can I use Go Generics in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add cxuu/golang-skills --skill go-generics -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/go-generics, .gemini/skills/go-generics, .github/skills/go-generics and .opencode/skills/go-generics in your project.

What does Go Generics need to run?

SKILL.md names no scripts, command-line tools or credentials: Go Generics is instructions for the agent only.

Does Go Generics access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is Go Generics safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Go Generics use?

Go Generics is published under the Apache-2.0 licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Go Generics use?

About 1.2k tokens (SKILL.md is roughly 4.9k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full. Its references folder adds about 1.2k tokens, read only when the agent opens those files.

What are the alternatives to Go Generics?

Skills that share tags, products or a category with Go Generics: Go Pedantry (chromedp/chromedp, 13k stars), LangBot Core Development (langbot-app/LangBot, 18k stars), Breaking Change Analysis (ruby-git/ruby-git, 1.8k stars) and Atomui Control Optimization (AtomUI/AtomUI, 842 stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Go Generics?

cxuu (a GitHub user) maintains it in cxuu/golang-skills, which has 172 GitHub stars. The repository holds 20 skills in this directory. The repository was last updated on June 20, 2026.

Source: cxuu/golang-skills on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.