The LLM writes the script. The script processes the data. You read only the result.
Your agent just read 50 TypeScript files to count lines. That's 700KB of context gone on something a 3-line script handles in 3KB.
Sound familiar?
- Agent wants to
cat package-lock.json(58,000 lines) to find one dependency - Agent reads entire
access.log(5,000 lines) to count unique IPs - Agent issues 47
Read()calls to understand dependency frequency - Context window fills up → compaction triggers → agent forgets what it was doing
Every time an agent reads data into context to process it, you pay a 100-700x context tax.
Think in Code is a mental model shift + pattern catalog that trains your agent to:
- STOP reading data into context to process it
- START writing one-shot scripts that process it
- READ ONLY the result (3KB vs 700KB)
❌ Anti-pattern:
Read src/auth.ts → Read src/user.ts → Read src/admin.ts → ... (47 more)
Cost: ~700 KB context
✅ Think-in-code:
ctx_execute("bash", `find src -name '*.ts' -exec wc -l {} + | sort -rn | head -20`)
Cost: ~1 KB output
Savings: 700x
| Task | Raw Read | Script Output | Savings |
|---|---|---|---|
Count lines in 50 .ts files |
700 KB | 1 KB | 700x |
| Find dependency in package-lock.json | 58 KB | < 1 KB | 58x |
| Analyze 5000-line access.log | 50 KB | 2 KB | 25x |
| Build dependency frequency map (20 files) | 300 KB | 3 KB | 100x |
| Extract config values from 5 files | 15 KB | < 1 KB | 15x |
Average savings: 50-700x.
# Option 1: Clone directly
git clone https://github.com/aptratcn/skill-think-in-code.git ~/.agent-skills/skill-think-in-code
# Option 2: npx install (skills.sh registry)
npx skills@latest add aptratcn/skill-think-in-code
# Option 3: Add to AGENTS.md (recommended)
echo "## Think in Code\nBefore reading data files: Can a script do this? See ~/.agent-skills/skill-think-in-code/SKILL.md" >> AGENTS.mdWorks automatically when the agent recognizes patterns:
Agent: "I need to read package-lock.json to find react version..."
→ Skill activates → Writes script → Reads 3-line result
Or explicitly:
"Use think-in-code to find the top 10 most-used dependencies in this project"
# Find dependencies with vulnerabilities
cat package-lock.json | python3 -c "
import json, sys
data = json.load(sys.stdin)
for name, info in data.get('packages', {}).items():
if 'vulnerability' in str(info):
print(name, info.get('version', 'unknown'))
"# Top 20 IPs by request count
awk '{print $1}' access.log | sort | uniq -c | sort -rn | head -20
# Top 20 404 paths
grep "404" access.log | awk '{print $7}' | sort | uniq -c | sort -rn | head -20# Most imported modules across project
grep -rn "import\|require" src/ --include="*.ts" | \
sed 's/.*import.*from //;s/.*require(//' | \
tr -d "'\";" | sort | uniq -c | sort -rn | head -30# Key values from multiple configs (one shot)
echo "=== TypeScript ===" && grep -A2 "compilerOptions" tsconfig.json && \
echo "=== ESLint ===" && grep "extends\|plugins\|rules" .eslintrc.js && \
echo "=== Jest ===" && grep "testMatch\|coverage" jest.config.ts| Situation | Why |
|---|---|
| Understanding code architecture | Need full context for mental model |
| Code review | Need to see patterns, not just data |
| Writing new code | Need to learn existing patterns |
| Debugging logic flow | Need to understand the code path |
Rule: If you're reading to UNDERSTAND, read. If you're reading to PROCESS, script it.
skill-think-in-code/
├── SKILL.md # Full skill instructions (6.8 KB)
├── README.md # This file
├── LICENSE # MIT
└── references/
├── patterns.md # 20+ script patterns catalog
└── examples.md # Real-world usage examples
| Skill | What It Does |
|---|---|
| skill-audit | Security scanner — audit before install |
| prompt-guard | Runtime prompt injection defense |
| token-optimizer | Output compression (~75% reduction) |
| context-doctor | Diagnose context bloat sources |
Inspired by context-mode (11,693 stars, +2,332 this week) — the MCP server that sandboxed tool output.
This skill is the pure markdown version: no npm, no MCP, no dependencies. Just copy the mental model and script patterns into your agent's behavior.
Same 700x savings. Zero install complexity.
MIT — Use freely, improve freely, share freely.
Stop reading. Start scripting. Your context window will thank you. 🧠
⭐ If this skill saved you from a context overflow, consider giving it a star!