go-context

Enforce context.Context as the first parameter in Go functions.

Updated Apr 16, 2026
One-click install
npx skills add https://github.com/HadiCherkaoui/opencode-config --skill go-context-hadicherkaoui
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: go-context
Source: https://github.com/HadiCherkaoui/opencode-config/tree/main/skills/golang/go-context
Command: npx skills add https://github.com/HadiCherkaoui/opencode-config --skill go-context-hadicherkaoui

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Go context.Context usage patterns including parameter placement, avoiding struct embedding, and proper propagation. Use when working with context.Context in Go code for cancellation, deadlines, and request-scoped values.

Core Features & Use Cases

  • Enforces using context.Context as the first parameter for functions.
  • Discourages storing Context in structs and creating custom Context types.
  • Guides propagation of cancellation, deadlines, and request-scoped values across API boundaries and background tasks.

Quick Start

Refactor your Go codebase to pass context.Context as the first parameter in all call chains.

Frequently Asked Questions about go-context

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

FAQPage Schema
How do I enforce context.Context as the first parameter in Go functions?

To enforce context.Context as the first parameter in Go, apply standardized context patterns across your projects. This ensures safe cancellation, deadlines, and request-scoped value propagation throughout API boundaries.

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

You should avoid storing context.Context in Go structs to prevent unpredictable lifetimes and scope leakage. Passing context explicitly as the first parameter ensures safe, predictable flows and proper cancellation across API boundaries.

How do I propagate cancellation and deadlines across Golang API boundaries?

To propagate cancellation and deadlines across Golang API boundaries, pass context.Context explicitly through call chains. Standardizing this propagation ensures workers and handlers respect timeouts and safely terminate operations.

What is the best way to handle request-scoped values in Go context?

The best way to handle request-scoped values in Go context is to propagate them explicitly across API boundaries. Guiding context value usage avoids custom Context types and ensures values remain tied to specific requests.

Can I create custom context types for my Golang workers?

No, you should not create custom Context types for Golang workers. Standardizing on the built-in context.Context prevents structural embedding issues and ensures predictable cancellation and deadline handling across background tasks.

When do I need to standardize context usage patterns in a Go codebase?

You need to standardize context usage patterns in a Go codebase when managing cancellation, deadlines, and request-scoped values. Standardization enforces the first-parameter pattern and prevents unsafe struct embedding across API handlers.