Context Conservation
Rules for maximizing work done per context window. Every token spent on exploration is a token not spent on implementation.
Core Principles
- Grep first, read second — never Read a file blind. Grep for the symbol/pattern, get line numbers, then Read with offset/limit.
- Narrow reads — always use offset/limit. Aim for 10-20 lines around the target, not 100+.
- One read per edit — Read the target lines, Edit them, move on. Don't re-read to verify; the Edit tool confirms success.
- Parallel independent calls — if you need to read 3 files, do it in one message with 3 Read calls.
- No redundant searches — if you already know the file and line from a prior Grep, go straight to Read+Edit.
Tool Selection — Cheapest First
| Need |
Use |
NOT |
| Find a file by name |
Glob |
Explore agent, find, ls -R |
| Find a symbol in code |
Grep (files_with_matches) |
Explore agent, Read + scan |
| Read specific lines |
Read (offset/limit) |
cat, head, full-file Read |
| Simple edit |
Edit |
sed, awk, Write (full rewrite) |
| Repeated pattern edit |
Edit with replace_all: true |
Multiple individual Edits |
When NOT to Use Agents
Don't use Explore/Task agent when:
- You know the file — just Grep + Read directly
- The search is simple — one Grep finds it
- You need < 3 lookups — do them yourself
Do use Explore agent when:
- Truly open-ended search across unknown files
- Need to understand an unfamiliar subsystem
- Would take 5+ Grep/Read rounds to find what you need
When NOT to Invoke Skills
Don't invoke a skill when:
- The task is trivial (e.g., adding one translation key — just edit the files)
- You already know the pattern from memory/context
- The skill document is large and the task is small
Do invoke a skill when:
- Following a multi-step procedure with project-specific gotchas
- The task is complex enough that the skill's checklist prevents mistakes
- You genuinely don't remember the procedure
Read Discipline
BAD: Read(file, offset=1, limit=2000) // entire file, huge context cost
BAD: Read(file) // same — default reads everything
OK: Read(file, offset=350, limit=50) // 50 lines around target
GOOD: Read(file, offset=368, limit=5) // just the lines you need
After a Grep gives line 370, read lines 368-373 (offset=368, limit=6). Not 300-450.
Edit Discipline
- Trust Edit output — it confirms success. Don't Read after to verify.
replace_all: true — for patterns repeated across a file (e.g., renaming a variable). One Edit, not N.
- Include minimal context —
old_string just needs to be unique, not the whole function.
Search Strategy
- Start with
Grep(pattern, output_mode="files_with_matches") — cheapest, just filenames
- If needed,
Grep(pattern, output_mode="content", -n=true) on the specific file — gives line numbers
- Then
Read(file, offset=line-2, limit=10) — surgical read
- Edit and move on
Multi-File Edits
For identical edits across multiple files:
- Grep one file to find insertion point and context
- Read the target lines from ALL files in parallel (one message, N Read calls)
- Edit ALL files in parallel (one message, N Edit calls)
Total: 1 Grep + N Reads + N Edits. Not a skill invocation + exploration.
Anti-Patterns
| Anti-pattern |
Cost |
Fix |
| Explore agent for known files |
~50K tokens |
Direct Grep + Read |
| Full-file Read to find one function |
~5K tokens |
Grep for function name first |
| Reading file before every Edit |
2x reads |
Read once, Edit, trust output |
| Loading large skill for small task |
~3K tokens |
Just do the task directly |
| Re-reading after successful Edit |
Wasted read |
Edit tool already confirms |
| Sequential reads that could be parallel |
Wasted turns |
Batch into one message |
1---2name: context-23description: Context window conservation rules. Invoke when approaching context limits or before large tasks.4---5
6# Context Conservation
7
8Rules for maximizing work done per context window. Every token spent on exploration is a token not spent on implementation.
9
10## Core Principles
11
121. **Grep first, read second** — never Read a file blind. Grep for the symbol/pattern, get line numbers, then Read with offset/limit.
132. **Narrow reads** — always use offset/limit. Aim for 10-20 lines around the target, not 100+.
143. **One read per edit** — Read the target lines, Edit them, move on. Don't re-read to verify; the Edit tool confirms success.
154. **Parallel independent calls** — if you need to read 3 files, do it in one message with 3 Read calls.
165. **No redundant searches** — if you already know the file and line from a prior Grep, go straight to Read+Edit.
17
18## Tool Selection — Cheapest First
19
20| Need | Use | NOT |
21|------|-----|-----|
22| Find a file by name | `Glob` | Explore agent, `find`, `ls -R` |
23| Find a symbol in code | `Grep` (files_with_matches) | Explore agent, Read + scan |
24| Read specific lines | `Read` (offset/limit) | `cat`, `head`, full-file Read |
25| Simple edit | `Edit` | `sed`, `awk`, Write (full rewrite) |
26| Repeated pattern edit | `Edit` with `replace_all: true` | Multiple individual Edits |
27
28## When NOT to Use Agents
29
30**Don't use Explore/Task agent when:**
31- You know the file — just Grep + Read directly
32- The search is simple — one Grep finds it
33- You need < 3 lookups — do them yourself
34
35**Do use Explore agent when:**
36- Truly open-ended search across unknown files
37- Need to understand an unfamiliar subsystem
38- Would take 5+ Grep/Read rounds to find what you need
39
40## When NOT to Invoke Skills
41
42**Don't invoke a skill when:**
43- The task is trivial (e.g., adding one translation key — just edit the files)
44- You already know the pattern from memory/context
45- The skill document is large and the task is small
46
47**Do invoke a skill when:**
48- Following a multi-step procedure with project-specific gotchas
49- The task is complex enough that the skill's checklist prevents mistakes
50- You genuinely don't remember the procedure
51
52## Read Discipline
53
54```
55BAD: Read(file, offset=1, limit=2000) // entire file, huge context cost
56BAD: Read(file) // same — default reads everything
57OK: Read(file, offset=350, limit=50) // 50 lines around target
58GOOD: Read(file, offset=368, limit=5) // just the lines you need
59```
60
61After a Grep gives line 370, read lines 368-373 (offset=368, limit=6). Not 300-450.
62
63## Edit Discipline
64
65- **Trust Edit output** — it confirms success. Don't Read after to verify.
66- **`replace_all: true`** — for patterns repeated across a file (e.g., renaming a variable). One Edit, not N.
67- **Include minimal context** — `old_string` just needs to be unique, not the whole function.
68
69## Search Strategy
70
711. Start with `Grep(pattern, output_mode="files_with_matches")` — cheapest, just filenames
722. If needed, `Grep(pattern, output_mode="content", -n=true)` on the specific file — gives line numbers
733. Then `Read(file, offset=line-2, limit=10)` — surgical read
744. Edit and move on
75
76## Multi-File Edits
77
78For identical edits across multiple files:
791. Grep one file to find insertion point and context
802. Read the target lines from ALL files in parallel (one message, N Read calls)
813. Edit ALL files in parallel (one message, N Edit calls)
82
83Total: 1 Grep + N Reads + N Edits. Not a skill invocation + exploration.
84
85## Anti-Patterns
86
87| Anti-pattern | Cost | Fix |
88|---|---|---|
89| Explore agent for known files | ~50K tokens | Direct Grep + Read |
90| Full-file Read to find one function | ~5K tokens | Grep for function name first |
91| Reading file before every Edit | 2x reads | Read once, Edit, trust output |
92| Loading large skill for small task | ~3K tokens | Just do the task directly |
93| Re-reading after successful Edit | Wasted read | Edit tool already confirms |
94| Sequential reads that could be parallel | Wasted turns | Batch into one message |