|
| 1 | +--- |
| 2 | +name: deep-context |
| 3 | +description: > |
| 4 | + 1M context window behavioral rules. MUST consult before any file reading, code editing, |
| 5 | + or subagent delegation decision. Applies to every task in Opus 4.6 sessions. Governs: |
| 6 | + whole-file reading (never use offset/limit for files under 4000 lines), direct reading |
| 7 | + over subagent delegation, pre-loading dependencies before edits, avoiding redundant |
| 8 | + re-reads, parallel file reads, and deep-context planning for complex multi-file tasks. |
| 9 | + Triggers on: read, edit, explore, debug, refactor, implement, investigate, fix, build, |
| 10 | + create, modify, change, update, add, review, analyze, understand. |
| 11 | +--- |
| 12 | + |
| 13 | +# Deep Context: 1M Token Context Rules |
| 14 | + |
| 15 | +You have a 1M token context window. A 500-line file costs ~0.1% of your context. The cost of *not* reading is almost always higher than the cost of reading. These rules override conservative behaviors optimized for smaller-context models. |
| 16 | + |
| 17 | +## Baseline Rules (Always Active) |
| 18 | + |
| 19 | +### Rule 1: Whole-File Reading |
| 20 | + |
| 21 | +Read entire files by default. Only use `offset`/`limit` when: |
| 22 | +- The file exceeds 4000 lines, OR |
| 23 | +- You have already identified the exact section you need and have previously read the full file |
| 24 | + |
| 25 | +For files between 2000-4000 lines, use two parallel Read calls (first half + second half) to load the complete file. |
| 26 | + |
| 27 | +A 500-line file is ~0.1% of your context. Partial reads cost more in missed connections than they save in tokens. |
| 28 | + |
| 29 | +### Rule 2: Direct Read Over Delegation |
| 30 | + |
| 31 | +Use Glob/Grep to find files, then Read them directly into your own context. Only delegate to subagents when: |
| 32 | +- The search space is genuinely unknown and broad |
| 33 | +- You need to explore 10+ files to find the right ones |
| 34 | +- The task is truly independent and parallelizable |
| 35 | + |
| 36 | +**The test:** "Would I lose important nuance by reading a summary instead of the source?" If yes, read it yourself. |
| 37 | + |
| 38 | +### Rule 3: Read Before Edit |
| 39 | + |
| 40 | +Before editing any file, read its immediate dependency graph: |
| 41 | +1. The target file itself (full read) |
| 42 | +2. Its imports and dependencies |
| 43 | +3. Files that import or reference it (callers/consumers) |
| 44 | +4. Its test files |
| 45 | +5. Config files that reference it |
| 46 | + |
| 47 | +Never start an edit without understanding what your change touches. |
| 48 | + |
| 49 | +### Rule 4: No Redundant Reads |
| 50 | + |
| 51 | +Trust your context. If you read a file earlier in this conversation, reference what you already know. Only re-read if: |
| 52 | +- The file was modified since you last read it (by you or a tool) |
| 53 | +- You explicitly need to verify current state after an edit |
| 54 | + |
| 55 | +Do not re-read files "just to be sure." |
| 56 | + |
| 57 | +### Rule 5: Parallel Reads |
| 58 | + |
| 59 | +When you need multiple files, read them all in a single parallel tool call. Never issue sequential Read calls for independent files. |
| 60 | + |
| 61 | +**Wrong:** |
| 62 | +``` |
| 63 | +Read(file_a.py) |
| 64 | +# wait |
| 65 | +Read(file_b.py) |
| 66 | +# wait |
| 67 | +Read(file_c.py) |
| 68 | +``` |
| 69 | + |
| 70 | +**Right:** |
| 71 | +``` |
| 72 | +Read(file_a.py) | Read(file_b.py) | Read(file_c.py) # single parallel call |
| 73 | +``` |
| 74 | + |
| 75 | +## Deep-Context Mode (Complex Tasks) |
| 76 | + |
| 77 | +Activate this planning phase when ANY of these apply: |
| 78 | +- Task touches 3+ files |
| 79 | +- Task involves debugging or investigating unexpected behavior |
| 80 | +- Task is a new feature or significant refactoring |
| 81 | +- Task crosses module/package boundaries |
| 82 | +- User explicitly requests deep analysis |
| 83 | + |
| 84 | +### Step 1: Scope the File Graph |
| 85 | + |
| 86 | +Use Glob and Grep to identify all files relevant to the task. Map what imports what, what tests what, what configs reference what. This is a *search* phase -- use lightweight tools, don't read files yet. |
| 87 | + |
| 88 | +### Step 2: Load Strategically |
| 89 | + |
| 90 | +Read files in priority order, using parallel batches: |
| 91 | + |
| 92 | +1. **Primary targets** -- files being modified |
| 93 | +2. **Direct dependencies** -- imports, base classes, interfaces |
| 94 | +3. **Callers/consumers** -- files that reference the targets |
| 95 | +4. **Tests** -- existing test files |
| 96 | +5. **Config/docs** -- manifests, READMEs, config files |
| 97 | + |
| 98 | +For a typical task: 5-15 files in 2-3 parallel batches. |
| 99 | + |
| 100 | +### Step 3: Execute with Full Context |
| 101 | + |
| 102 | +Implement the change with the full picture loaded. No mid-task "let me check..." reads -- you should already have what you need. |
| 103 | + |
| 104 | +Briefly tell the user what you loaded: "Loaded X, Y, Z to understand the full picture." |
| 105 | + |
| 106 | +## Anti-Patterns |
| 107 | + |
| 108 | +### "Let me check that with a subagent" |
| 109 | +**Wrong:** Spawning an Explore agent to find and summarize code you could read directly. |
| 110 | +**Right:** Glob for the pattern, Read the matches yourself. |
| 111 | +**Exception:** Genuinely broad research across 10+ unknown files. |
| 112 | + |
| 113 | +### "Let me read lines 1-50 first" |
| 114 | +**Wrong:** `Read(file, offset=0, limit=50)` to "peek" at a file. |
| 115 | +**Right:** `Read(file)` for files under 4000 lines. |
| 116 | + |
| 117 | +### "Let me read this file again" |
| 118 | +**Wrong:** Re-reading a file already in your context. |
| 119 | +**Right:** Reference your existing knowledge. Re-read only if the file was modified. |
| 120 | + |
| 121 | +### "I'll start coding and figure out imports later" |
| 122 | +**Wrong:** Editing before reading dependencies. |
| 123 | +**Right:** Read target + imports + tests + callers, then edit. |
| 124 | + |
| 125 | +### "I'll read these files one at a time" |
| 126 | +**Wrong:** Sequential Read calls for independent files. |
| 127 | +**Right:** Batch all independent reads into one parallel tool call. |
| 128 | + |
| 129 | +## Context Budget Awareness |
| 130 | + |
| 131 | +Use these heuristics to gauge context pressure and shift strategy: |
| 132 | + |
| 133 | +| Signal | Strategy | Behavior | |
| 134 | +|--------|----------|----------| |
| 135 | +| **Early session** (few files, short conversation) | Aggressive | Load everything potentially relevant. Read whole files freely. | |
| 136 | +| **Mid session** (10-20 files loaded, several tasks done) | Selective | Focus on files directly touched by the current task. | |
| 137 | +| **Heavy session** (30+ files, long conversation, compaction warnings) | Deliberate | Only read what's strictly needed. Prefer Grep for quick lookups. | |
| 138 | +| **Approaching limit** (compaction occurred, system pressure signals) | Conserve | Stop loading new content. Work with what you have. Suggest new session. | |
| 139 | + |
| 140 | +## Guardrails |
| 141 | + |
| 142 | +- **Don't read blindly.** "Read aggressively" does not mean "read the whole repo." Have a reason for each file. |
| 143 | +- **Match scope to task.** "Fix this one line" doesn't need the entire module graph loaded. |
| 144 | +- **Communicate loading.** When entering deep-context mode, tell the user what you're loading and why. |
0 commit comments