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.

How many versions of react are on npm?

Fetch tool: a helper model reads the start of the file.

The file7,011,585 B
A helper model sees100,000 chars

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.

The script reads7,011,585 B
The model reads407 B

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
Long-Context Data Analysis · Claude Haiku 4.5$0.175 → $0.06264% lowerlower in 12 of 12 pairs

The bill: data analysis, cost per task.

Haiku 4.5, direct$0.175
Haiku 4.5, Context Mode$0.062
Opus 5.5, direct$0.223
Opus 5.5, Context Mode$0.201

Drawn to scale. Paired runs, 2026-09-29. Correct answers were equal in both arms.

The problem

The answer is in the file. The file does not fit.

The fetch tool sees the start

It hands the first 100,000 characters to a helper model: about 1.4% of the 7,011,585-byte react registry document.

A shell script fills the thread

If the agent writes its own download and script, every command and its output stay in the conversation.

You pay again on each turn

Text in the conversation goes back to the model on every later call of the session.

How it works

The script reads the file. The model reads the answer.

  1. 01The agent writes a script

    For example: count the versions in the react registry document.

  2. 02Context Mode runs it

    Public pages and APIs run in a sandbox. Files on your machine run as your agent's own shell call.

  3. 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.

1 · Your agent

asks about a 7 MB file and writes a short script.

2 · Context Mode

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.

3 · The model

reads the 407-byte answer.

The file never enters the conversation. The model reads only what the script prints or returns.
Proof

Data analysis, run twice. Lower cost, same answers.

64% lowercost per task on Claude Haiku 4.5, $0.175 to $0.062, 12 of 12 pairs
407 bytesreached the model from a 7,011,585-byte file: one measured query, not a benchmark figure
$113 lessper 1,000 data-analysis tasks on Haiku 4.5
Long-Context Data AnalysisContext ModeDirectLower, correct answers
Claude Haiku 4.5$0.062$0.17564% · 11 of 12 correct, both arms
Claude Opus 5.5$0.201$0.22310% · 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 →

Products used

What this uses.

Thinking in Code

The agent writes a script; only its result enters the conversation.

How saving works

The two tools, the before and after, and why it is safe.

Benchmarks

The paired runs, with their data and pre-registration.

Related

Context Saving · Cut agent spend · For developers

Ask about the whole file. Send the model only the answer.

npx @context-mode/cli connects your agents. 1,000 requests free, no card.

Get started free

Your coding agent costs less and remembers your project.

Start free: 1,000 requests, every feature, no card. After you sign in, the console gives you one command to connect Claude Code or Codex.

Read the docs