Token Efficiency Encyclopedia

Output Spooling to Disk

A test suite prints 40,000 lines and fails on one of them. Run it directly and the whole dump enters the transcript, where it stays for the rest of the session and is re-sent on every subsequent turn. Spool it — pytest > /tmp/test.log 2>&1; tail -30 /tmp/test.log — and the context holds thirty lines, while the other 39,970 remain on disk, available to grep if they ever turn out to matter.

The asymmetry that makes this worth a rule: a tool result cannot be taken back. The agent chooses, before running the command, whether its output will be resident for the remainder of the session. There is no un-print.

Principle

Send verbose output to a file and read a deliberate slice of it. The file system is a context extension with zero token cost and full random access; the transcript is a write-once log that is re-read on every turn.

Why the Cost Is Not What It Looks Like

A 40,000-line dump is not a one-time charge. With T turns remaining in the session, it is charged T more times, minus whatever prompt-cache discount applies. The naive reading — "one big tool result, one big cost" — understates it by a factor of the remaining session length, which is exactly why the habit survives: the damage is invisible at the moment it is done.

Spooling also preserves what truncation destroys. A tool result clipped by the harness at some line limit loses the tail permanently; a spooled file loses nothing, because the bytes are still on disk under a path the agent knows.

Techniques

Redirect and Tail

The default move for any command whose output is unbounded: builds, test runs, installers, container logs, data dumps. Read the last N lines, which is where failures usually surface, and go looking only if that is not enough.

Query Instead of Read

Once the output is a file, it is searchable. grep -c, grep -n FAIL, awk over the summary line: the agent extracts the answer it actually needs — a count, a first failure, an exit status — rather than re-reading the material to find it. See Grep-Result Tool Output.

Exit Code First

Most of the time the question is "did it pass?", and the exit code answers it in one token. Read the log only on failure. See Fail Fast Validation.

Filter at the Source

| tail -30, --quiet, -q, --reporter=dot, 2>/dev/null: many tools can simply be told to say less. Cheaper than spooling, when available, because nothing has to be written or re-read.

Intermediate Artifacts Stay on Disk

Output that is only an input to the next command — a generated file, a JSON dump about to be queried, a diff about to be applied — never needs to pass through the context. The same logic on the generation side is Write-Path Delegation.

Trade-offs

Anti-patterns

See Also

Tools