# CONTEXT.md

> Control which instructions, examples, tools, retrieved facts, messages, and summaries reach the model; record their authority, provenance, freshness, token cost, and intended decision.

**Decision rule:** Include context only when it changes a named decision or reduces a measured failure. Retrieve current authoritative evidence instead of accumulating every available token.

## How to use this template

- Replace every angle-bracket placeholder with project-specific evidence.
- Remove sections that do not apply instead of leaving ambiguous boilerplate.
- Link decisions to their specifications, tasks, tests, traces, and owners.
- Re-review this file when the workflow, authority boundary, or primary source changes.

## Context inventory

> Identify every source of runtime tokens and the specific decision or behavior it supports.

- **Always loaded:** <List system instructions, repository policy, schemas, and stable constraints>
- **Retrieved:** <List knowledge stores, search, tools, ranking, and freshness requirements>
- **Runtime:** <List user input, session history, tool output, scratch state, and summaries>

## Selection and budget

> Prioritize relevant and authoritative context under realistic limits.

- **Budget:** <Allocate tokens or size limits by instruction, history, retrieval, tools, and output>
- **Ranking:** <Define relevance, authority, recency, diversity, and conflict rules>
- **Compaction:** <Describe summarization, truncation, checkpointing, and information that must survive>

## Provenance and conflict

> Make it possible to inspect why information was present and which source wins.

- **Provenance:** <Attach source, owner, timestamp, version, and retrieval reason>
- **Authority order:** <Define precedence for user intent, project policy, retrieved evidence, and model inference>
- **Sensitive context:** <State redaction, isolation, retention, and export restrictions>

## Evaluation

> Measure whether the context system helps rather than assuming more is better.

- **Quality:** <Test retrieval precision, groundedness, conflict resolution, and task success>
- **Efficiency:** <Measure tokens, latency, cache effectiveness, and repeated retrieval>
- **Failure cases:** <Test stale facts, prompt injection, distraction, compaction loss, and missing context>

## Related AgentAtlas field guides

- [Context engineering](https://agentatlas.dev/topics/context-engineering)
- [Memory and context](https://agentatlas.dev/topics/memory-context)
- [Safety and permissions](https://agentatlas.dev/topics/safety-permissions)

## Primary references

- [Effective context engineering for AI agents](https://www.anthropic.com/engineering/effective-context-engineering-for-ai-agents) — Treating context as a finite resource and curating instructions, tools, external data, history, and summaries across long-running agents.
- [How Claude remembers your project](https://code.claude.com/docs/en/memory) — Repository instruction hierarchy, project memory, scoped rules, and how persistent context is discovered and loaded.
- [Sessions](https://openai.github.io/openai-agents-python/sessions/) — Session memory, storage choices, history limits, compaction, resumption, and operational persistence patterns.
- [Codex security](https://developers.openai.com/codex/security) — Sandboxing, approvals, network access, filesystem controls, and security boundaries for agentic coding work.
- [Configure permissions](https://code.claude.com/docs/en/permissions) — Permission rules, allow and deny controls, managed policy, tool authorization, and least-privilege configuration.

---

- Template version: 1.0.0
- Reviewed: 2026-07-26

Generated deterministically from reviewed AgentAtlas records.
