Think in Code
Program the analysis instead of reading raw data into the context window.
Every byte a tool returns costs reasoning capacity for the rest of the session. The context window is finite. When you read a 700 KB log into it, you spend 700 KB of that window on bytes you will read once and never reference again — and the model carries that weight through every later turn.
Think in Code flips the default. Instead of pulling data into context, the model writes a small program that processes the data in a sandbox and prints only the conclusion. The raw bytes stay where they are. The window stays free for the actual work.
Program the analysis. Do not compute it by reading. One script can replace ten tool calls.
The cost of reading
Say you need a verdict on a directory of 47 log files. The direct approach reads each file, so all 47 land in the window — easily hundreds of kilobytes of timestamps and stack frames you will scan past. The next several turns inherit that bloat, and the model has less room to reason about anything else.
The Think in Code approach runs one program. It opens all 47 files in the sandbox, computes the aggregates you care about, and returns a few lines of summary. The files never enter context.
Summarize, do not read
const fs = require("fs");
const path = require("path");
const dir = "./logs";
let files = 0;
let totalLines = 0;
let totalBytes = 0;
let errors = 0;
try {
for (const name of fs.readdirSync(dir)) {
const full = path.join(dir, name);
if (!fs.statSync(full).isFile()) continue;
const text = fs.readFileSync(full, "utf8");
const lines = text.split("\n");
files += 1;
totalLines += lines.length;
totalBytes += Buffer.byteLength(text);
errors += lines.filter((l) => /\bERROR\b/.test(l)).length;
}
} catch (e) {
console.log("failed to scan:", e && e.message);
}
console.log(
`files=${files} lines=${totalLines} bytes=${totalBytes} errors=${errors}`,
);Only that final line returns to the model:
files=47 lines=812043 bytes=731220 errors=1396The 47 files contributed 0 bytes to context. The model gets exactly the four
numbers it asked for and keeps the rest of its window for deciding what to do
next. Wrap file access in try/catch and handle null or undefined so a single
unreadable file never aborts the whole pass.
When to reach for it
Any time you would analyze, count, filter, compare, search, parse, or transform data, write code instead of reading the data in. If you are reading a file only to edit it, a plain read is correct — Think in Code is for analysis, where the bytes exist to produce an answer, not to be quoted back.