The Research Report
How a Tiny 8B Model Matched GPT-5 — With a Python REPL
The context window wars are over. We just didn't know it yet.
MIT researchers dropped a paper on New Year's Eve that changes everything we thought we knew about long-context AI. An 8 billion parameter model — small enough to run on a MacBook — matched GPT-5's performance on complex long-context tasks. The trick wasn't a bigger model or a longer context window. It was a Python REPL.
Here's how it works and why you should care.
The Print Contract
Every coding agent hits the same wall. Turn 20 rolls around and the conversation is bloated with raw data. File contents. API responses. Query results. All of it sits in the context window forever. The model forgets why it started.
The solution is something the researchers call the "print contract." Raw data stays in Python variables. Only print() output enters the context. The model processes everything inside a persistent REPL session and surfaces only summaries.
Think of it like this:
Without the print contract: An agent analyzes 142 TypeScript files. Each file read dumps its contents into context. By turn 4, the model has 2000+ lines of raw output to sift through. It loses the thread.
With the print contract: The agent writes a Python script that processes all 142 files inside the REPL. Variables survive across turns. Only one line enters context: "142 TypeScript files across 23 directories, with the heaviest concentration in src/capabilities (18 files)."
The model never forgets. Because it never had to remember the raw data in the first place.
How the RLM Paper Did It
The Recursive Language Models paper from Zhang, Kraska, and Khattab at MIT introduced a framework that treats prompts as variables, not context.
Here's the loop:
- Load the user's prompt into a Python REPL as a string variable
- Give the root model only the query, the prompt length, and a prefix
- The model writes code to peek, slice, or grep the variable
- Executed code runs in the REPL
- Truncated stdout appends to the model's context
- Repeat until the model calls FINAL(answer)
The model never sees the full input. It sees metadata and writes code to interact with the data programmatically. For tasks requiring full coverage, the model chunks the input and recursively calls itself on each piece.
The results are striking. RLM(Qwen3-8B) — an 8B parameter model fine-tuned on just 1,000 samples — improved 28.3% over the base model and approached GPT-5 quality on three of four long-context benchmarks.
On OOLONG-Pairs, a task requiring quadratic-complexity reasoning over 32K tokens, vanilla GPT-5 scored less than 0.1%. The RLM version scored 58%.
The Persistent REPL Problem
The original RLM paper had one limitation. Each turn started fresh. The REPL session didn't persist across interactions. If you were analyzing a codebase across ten turns, you re-loaded the data every time.
A team at Knot0 fixed this.
They built repl-scratchpad, an open-source extension that makes the REPL persistent across turns using tmux. Variables survive. Data stays loaded. The model picks up exactly where it left off.
The mechanism is simple:
- Agent writes Python code to a temp file
- Code executes in a persistent tmux-backed Python REPL
- Variables survive across turns
- Only print() output enters the conversation context
- Everything else stays in the scratchpad's memory
Now the print contract works across an entire session. Not just a single turn.
Why This Matters for Small Models
Frontier labs are racing to 10 million token context windows. Google ships 2 million tokens with Gemini. Anthropic offers 200K standard with 1M in beta. GPT-5.2 pushes to 400K.
The assumption is that bigger windows solve the long-context problem. But there's a fundamental issue: transformers degrade on long inputs regardless of window size. Attention gets diluted. The model loses track of details buried in the middle.
The RLM approach flips the script. Don't make the window bigger. Make the model smarter about what it looks at.
An 8B model with a 32K context window can now process million-token inputs by recursively chunking and sub-calling. You don't need a 128K or million-token context window. You need a model that can write code and follow a loop.
The Cost Story
On BrowseComp+ — a benchmark with 6-11M token inputs — RLM(GPT-5) cost a median of $0.99 per query versus $1.50-$2.75 for naive approaches that try to stuff everything into context.
For local models, the cost is just electricity and time. An 8B model needs about 16GB of RAM at full precision. Quantized variants cut that in half. Go further with 4-bit GGUF and you're running in 6-8GB on consumer hardware.
The tradeoff is latency. Recursive sub-calls are sequential. A complex task might make 20-30 sub-calls, each requiring a full inference pass. On a local 8B model, that's minutes, not seconds.
For batch processing and background pipelines, the latency is a non-issue. For interactive chat, it's a real constraint. But I'd rather have a slow correct answer than a fast wrong one from a model that lost track of what it read 50K tokens ago.
Setting Up a Persistent REPL
The repl-scratchpad tool works with Claude Code, OpenAI Codex, Gemini CLI, Cursor, GitHub Copilot, and any tool supporting the Agent Skills open standard.
Install it:
git clone https://github.com/knot0-com/repl-scratchpad.git ~/.claude/skills/repl-scratchpad
Then activate it:
/repl-scratchpad
"Start a scratchpad session"
"Use the REPL to analyze these files"
The skill triggers when you ask your agent to use the scratchpad. Variables persist across turns. Raw data stays out of context. Only summaries surface.
What This Changes
The RLM paper and repl-scratchpad together represent a shift in how we think about model capabilities.
Small models get long-context superpowers. An 8B model can now handle tasks that previously required frontier models with massive context windows. The playing field levels.
Context engineering beats context stuffing. The field is moving from "how much can we fit in the window" to "how smart can we be about what we look at." This is the context engineering mindset.
The architecture is model-agnostic. The same REPL loop works with OpenAI, Anthropic, local models via vLLM, or any backend. Swap the model without changing the inference logic.
Prime Intellect — which built RLM training infrastructure — predicts this will be "the paradigm of 2026." Their argument: RLM-native training, where models learn to recursively reason from the ground up, will unlock capabilities we haven't seen yet.
The 8B result is just the beginning.
Citations
- Zhang, A., Kraska, T., & Khattab, O. "Recursive Language Models." arXiv:2512.24601, December 2025. https://arxiv.org/abs/2512.24601
- Zhang, A. "Recursive Language Models." Blog post, 2025. https://alexzhang13.github.io/blog/2025/rlm/
- Knot0. "repl-scratchpad: Persistent REPL scratchpad for coding agents." GitHub, 2025. https://github.com/knot0-com/repl-scratchpad
- DoDataThings. "Recursive Language Models: How to Process Infinite Context With an 8B Model." 2025. https://dodatathings.dev/blog/recursive-language-models
- Introl. "Recursive Language Models: Teaching AI to Manage Its Own Context." 2026. https://introl.com/blog/recursive-language-models-rlm-context-management-2026
- rlm.md. "Recursive Language Models." https://rlm.md/
- Prime Intellect. "Recursive Language Models: the paradigm of 2026." January 2026. https://www.primeintellect.ai/blog/rlm
Suggested Title
How a Tiny 8B Model Matched GPT-5 — With a Python REPL
Alternative: The Print Contract: How Small Models Outperform Giants on Long Context
Word Count
1,487 words (body text only)
Fact-Check Notes
- The RLM paper shows RLM-Qwen3-8B approaching GPT-5 quality on three of four tasks. This is a fair characterization based on the paper's results, but "approaching" leaves room for interpretation. The paper shows the 8B model getting within single-digit percentage points on some benchmarks.
- The 28.3% improvement figure for RLM-Qwen3-8B over base Qwen3-8B comes directly from the paper abstract.
- The OOLONG-Pairs benchmark result (GPT-5 <0.1% vs RLM 58%) is from the rlm.md summary site and Alex Zhang's blog. These are credible sources but not the primary paper.
- The $0.99 vs $1.50-$2.75 cost comparison for BrowseComp+ comes from the DoDataThings blog post, which cites the paper.
- The repl-scratchpad tool's "14+ coding agents" claim comes from their GitHub README. I haven't independently verified compatibility with all 14.
- Prime Intellect's "paradigm of 2026" prediction is a direct quote from their blog post.