Context Management at 1M Tokens
TL;DR: The half-life of superintelligence is about 30 minutes. Claude can be mid-refactor, then start undoing its own work. I hit context limits constantly running multiple instances. Built a TEMP file system with cursor automation that preserves state when the AI forgets.
The half-life of superintelligence is about 30 minutes.
You're halfway through a refactor. Claude is fixing tests. Then suddenly it starts undoing what it just built. You point it out: "Great point!"
It forgot.
I'm running Claude primarily via terminal—usually multiple instances at once. I don't hit context limits occasionally. I hit them constantly.
At 1M tokens, auto-compaction happens. Your detailed context becomes: "The user was working on test refactoring and made good progress."
You lose: which tests you fixed, bug line numbers, established patterns, the mental model you built over three days.
Then you spend 2 hours reconstructing it from git history.
Why This Happens
I'm running Claude via terminal—usually 2-3 instances at once for different parts of the codebase. Each instance has its own 1M token limit.
When you're moving fast:
- Instance 1: Refactoring tests
- Instance 2: Fixing API routes the tests revealed
- Instance 3: Updating docs
All three hit context limits on different schedules. All three forget what they were doing mid-work.
What traditional solutions don't solve:
"Start a fresh chat" — Loses why you made decisions, misses active debugging state
"Document in real-time" — Slows you down, creates doc debt
"Just remember it" — You won't. Multiple parallel threads, dozens of resets. It's impossible.
Prior Art: Advanced Context Engineering
I discovered this isn't a new problem. Advanced Context Engineering for Coding Agents describes the pattern in detail: explicit context preservation through structured state files.
Their approach: comprehensive context snapshots with detailed templates.
What they got right:
- Explicit context preservation vs. hoping AI remembers
- Structured templates for repeatability
- When to create context files (complex multi-day work)
What I added: Automation via Cursor rules and enforcement via security layers.
My Implementation: Automated Context Preservation
The TEMP File System
I use TEMP_SESSION_PROGRESS.md files with two key innovations:
1. Cursor automation — Rules enforce creation when context drops below 10%
2. Security-first — 4-layer system prevents accidental commits
When to Create the File
CREATE when:
- ✅ Context below 10% (~100k tokens remaining)
- ✅ Multi-day projects (testing, migrations, major refactors)
- ✅ Multiple interdependent tasks
- ✅ Critical infrastructure changes
SKIP when:
- ❌ Simple tasks (less than 2 hours)
- ❌ Well-documented features with clear commit trail
- ❌ Purely conversational exchanges
The Template (Simplified)
The file structure:
Header:
- Mission statement (what you're accomplishing)
- Success criteria (what "done" looks like)
Status:
- Progress metrics (started → current → goal)
- What's working (completed items)
- What's blocking (issues + resolution paths)
Configuration:
- Environment references (never paste actual values)
- Project IDs for reference
Next Steps:
- 3 specific actions to take immediately
Verification:
- Commands to check current state
- Quick sanity checks
Example template available in docs/development/CONTEXT_MANAGEMENT.md
The 4-Layer Security System
TEMP files might reference configs. Can't commit them.
Layer 1: .gitignore
TEMP_*.md
*_TEMP.mdLayer 2: Pre-Commit Hook
if git diff --cached --name-only | grep -E "TEMP_.*\.md"; then
echo "🚨 ERROR: Attempting to commit TEMP file"
exit 1
fiLayer 3: CI Check
- name: Check for TEMP files
run: |
if git ls-files | grep -E '^TEMP_.*\.md$'; then
echo "🚨 TEMP files found in repository!"
exit 1
fiLayer 4: Cleanup Script
npm run cleanup:temp
# Shows file age, warns if >24 hours old, prompts to deleteWhy 4 layers? I'll bypass layer 1 ("just this once"). Layer 2 stops me. If I disable hooks, layer 3 catches it. Layer 4 reminds me to clean up.
Real Example: Test Refactoring Across Dozens of Resets
The project: Fix 619 tests (79% → 93.5% passing) by refactoring test architecture. 10 days. 30+ test files. 11 production bugs discovered.
Context resets: Dozens. Multiple terminal instances, each hitting 1M tokens on different schedules.
What the TEMP file captured:
## Status
- Start: 569/619 passing (92%)
- Current: 579/619 (93.5%)
- Found: 10 production bugs (with line numbers)
## Pattern That Works
```typescript
// Mock BEFORE import (critical!)
jest.mock('@clerk/nextjs/server', () => ...);
import { POST } from '@/app/api/webhooks/gmail/route';Next: 01-email-analysis-database-write.test.ts
Context reset? Read the file. Back to work in 2 minutes.
Without it: each reset meant grepping git history, re-learning what pattern worked, figuring out where I was. 30-60 minutes per reset.
Dozens of resets × 30-60 minutes = days of lost time.
The automation saved the project.
## Lessons Learned
### 1. Automation Beats Discipline
Don't rely on remembering to create context files. Cursor rules enforce it when context hits 10%.
### 2. Security Prevents Accidents
I forgot to delete a TEMP file twice. Layer 4 (cleanup script) caught both within 48 hours. Layer 2 (pre-commit hook) blocked three attempted commits.
### 3. Templates Enable Speed
Don't start from scratch. Template fills in 2-3 minutes. AI can generate it with: "Claude, create TEMP file using template from docs, capture current test status and next 3 tasks."
### 4. Context Preservation ≠ Documentation
**Git commits** = permanent changes
**TEMP files** = active session state
TEMP captures work-in-progress. Git captures completed work.
## What to Include
**Always:**
- Current progress metrics
- Blocking issues + resolution paths
- Next 3 specific actions
- Key patterns discovered
**Sometimes:**
- Configuration references (never paste actual values)
- Bug catalog with line numbers
- Verification commands
**Never:**
- Actual credentials/secrets
- Anything you'd commit to git
- Generic progress notes ("making good progress")
## Your Implementation
### Week 1: Set Up Safety
```bash
# Add to .gitignore
echo "TEMP_*.md" >> .gitignore
# Create pre-commit hook (see above)
# Add CI check (see above)
# Add cleanup script
Week 2: Create Template
- Start with simple version (mission, status, next steps)
- Customize for your domain
- Store in
docs/development/CONTEXT_MANAGEMENT.md
Week 3: Practice
- Pick a 2-3 day task
- Create TEMP file at 10% context
- Simulate reset (start fresh chat)
- Did it work? Iterate on what you forgot.
Where I am now
I don't hit context limits 4 times. I hit them constantly.
Running multiple Claude terminal instances for three weeks means dozens of context resets. Each one used to mean lost time reconstructing what I was doing.
Now: cursor automation creates the TEMP file when context drops to 10%. I read it in the next session. I'm back to work in under 5 minutes.
The automation is the only reason this works. I wouldn't remember to create the file manually—I'm usually mid-debug when context resets.
Three weeks in, I can tackle multi-day refactors without fear. The AI forgets. The TEMP file remembers.
Credit where due: Advanced Context Engineering established the pattern. I automated it via Cursor rules and added 4-layer security enforcement to prevent accidental commits.
The unlock: Multi-day complex work is no longer limited by context window size. When the AI's memory fails, the system catches you.
Related: When AI Creates Documentation Faster Than You Can Clean It