# Context Engineering — Front-Matter: Front matter - **Source**: /library/Context Engineering/source-file.pdf - **PDF pages**: 1–11 - **Pages without text**: 1 --- Context Engineering: Engineering Information for AI Systems J.C. Ködel Context Engineering: Engineering Information for AI Systems 1. About the author 2. Map of the trilogy 3. How LLMs use context 1. The model only sees the input 2. Attention: how the model weighs what you sent 3. Nothing survives between calls 4. Where the context hides 5. What changes in your practice 4. Tokens and context windows 1. The model reads tokens, not words 2. What tokenization explains as a bonus 3. The context window is the container 4. A big window is no license to fill it 5. Measure it yourself: what travels with a one-line question 6. The yardstick you take from this chapter 5. Memory and limits 1. The chat’s memory is a replay 2. Where the illusion breaks 3. What about the tools that claim to have memory? 4. Work with the memory that exists, not the one you imagine 6. The context cycle 1. The shape of the cycle 2. Where the cycle swells 3. The arithmetic of accumulation 4. Reading a session as a cycle 7. Context rot: why large contexts degrade quality 1. The U-shaped curve: “lost in the middle” 2. Needles, haystacks and the test that became a standard 3. Context rot: degradation in tasks that ought to be trivial 4. Diagnosing rot in your session 8. Token economics: the real cost of bad context 1. How the meter runs 2. Agent scale: the multiplier nobody budgets for 3. Do the math yourself 9. Parametric calculation: cost of irrelevant context 1. What to measure tomorrow morning 2. Quality and cost are the same bug 0. Prompt engineering vs context engineering: why the prompt became a second-order variable 1. What prompt engineering really solves 2. The same prompt, opposite results 3. The discipline that takes its place 4. The objections that deserve an answer 5. Where the right context comes from 11. Specifications 1. What a spec carries 2. Examples are the part the model understands best 3. The waterfall objection 2. Living documentation 1. The document that describes the present 2. “All docs rot, so why write them?” 3. What each artifact answers 13. ADRs 1. A record for the why 2. “ADRs are bureaucracy” 3. Three artifacts, three questions 4. Conventions 1. Fewer decisions per task 2. The conventions document 3. Conventions that run in CI 4. Where each kind of information lives 15. Persistent context files 1. The shortcut and what it costs 2. Anatomy of a file that works 3. Anti-patterns, and where each line goes instead 4. “It turns into a dump and nobody maintains it” 6. Project organization 1. The context source you do not write 2. What the technical tree screams 3. What the feature tree screams 17. Modularization 1. Parnas’s criterion 2. Deep modules, small surface 3. A public surface is not the interface keyword 4. Boundary lines across VilaSchedule’s tree 5. “Too much ceremony for a system this size” 8. Context for brownfield projects 1. Step 1: structure and names 2. Step 2: git archaeology 3. Step 3: AI-guided reading 4. Step 4: generating the artifacts incrementally 9. Context layers 1. A layer is a lifetime, not a folder 2. The layers of a session 3. The same session, annotated by layer 4. What the layers let you decide 5. “This is bureaucracy for a twenty-minute session” 0. Context packing 1. Packing is choosing the minimum, and choosing means saying no 2. The inventory of the bloated packet 3. The window is not uniform 4. Four questions that assemble the packet 5. The same request, packed 6. “If I forget the right file, it will make something up” 7. What the packet cannot carry 21. Context recovery 1. Recovery is reassembling what had no address 2. Recovery is not prevention 3. The routine I use to restart a task 4. The state note 5. The two restarts, side by side 6. “In 2026 the agent handles it on its own” 7. Not everything that came back is still true 2. Context validation 1. Checking a belief is not validating input 2. Two ways to state what is not so 3. The statement, the check and the repair 4. The checklist I run 5. When the check fails 6. “If I have to check everything, what is the AI for?” 7. What is left of the check when the history shrinks 3. Context compression 1. Compressing is choosing what is left 2. What a summary optimizes for 3. The anchors you write beforehand 4. “Then turn automatic summarization off” 5. What this chapter assumes is in place 6. One window, one task 4. Context isolation 1. One context per task 2. When splitting is worth the coordination cost 3. Thursday, split again 4. The subtask contract 5. Two subtasks at once, each on its own ground 6. “The subagent loses sight of the whole” 7. “Re-explaining the context to each one is expensive” 8. The packet that fits in no window at all 5. RAG vs direct context 1. Fetching the passage when the question comes up 2. Size, mutability and how each task uses it 3. Embedding is the default until it hurts 4. “RAG retrieves the wrong passage” 5. “Chunking fragments meaning” 6. The column the search does not answer 6. MCP and tools as dynamic context 1. Information you do not read but ask for 2. The name this has in 2026 3. The definition is what the model reads 4. Every tool is context paid for before the question 5. When the data calls for a tool 6. “That is a whole integration to read four times” 7. “And when the tool is down?” 8. What the three decisions still do not say 7. Context security and trust 1. The window has one voice 2. The attack has a name and a test 3. Privilege is granted per tool, not per trust 4. Provenance is origin plus authority 5. The packet is an exposure surface 6. “A good model already resists this” 8. Where to start 9. Development loops with AI 1. Technique is not cadence 2. Pack, run, validate, distill 3. Where recovery comes in 4. One turn on Thursday 5. Calibrate without breaking it 6. “That is ceremony for a ten-minute task” 7. Two weeks later, the same feeling 0. Measuring context: how to evaluate whether your context improves results 1. “Evaluating that is work for a machine learning team” 2. What counts as right the first time 3. Thirty seconds per turn 4. The number on its own decides nothing 5. Two counts that fit in the same file 6. “Fifteen turns prove nothing” 7. Your rate and the team’s 31. Principles applied: chat, IDE, terminal and CI 1. Four questions before any configuration 2. The map of July 2026 3. Chat assistant: the context lives outside the repository 4. IDE agent: the context lives next to the code 5. Terminal agent: the context lives in directory layers 6. Agent in CI: nobody there to correct course 7. One source, four projections 8. “This will age the same way” 9. The context that never leaves your laptop 2. Teams: context as a repository asset 1. What belongs to the repository 2. One owner per artifact 3. An agent’s first day 4. “Nobody is going to maintain this” 5. What happens when all of this meets a project 33. Preparing a project (from scratch and from a legacy system) 1. A caveat about the tool 2. The path from scratch: three files and a tree 3. The legacy path: a packet that shows its evidence 4. How to know the packet is ready 4. A complete AI-guided implementation 1. Session 1: the skeleton, and three sentences that paid for the session 2. Session 2: five statements, three checks and a defect that was not a statement 3. Session 3: the window fills up, and what is left is not what you think 4. Session 4: the same task resumed twice 5. Session 5: the slice that left the main window 6. What the five sessions add up to 5. Post-mortem: where the context failed and how it was recovered 1. The delivery that came back incomplete and said nothing 2. The decision nobody made out loud 3. The reason that died with the session 4. The packet that was wrong 5. The boundary drawn halfway 6. The rule nobody enforced 7. What each failure cost 8. The legacy system as counterpoint 9. Post-mortem script 6. References 1. Papers and articles 2. Vendor documentation and publications 3. Other sources