go/context

Propagate Go context cancellation, deadlines, and values across call chains.

3|1|Updated Feb 10, 2026
One-click install
npx skills add https://github.com/deandum/claude-resources --skill go-context-deandum
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: go/context
Source: https://github.com/deandum/claude-resources/tree/main/skills/go/context
Command: npx skills add https://github.com/deandum/claude-resources --skill go-context-deandum

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Go context propagation, cancellation, timeouts, and value storage to coordinate request lifecycles and goroutine coordination in Go programs.

Core Features & Use Cases

  • Context creation patterns: Background, TODO, WithTimeout, WithCancel, WithDeadline, WithValue, and WithoutCancel
  • Pattern examples: HTTP handlers with timeout management and safe cancellation behavior
  • Pattern examples: Type-safe context values with custom keys and accessors
  • Anti-patterns and verification: Avoid storing context in structs, avoid bare strings as keys, and check for cancellation signals

Quick Start

Invoke the Go context utilities to propagate cancellation and timeouts across goroutines in a request lifecycle.

Frequently Asked Questions about go/context

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

FAQPage Schema
How do I use Go context to propagate cancellation and timeouts across goroutines?▼

Go context propagates cancellation and timeouts across goroutines by passing context.Context as the first parameter. You use WithTimeout, WithCancel, or WithDeadline to signal goroutines to stop processing when a request lifecycle ends.

Why should I avoid storing context.Context in structs in Go?▼

Storing context.Context in structs is an anti-pattern because context instances are designed for request-scoped lifecycles. Explicitly passing context as the first function parameter ensures cancellation signals and deadlines propagate correctly down the call chain.

What is the best way to pass request-scoped values in Go without using bare strings as keys?▼

Pass request-scoped values using WithValue alongside custom key types. Avoiding bare strings as keys prevents naming collisions, ensuring type-safe context value retrieval when propagating data across HTTP handlers and workers.

How do I manage deadlines in Go HTTP handlers to prevent long-running requests?▼

Manage HTTP handler deadlines by creating a derived context using WithDeadline or WithTimeout. This enforces a strict maximum duration for the request lifecycle, ensuring safe cancellation behavior if the threshold is exceeded.

When do I need to use WithoutCancel for background workers in Go?▼

Use WithoutCancel when background workers must continue executing independently of a parent request's cancellation signal. It derives a new context that preserves deadlines and values while ignoring upstream cancellation propagation.

Does Go context work with microservices to coordinate request lifecycle control?▼

Yes, Go context works with microservices to coordinate request lifecycle control. Propagating context across service boundaries enforces distributed timeouts, manages deadlines, and carries request-scoped values throughout the network call chain.