context-standards

Enforce Go context.Context best practices for cancellation, propagation, and value usage.

1|Updated Jan 21, 2026
One-click install
npx skills add https://github.com/pdylanross/barnacle --skill context-standards
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: context-standards
Source: https://github.com/pdylanross/barnacle/tree/main/.claude/skills/context-standards
Command: npx skills add https://github.com/pdylanross/barnacle --skill context-standards

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill ensures adherence to best practices when working with Go's context.Context type, preventing common pitfalls and improving code quality.

Core Features & Use Cases

  • Cancellation Handling: Guides developers on properly checking for context cancellation before executing long-running operations.
  • Context Propagation: Enforces the standard of passing context as the first parameter in function signatures.
  • Value Usage Guidelines: Provides clear rules on when and how to use context.WithValue to avoid misuse and key collisions.
  • Use Case: A developer is unsure about the correct way to handle timeouts or cancellations in a Go service. This Skill provides the exact rules to follow.

Quick Start

Follow the golang context standards when writing new functions.

Frequently Asked Questions about context-standards

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

FAQPage Schema
How do I properly pass golang context in function signatures?

Pass golang context as the first parameter in function signatures to ensure proper context propagation. This standard practice maintains idiomatic Go code and allows cancellation signals to flow correctly through your application call chain.

What are the best practices for checking context cancellation in Go?

Check golang context cancellation before executing long-running operations to ensure your service responds promptly to timeouts and termination signals. This prevents goroutine leaks and allows graceful shutdown when parent operations are canceled.

When should I use context.WithValue in Go and what are the limitations?

Use golang context.WithValue only for request-scoped data that transits process boundaries, not for optional function parameters. Misuse leads to key collisions and unclear data flow, so follow strict key management strategies to avoid these common pitfalls.

How do I manage context keys to avoid collisions in Go services?

Manage golang context keys by using unexported custom types to prevent collisions between packages. This key management strategy ensures that stored values remain isolated and type-safe when propagating context through your application.

What is the correct way to handle timeouts and cancellations in a Go service?

Handle golang context timeouts by propagating context from the entry point and checking ctx.Done() before long-running operations. This ensures your service adheres to best practices for cancellation handling and robust context propagation.