# Context engineering

> Canonical: https://skillalmanac.com/glossary/context-engineering | Last verified: 2026-11-25 | Index status: index-eligible

Context engineering is usually described as the practice of choosing and maintaining the information a language model sees at each step, including instructions, tools, examples, message history and retrieved data, not only the wording of the prompt.

Also called: context engineering for AI agents, context engineering AI, context engineering vs prompt engineering, agent context management.

## In plain language

Context engineering is deciding what goes on the model's desk before it answers. Alongside knowledge learned during training, a model uses the context supplied for that request: selected instructions, tool descriptions, earlier messages and files or search results. Think of briefing a new colleague: a good brief is short, current and has the right documents, while a pile of everything makes them miss the point. For an AI agent that works for hours, the job can include selecting, trimming and refreshing that pile as it grows. The limit is that the space is finite, so adding text can push out other text and can make results worse. Resending a large retained context can increase token usage; allowance and billing effects depend on the provider, plan and caching.

## Technical definition

The term covers managing the whole token budget of a request: system prompt, tool definitions, examples, conversation history, tool results and retrieved documents. Anthropic's engineering article calls it the natural progression of prompt engineering, and lists techniques for long tasks. Compaction summarises a conversation near the context limit and continues in a fresh window. Structured note-taking has the agent write notes to storage outside the window and reload them later. Sub-agents handle focused work in clean windows and return condensed summaries. Just-in-time retrieval keeps lightweight references such as file paths and loads data through tools only when needed.

## How it shows up when you use agents

In a coding-agent session, context is the information actually supplied for a model request. It can include a [system prompt](/glossary/system-prompt), loaded project instructions, selected tool definitions, retained messages and tool results. It need not include every historical command output or every available tool: compaction, clearing and deferred loading can change what is retained. The [context window](/glossary/context-window) is the ceiling on all of it together. Context engineering is the habit of managing that pile on purpose.

What breaks when it is misunderstood: people keep rewriting the prompt when the real problem is the pile. A session that has run for hours carries stale tool output and old dead ends, and the agent can lose the thread or repeat itself. Claude Code documents compaction, context management and deferred tool definitions. The retained context, caching and provider or plan determine the usage and billing effects; historical raw output need not all be resent.

Next action: when a session drifts, check what is occupying space before rewording anything. In Claude Code, `/context` shows it. Use `/compact` with a note about what to keep, or `/clear` between unrelated tasks. Write down what the next session needs, as in a handoff note, rather than hoping the old history survives. For work that splits cleanly, an agent can delegate to a [subagent](/glossary/subagent) so the noisy detail stays out of the main window.

## Common confusions

- **Context engineering versus prompt engineering.** Prompt engineering is mainly about writing the instructions. Context engineering, per Anthropic's article, also covers tools, examples, message history and external data. See [Prompt engineering](/glossary/prompt-engineering).
- **Context window versus context.** The window is the maximum size. The context is what you actually put in it.
- **Context versus memory.** Context is what the model sees for this request. [Agent memory](/glossary/agent-memory) is stored information that may be loaded into context later.
- **Myth.** More context gives better answers. The space is finite, and extra text competes with the text that matters.

## Worked examples in this catalogue

### [context-window-packer](https://skillalmanac.com/skills/skill-almanac/context-window-packer)

Status: illustrative example from the item's own documentation, not executed for this page.

What you see: A record of which files were kept, shrunk or dropped to fit one prompt's token budget, and the reason for each choice.

Why it exercises the concept: It is context engineering done by hand and written down: a limited budget, a set of candidates and an explicit decision about what earns a place.

### [session-handoff-notes](https://skillalmanac.com/skills/skill-almanac/session-handoff-notes)

Status: illustrative example from the item's own documentation, not executed for this page.

What you see: A handoff note the next coding-agent session can act on, checked for evidence, paths and vague items.

Why it exercises the concept: It matches the note-taking technique in Anthropic's article: state is saved outside the window so a fresh session can continue without carrying the old history.

### [Claude Code](https://skillalmanac.com/tools/claude-code)

```
/compact
```

Status: illustrative example from the item's own documentation, not executed for this page.

What you see: Claude Code summarises the conversation so far and continues from the summary. The costs page shows adding instructions after the command, such as focusing on code samples and API usage, to say what to keep. The same page says /context shows what is using space.

Why it exercises the concept: Compaction is one of the techniques the article names, and this is the command that performs it in a coding session.

## Related terms

- [Prompt engineering](https://skillalmanac.com/glossary/prompt-engineering.md)
- [Context window](https://skillalmanac.com/glossary/context-window.md)
- [Agent memory](https://skillalmanac.com/glossary/agent-memory.md)
- [System prompt](https://skillalmanac.com/glossary/system-prompt.md)
- [Subagent](https://skillalmanac.com/glossary/subagent.md)
- [Agent harness](https://skillalmanac.com/glossary/agent-harness.md)

## Sources

- [Effective context engineering for AI agents](https://www.anthropic.com/engineering/effective-context-engineering-for-ai-agents), Anthropic (accessed 2026-11-23)
- [Manage costs effectively](https://code.claude.com/docs/en/costs), Anthropic (Claude Code Docs) (accessed 2026-11-23)

Definitions are written by Skill Almanac from the sources above and checked against them on 2026-11-25. [Glossary index](https://skillalmanac.com/glossary.md).
