Use case · Thinking in Code
My agent opened a 7 MB JSON file and ran out of room. Now a script reads it. The model reads the answer.
With Thinking in Code, your agent writes a short script, the script reads the whole file, and only what it prints or returns reaches the model. One question about a 7 MB JSON file came back as 407 bytes, and data analysis cost 64% less on Claude Haiku 4.5.
Fetch tool: a helper model reads the start of the file.
A helper model reads
- The first 1.4% of the file
Never read
- The other 98.6%
The answer needs the whole file. The agent sees the start.
Shell script: the agent downloads the file and runs its own script.
// the agent writes its own download and script $ curl -s https://registry.npmjs.org/react -o react.json $ node count.js // each command and its output stay in the thread
Every later call sends them again.
Thinking in Code: Context Mode runs the script and keeps only its answer.
Sent to the model
- The version count (2,959), the first and latest stable release, and their dates
Never sent
- The 7 MB file itself
The bill: data analysis, cost per task.
Drawn to scale. Paired runs, 2026-09-29. Correct answers were equal in both arms.
The answer is in the file. The file does not fit.
It hands the first 100,000 characters to a helper model: about 1.4% of the 7,011,585-byte react registry document.
If the agent writes its own download and script, every command and its output stay in the conversation.
Text in the conversation goes back to the model on every later call of the session.
The script reads the file. The model reads the answer.
- 01The agent writes a script
For example: count the versions in the
reactregistry document. - 02Context Mode runs it
Public pages and APIs run in a sandbox. Files on your machine run as your agent's own shell call.
- 03Only the result comes back
The script read 7,011,585 bytes. The model read 407: the version count (2,959), the first and latest stable release, and their dates.
asks about a 7 MB file and writes a short script.
runs the script, which reads all 7,011,585 bytes. It keeps only what the script prints or returns, and checks hosts if Protect is on.
reads the 407-byte answer.
Data analysis, run twice. Lower cost, same answers.
| Long-Context Data Analysis | Context Mode | Direct | Lower, correct answers |
|---|---|---|---|
| Claude Haiku 4.5 | $0.062 | $0.175 | 64% · 11 of 12 correct, both arms |
| Claude Opus 5.5 | $0.201 | $0.223 | 10% · 20 of 20 correct, both arms |
Paired runs on 2026-09-29: questions about the react and express npm registry documents. In earlier runs (2026-09-28), Opus 5.5 going direct often wrote its own script, so the gap is smaller. Method and sources →
What this uses.
The agent writes a script; only its result enters the conversation.
The two tools, the before and after, and why it is safe.
The paired runs, with their data and pre-registration.
Ask about the whole file. Send the model only the answer.
npx @context-mode/cli connects your agents. 1,000 requests free, no card.