# Go context

> Go context is an open-source agent skill for developer tools. Guides an agent to use Go's context.Context correctly for cancellation and timeouts. It is available on Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, Windsurf and Goose.

- **Kind:** Skill
- **Pricing:** Open source
- **Platforms:** Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, Windsurf, Goose
- **Website:** https://github.com/eduardo-sl/go-agent-skills/tree/main/skills/(code-quality)/go-context
- **Repository:** https://github.com/eduardo-sl/go-agent-skills
- **GitHub stars:** 90
- **License:** MIT
- **Skill name:** go-context
- **Collection:** https://github.com/eduardo-sl/go-agent-skills
- **Categories:** [developer tools](https://ai-powered.com/categories/developer-tools)
- **Listing updated:** 2026-12-02

## About

This skill covers the correct handling of Go's context.Context type: where it belongs in function signatures, how to propagate it, and how to attach cancellation, deadlines and timeouts. It warns against common mistakes such as storing contexts in structs, passing nil, and ignoring cancellation inside loops, and it includes a verification checklist the agent can run through after making changes.

The skill also explains how to divide a parent's remaining time budget among child calls, when to read the deadline before starting uninterruptible work, and how to use request-scoped values with unexported key types and accessor functions. Guidance for HTTP handlers, middleware and tests is included, along with newer APIs such as cancel causes, WithoutCancel and AfterFunc, each tied to the Go version that introduced it.

The skill expects a Go project and the Go toolchain. It is allowed to read and edit files, search the codebase, and run go and gofmt commands. Its reference files are loaded on demand for deeper examples on timeouts, values, HTTP testing and cause handling.

## When your agent uses it

> 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". Not for: concurrency beyond context (go-concurrency-review), HTTP middleware (go-api-design), error handling (go-error-handling).

## What it can access

From a static check of the files on GitHub; nothing was run.

- [Instructions only, no scripts](https://github.com/eduardo-sl/go-agent-skills/tree/HEAD/skills/(code-quality)/go-context)
- [Asks for: Read, Edit, Write, Glob, Grep, Bash(go:*), Bash(gofmt:*)](https://github.com/eduardo-sl/go-agent-skills/blob/HEAD/skills/(code-quality)/go-context/SKILL.md)
- [License: MIT](https://github.com/eduardo-sl/go-agent-skills/tree/HEAD/skills/(code-quality)/go-context)

## Features

- **Context parameter placement:** Rules for putting context.Context first and avoiding storing it in structs or passing nil.
- **Cancellation handling:** Patterns for deferring cancel, using errgroup and checking ctx.Err() inside loops.
- **Timeout budgeting:** Guidance on nesting timeouts and reading ctx.Deadline() so child calls fit within the parent's budget.
- **Context values rules:** Limits on what to store in context values, with unexported key types and accessor functions.
- **HTTP and test context:** Handling r.Context() in handlers and middleware, and writing cancellation tests with t.Context().
- **Cause and detach APIs:** Reference for WithCancelCause, WithoutCancel and AfterFunc with their Go version requirements.

## Good for

- Review a Go service for misused context.Context parameters
- Add timeouts to an HTTP client call in Go
- Make a long processing loop stop when its context is cancelled
- Write a test that proves a Go function honours cancellation
- Propagate request context to background work safely

## Install

### Any agent

Download the skill folder from https://github.com/eduardo-sl/go-agent-skills and copy it into your agent's skills folder.

## FAQ

### What does the skill need to run?

It requires the Go toolchain and works on Go projects. It is allowed to use go and gofmt commands along with file reading, editing and searching tools.

### When does Go context apply?

It applies to context usage questions such as context.Context, cancellation, timeouts, deadlines, context values and propagation. Concurrency beyond context, HTTP middleware and error handling are handled by other skills.

### Does Go context run any scripts?

No, the skill has no scripts. It relies on written guidance and reference files that are loaded when needed.

### Does Go context run scripts?

No. It is instructions only, with no scripts. This comes from a static check of the files on GitHub; nothing was run. Read the files before you install it.

### Which AI agents can use Go context?

Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, Windsurf and Goose. Each reads skills in the SKILL.md format from its own folder; the install steps on this page list them.

### What are the best alternatives to Go context?

The closest alternatives to Go context are Go concurrency review, Go test quality, Go backend, Go database and Go coding standards.

## Where this comes from

- Description: from the skill's own SKILL.md.

## Alternatives

- [Go concurrency review](https://ai-powered.com/skills/go-concurrency-review): Go concurrency review is an open-source agent skill for developer tools.
- [Go test quality](https://ai-powered.com/skills/go-test-quality): Go test quality is an open-source agent skill for developer tools.
- [Go backend](https://ai-powered.com/skills/go-backend): Go backend is an open-source agent skill for developer tools.
- [Go database](https://ai-powered.com/skills/go-database): Go database is an open-source agent skill for databases.
- [Go coding standards](https://ai-powered.com/skills/go-coding-standards): Go coding standards is an open-source agent skill for developer tools.
- [Go documentation](https://ai-powered.com/skills/go-documentation): Go documentation is an open-source agent skill for developer tools.
- [Vibe concurrent test safety](https://ai-powered.com/skills/vibe-concurrent-test-safety): Vibe concurrent test safety is an open-source agent skill for developer tools.
- [Go GRPC](https://ai-powered.com/skills/go-grpc): Go GRPC is an open-source agent skill for developer tools.

---
Source: https://ai-powered.com/skills/go-context
