Context engineering
Updated 2026-10-11
Questions this answers
- What is context engineering, and how is it different from prompt engineering?
- Why does Claude give worse answers the longer a chat goes on?
- What is context rot?
- The context window is huge now. Why do I still need to manage it?
- What should go in a CLAUDE.md file?
- How do I start a new session without losing everything from the last one?
The Fix
Context engineering is deciding what a model sees on each call: the system prompt, your message, attached files, past turns, tool definitions, and whatever the agent remembered. Prompt engineering is how you word the request. Context engineering is choosing which files, history, and tools go in with it.
The failure mode is context rot. Answers get worse as the context window fills with old turns, stale files, and tool output. Chroma tested 18 models and saw the drop as inputs grew, even on simple retrieval tasks. A bigger window doesn't fix it, because attention across a long window is uneven: a detail from early in a session gets lost later on, and hallucinations fill the gap.
Most agent features are context tools. A skill loads its instructions only when a task matches. A subagent searches in its own window and hands back only the answer. A hook can add your open tasks at the start of every session.
When to Use It
The habits we teach, from a single chat up to a codebase:
- Attach the two files that matter instead of the whole folder.
- New topic, new chat. In the same chat, the model keeps weighing the last task's files and decisions while it answers the new one.
- Plant a seed for the next session. Before you close a long session, ask for a short handoff: what's decided, what's open, which files matter. Open the next session with it. /compact does a version of this in place, and you can tell it what to keep.
- Keep CLAUDE.md a router. A short file at the repo root that points to three kinds of doc: conventions (how we write code), architecture (how the system fits together), and runbooks (how to run, deploy, or demo it). The agent opens only what the task needs, which is progressive disclosure.
- Load the rest on a trigger. Claude Code rules in
.claude/rules/load only for the file types you scope them to, so frontend conventions stay out of a database task.
The agent that maintains this site overnight remembers nothing between runs. Each run starts by reading a short decisions file: the edits our reviewers made to its past changes, and the topics they vetoed. These habits are part of our AI training for teams.
Best Practices
Anthropic: Effective context engineering
anthropic.com
Anthropic on curating the context window, and why it beats prompt tweaking for agents.
Chroma: Context rot
trychroma.com
Measures how model performance degrades as the context window fills, across frontier models.
Claude Code docs: How Claude remembers your project
code.claude.com
CLAUDE.md and AGENTS.md files, imports, and rules scoped to file types.