---
title: "context-stored-in-struct"
description: "Detect context.Context fields in structs."
image: "https://strider.gempir.com/og.png"
---

> Documentation Index
> Fetch the complete documentation index at: https://strider.gempir.com/llms.txt
> Use this file to discover all available pages before exploring further.

# context-stored-in-struct

**Default severity:** `warning`

Contexts carry request-scoped cancellation, deadlines, and values. Keeping one
in a struct obscures its lifetime and can accidentally reuse stale request
state. Pass the context explicitly to each operation that needs it.

## Bad

```go
type Service struct { ctx context.Context }
```

## Good

```go
func (service *Service) Run(ctx context.Context) error
```

Source: https://strider.gempir.com/analyzers/context-stored-in-struct/index.mdx
