go-context-patterns

Implement Go context patterns for cancellation, timeouts, and request-scoped values.

Updated Jan 8, 2026
One-click install
npx skills add https://github.com/OlegHQ/claude-config --skill go-context-patterns
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: go-context-patterns
Source: https://github.com/OlegHQ/claude-config/tree/main/go-skills-plugin/skills/go-context-patterns
Command: npx skills add https://github.com/OlegHQ/claude-config --skill go-context-patterns

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Go projects often suffer from unbounded operations and difficult-to-cancel workflows. This skill provides clear patterns for using Go's context to control cancellation, timeouts, and per-request values across layers.

Core Features & Use Cases

  • Context-first APIs to pass deadlines, cancellation signals, and trace data through the call stack.
  • Timeouts and cancellation patterns to bound long-running operations and goroutines.
  • Safe propagation of request-scoped values without storing context in structs.
  • Clear guidelines for goroutine lifecycles and background tasks.

Quick Start

Thread a context through your APIs and apply timeouts (e.g., context.WithTimeout) to bound I/O or computation.

Frequently Asked Questions about go-context-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I safely propagate cancellation and timeouts across goroutines in Go?

To propagate cancellation and timeouts in Go, thread a context through your APIs and apply context.WithTimeout. This ensures proper propagation through call stacks and bounds long-running goroutine lifecycles safely.

What is the best way to design context-first APIs for request-scoped values in Go?

Context-first API design in Go passes deadlines, cancellation signals, and trace data as the first argument. This approach safely propagates request-scoped values through the call stack without storing the context in structs.

Why should I avoid storing Go context inside a struct?

You should avoid storing Go context inside a struct to ensure safe value passing. Contexts are designed for request-scoped data and cancellation signals, meaning they must flow through call stacks rather than persisting within struct lifecycles.

How do I bound long-running I/O operations using Go context patterns?

To bound long-running I/O operations using Go context patterns, apply context.WithTimeout or context.WithCancel to your context. This enforces strict deadlines and cancellation signals, preventing unbounded operations across your services.

When do I need to use context for background tasks in Go?

You need to use context for background tasks in Go when managing goroutine lifecycles for long-running or I/O-bound operations. Applying context patterns provides clear guidelines for cancellation and prevents unbounded workflows.

Does this Go context pattern handle trace data propagation across services?

Yes, this Go context pattern handles trace data propagation by using context-first APIs. It passes deadlines, cancellation signals, and request-scoped trace data safely through the call stack across multiple services.