Disclosure: this study was designed and run by the team that builds HeyBrain. No model vendor sponsored or reviewed it. Full disclosure.
How much context does long-term memory save? Measuring HeyBrain on LongMemEval-S, SWE-bench and multi-session coding projects
Chat assistants and coding agents answer from whatever sits in their context window, and their vendors document that agent tools re-send the conversation on every request. A retrieval memory layer can replace that history with a short set of relevant passages. We measure how many input tokens this saves and what it costs in accuracy, using HeyBrain, a hybrid retrieval memory service, against a baseline that keeps the full history in context. On LongMemEval-S (500 questions, median 48 past sessions per question), HeyBrain cut the input per question by a median of 92.3%, from about 168,000 to 13,000 tokens as billed for Claude Sonnet 5.5. The saving costs some accuracy. With Claude Sonnet 5.5 as the reader on all 500 questions, HeyBrain answered 90.0% correctly against 95.0% for the full history (−5.0 points, 95% CI −7.6 to −2.6, exact McNemar p < 0.001), at about one-twelfth of the reader cost at uncached list prices (about one-quarter when the prompt is already cached). Across six current readers from Anthropic and OpenAI, HeyBrain scored 87.8% to 93.2% on all 500 questions, and on a stratified 48-question sample it trailed the full history by 2 to 4 points on five readers and led on one. Most of the gap is in questions that combine several past sessions. An ablation shows that accuracy depends on keeping every answer-bearing passage: trimming evidence to a fixed top four passages saved a further 39% of tokens but lost 3.2 points (p = 0.004), while raising the budget from 40,000 to 80,000 characters recovered most of the gap (93.0% vs 95.0%, p = 0.11) and still sent 85% fewer tokens. On the same 100 questions, the saving was 57% with five past sessions and 92% with fifty. In a separate experiment with Claude Code on 20 SWE-bench Lite tasks, a memory brief carried between sessions produced no consistent token saving and the same task success (16/20 vs 15/20). A pilot with Claude Code and OpenAI Codex over chains of four issues found the same: neither a notes file the agent keeps nor a HeyBrain search tool reduced coding tokens, and the notes file cost about a third more on both agents. In a pre-registered study across multi-session coding projects, the picture changes: without memory, both agents broke earlier decisions in almost every later session (kept in 1 and 2 of 36), while a HeyBrain brief injected at session start kept them in 33 (Claude Code) and 36 (Codex) of 36. Each agent's own resume, run while its prompt cache was warm, kept about as many decisions (35 and 36) and was the cheaper way to keep them: the brief cost 38% more than resume on Claude Code and 172% more on Codex. In those sessions no notes, tool or brief arm had a lower median cost than starting with nothing, and on 30 interrupted SWE-bench Verified tasks we detected no change in the cost of finishing or the success rate with any notes, tool or brief arm. Savings grow with history length; with two or three past sessions (estimated) and on small coding tasks we found none.
Key results
fewer input tokens per memory question (median, 500 questions). Same result with the Claude and OpenAI tokenizers and with all six readers tested.
accuracy vs full history with Sonnet 5.5 on all 500 questions (95.0% vs 90.0%, significant), at one-twelfth of the reader cost at uncached list prices, about one-quarter when the prompt is already cached.
HeyBrain accuracy across six readers (Fable 5.2, Opus 5.5, Sonnet 5.5, Haiku 5.5, GPT-6.2 Astra, GPT-6.2 Sol), all 500 questions.
accuracy and token saving with an 80,000-character evidence budget, against 95.0% for the full history (difference not significant, p = 0.11).
input tokens saved as the history grows from 5 to 50 past sessions (same 100 questions, measured).
accuracy when every answer passage was retrieved vs when one was missing. Coverage, not budget, drives quality.
earlier project decisions kept by Codex with a HeyBrain brief vs a fresh session. Its own resume also kept 36, and the brief cost 172% more than resume on a warm cache.
decisions kept by Claude Code with the brief vs fresh. Its own resume kept 35, and the brief cost 38% more than resume on a warm cache.
token saving from any memory over a fresh session: on small SWE-bench Lite tasks, in the pilot, and when finishing 30 interrupted SWE-bench Verified tasks.
1. Introduction
Long conversations are expensive because models are stateless: each request carries the context the model needs. Anthropic's documentation states that "Claude Code sends your full conversation with every request".3 OpenAI describes the same property for the Codex agent loop: "as the conversation grows, so does the length of the prompt".6 The Claude API documentation describes input that contains all previous conversation history.4
A memory layer changes what is sent. Instead of the whole history, the model receives a few retrieved passages. This saves tokens only if the passages are much smaller than the history, and it is useful only if accuracy holds. We test both, and we report where the approach does not help.
We ask three questions. (Q1) How many input tokens does retrieval save on a long-term memory benchmark, across tokenizers? (Q2) What happens to answer accuracy? (Q3) Does a memory brief or memory tool reduce what a coding agent spends when it resumes work in a new session?
2. Systems and baseline
- Full-history baseline. The complete chat history and the question are placed in the reader's prompt. This is the upper bound of what an assistant could see without memory.
- HeyBrain. Past sessions are indexed. At question time a hybrid retriever (lexical plus vector search) returns ranked passages up to a budget of 40,000 characters, typically 12 to 13 passages. Only these passages and the question go to the reader. The same reader, prompt template and judge are used in both arms.
What we do not compare. Claude and ChatGPT both offer built-in memory. Anthropic states that memory is on by default for its individual plans,5 and OpenAI states that ChatGPT "looks for relevant context when it is likely to improve a response".7 Neither discloses how many tokens these features add to a request, so we make no claim about them in either direction. All comparisons in this report are against the full history.
3. Experiment 1: memory questions on LongMemEval-S
3.1 Data
LongMemEval-S1 contains 500 questions, each paired with a chat history that holds the answer somewhere in its past sessions. Histories have a median of 48 sessions and 491 turns. Questions span six types (single-session user, single-session assistant, single-session preference, multi-session, knowledge update, temporal reasoning), and 30 are abstention questions whose correct answer is that the history does not say.
3.2 Token measurement
We counted tokens three ways: the OpenAI o200k_base tokenizer on all 500 questions; Anthropic's count_tokens endpoint (model claude-sonnet-5-5) on 60 questions stratified by type; and the input usage reported by the API in the paid Sonnet 5.5 and GPT-6.2 runs, which includes the prompt template.
Figure 1. Median input tokens per question (evidence or history plus question). Claude counts: n = 60; o200k counts: n = 500. The Claude tokenizer yields about 1.61 times the o200k count on this text, but the share saved is the same to within 0.01 points.
| Measurement | Full history | HeyBrain | Saved, median (IQR) | n |
|---|---|---|---|---|
| o200k_base tokenizer | 103,519 | 7,973 | 92.3% (92.0–92.6%) | 500 |
| Anthropic count_tokens | 166,956 | 12,769 | 92.3% (92.1–92.6%) | 60 |
| Sonnet 5.5 reader input, API usage (incl. prompt) | 167,862 | 12,993 | 92.3% (92.0–92.5%) | 500 |
| GPT-6.2 reader input, API usage (incl. prompt) | 103,952 | 8,136 | 92.2% | 48 |
Table 1. Input tokens per question, medians. Claude Fable 5.2, Opus 5.5, Sonnet 5.5 and Haiku 5.5 returned identical counts on all 60 questions, so the saving does not depend on which current Claude model is used. OpenAI does not publish tokenizers for its current models; o200k_base is a proxy, and the GPT-6.2 usage counts (row 4, which include the prompt template) land within 2% of it.
3.3 Accuracy
Readers used the official LongMemEval reader prompt, and answers were graded by gpt-4o-2024-08-06 with the benchmark's official per-type judge prompts. We compare arms on the same questions and report the paired difference with a bootstrap 95% confidence interval and an exact McNemar test.9,10
| Reader, sample, HeyBrain configuration | Full history | HeyBrain | Paired Δ (95% CI) | McNemar p |
|---|---|---|---|---|
| Claude Sonnet 5.5, all 500 questions, current configuration | 95.0% (475/500) | 90.0% (450/500) | −5.0 (−7.6 to −2.6) | < 0.001 |
| gpt-4.1-mini, all 500 questions, earlier configuration (24,000-character budget) | 73.8% (369/500) | 77.4% (387/500) | +3.6 (−0.6 to +7.6) | 0.098 |
Table 2. Answer accuracy on all 500 questions. With Sonnet 5.5 the full history answered 34 questions HeyBrain missed, and HeyBrain answered 9 the full history missed. The older, weaker reader gained from retrieval; the current one loses 5 points. An earlier 48-question sample (Table 3) had suggested a smaller, non-significant gap.
3.4 Six current readers
To check whether the result depends on the reader, we ran five more models on the same prompt, contexts and judge: the HeyBrain arm on all 500 questions, and both arms on the same stratified 48-question sample (8 per type). Thinking was off where the model allows it. Opus 5.5 and Fable 5.2 do not allow it to be turned off and ran at effort low; the GPT-6.2 models ran at reasoning_effort: low. None of these five readers refused or hit its output limit. Sonnet 5.5 ran with a 1,024-token output limit, which cut off 10 HeyBrain and 9 full-history answers; it also refused 2 full-history questions, which count as wrong.
| Reader (setting) | HeyBrain, 500 | Full, 48 | HeyBrain, 48 | Paired Δ, 48 (95% CI) | Reader cost / question, full → HeyBrain |
|---|---|---|---|---|---|
claude-fable-5-2 (effort low) | 93.2% | 100.0% | 95.8% | −4.2 (−10.4 to 0.0) | $1.359 → $0.120 |
claude-opus-5-5 (effort low) | 92.0% | 97.9% | 93.8% | −4.2 (−12.5 to +4.2) | $0.680 → $0.060 |
gpt-6.2-astra (reasoning low) | 90.4% | 93.8% | 91.7% | −2.1 (−10.4 to +4.2) | $0.835 → $0.067 |
claude-sonnet-5-5 (thinking off) | 90.0% | 95.8% | 91.7% | −4.2 (−12.5 to +4.2) | $0.340 → $0.030 |
gpt-6.2-sol (reasoning low) | 89.8% | 95.8% | 93.8% | −2.1 (−10.4 to +4.2) | $0.209 → $0.017 |
claude-haiku-5-5 (thinking off) | 87.8% | 85.4% | 87.5% | +2.1 (−6.2 to +10.4) | $0.085 → $0.0015 |
Table 3. HeyBrain against the full history across readers. No 48-question difference is significant (all McNemar p ≥ 0.5), but five of six point the same way. The smallest model is the exception: Haiku 5.5 does slightly better with HeyBrain's 13,000 tokens than with a 168,000-token history. Input tokens saved were 92.3% for every Claude reader and 92.2% for both GPT-6.2 readers. Costs are uncached list prices on the study date, with no prompt-caching discount (see Section 3.6); Haiku's full-history cost includes its higher rate above 100,000 input tokens.
3.5 By question type
The gap is not spread evenly. With Sonnet 5.5, single-session questions and preferences are within 2 points of the full history, while multi-session questions, which need facts from several past sessions, lose 10.5 points and temporal questions lose 6.0. Multi-session is also the weakest type for HeyBrain with every reader tested.
| Question type | gpt-4.1-mini full | gpt-4.1-mini HeyBrain | n | Sonnet 5.5 full | Sonnet 5.5 HeyBrain | n | HeyBrain, six readers |
|---|---|---|---|---|---|---|---|
| Single-session user | 98.4% | 95.3% | 64 | 100.0% | 100.0% | 70 | 95.7–100% |
| Single-session assistant | 98.2% | 98.2% | 56 | 98.2% | 96.4% | 56 | 96.4–98.2% |
| Single-session preference | 23.3% | 63.3% | 30 | 96.7% | 96.7% | 30 | 93.3–100% |
| Knowledge update | 84.7% | 91.7% | 72 | 96.2% | 93.6% | 78 | 93.6–100% |
| Temporal reasoning | 68.5% | 74.0% | 127 | 94.0% | 88.0% | 133 | 85.7–89.5% |
| Multi-session | 61.2% | 58.7% | 121 | 91.0% | 80.5% | 133 | 76.7–86.5% |
| Abstention | 73.3% | 70.0% | 30 | counted within types | |||
Table 4. Accuracy by question type, all 500 questions. The gpt-4.1-mini columns report abstention questions separately; the other columns count them inside their types, so the n columns differ. The last column is the lowest and highest HeyBrain accuracy among the six readers in Table 3.
3.6 Reader cost
Across all 500 questions, the Sonnet 5.5 reader cost $0.339 per question with the full history and $0.029 with HeyBrain, about one-twelfth. These are uncached list prices on the study date: each question is billed as a single request with no prompt-caching discount, which is how the benchmark runs were billed. The ratio is similar for every reader in Table 3 (11 to 13 times cheaper), except Haiku 5.5, where a full history crosses into its higher price tier and HeyBrain is 57 times cheaper.
Prompt caching narrows the gap. Both vendors bill cached input far below the normal input rate: Anthropic reads Sonnet 5.5 cached input at 0.05 times the input price after a cache write at 1.25 times (five-minute cache) or 2 times (one-hour cache), and OpenAI bills GPT-6.2 Astra's cached input at 0.05 times. Caching discounts the full history more than HeyBrain, because the long history is the part that repeats. We applied these prices to the measured per-question token counts in four usage patterns (Table 3b). With the prompt already cached, HeyBrain is about 4 times cheaper rather than 12 with Sonnet 5.5 (6 times with GPT-6.2 Astra); in a conversation that continues with follow-up questions, 5 to 10 times cheaper.
| Reader, cache | One question, no cache | Prompt already cached | First question + 3 follow-ups | First question + 10 follow-ups |
|---|---|---|---|---|
| Sonnet 5.5, five-minute cache (n = 500) | 11.6× | 4.1× | 8.7× | 6.0× |
| Sonnet 5.5, one-hour cache (n = 500) | 11.6× | 4.1× | 9.5× | 6.7× |
| GPT-6.2 Astra, automatic cache (n = 48) | 12.5× | 6.4× | 7.3× | 4.6× |
Table 3b. Full-history reader cost divided by HeyBrain reader cost (ratio of totals). modeled Token counts are measured; the caching is priced, not run. "Prompt already cached": the whole prompt is read from cache and only the answer is billed at full rate (Sonnet 5.5: $0.0207 vs $0.0051 per question). Follow-ups: the first question writes the cache, then each follow-up reads it and adds about 600 tokens of conversation and 400 of output.
4. Experiment 2: how much history is needed before memory pays off
HeyBrain's saving is the gap between the history and the evidence it retrieves, so it shrinks when the history is short. To measure this we took a 100-question subset stratified by question type (seed 7) and cut each history down to its answer-bearing sessions plus the most recent other sessions, 5, 10 and 20 sessions in all. We re-ran retrieval on each cut history and ran both arms with Sonnet 5.5. The 50-session row is the uncut benchmark (median 48 sessions) on the same 100 questions.
| Past sessions | Full history | HeyBrain | Paired Δ (95% CI) | McNemar p | Input tokens, full → HeyBrain | Saved | Cost ratio |
|---|---|---|---|---|---|---|---|
| 5 | 94.0% | 91.0% | −3.0 (−7.0 to 0.0) | 0.25 | 20,300 → 8,692 | 57.2% | 2.0× |
| 10 | 93.0% | 90.0% | −3.0 (−8.0 to +2.0) | 0.45 | 37,790 → 12,078 | 68.0% | 3.1× |
| 20 | 91.0% | 85.0% | −6.0 (−13.0 to 0.0) | 0.15 | 72,990 → 12,710 | 82.6% | 5.3× |
| 50 (uncut) | 93.0% | 86.0% | −7.0 (−14.0 to −1.0) | 0.065 | 167,773 → 12,993 | 92.3% | 11.3× |
Table 4b. History size, measured. Sonnet 5.5 reader, the same 100 questions in every row, medians of API-reported reader input, cost ratio at uncached list prices. HeyBrain's evidence stops growing at about 13,000 tokens once the history passes 10 sessions, while the full history keeps growing. No accuracy difference is significant by McNemar; the bootstrap interval excludes zero only at 50 sessions. On this subset HeyBrain scores 86% at 50 sessions, against 90% on all 500 questions.
The saving rises from 57% of input tokens with five past sessions to 92% with fifty, and the cost advantage from 2 to 11 times. The accuracy gap tends to widen as the history grows, from 3 points to 7, as more sessions compete for the same evidence budget. We did not run readers below five sessions. A token model of the measured histories estimates estimated that with two or three past sessions (under about 7,000 tokens) memory uses 4 to 5% more tokens than keeping the history over a question and three follow-ups, because the tool definition and retrieval framing outweigh the history itself. A deployment can avoid that by sending the whole history when it is below a threshold.
5. Experiment 3: how much evidence does the reader need?
Retrieved evidence has a median of 37,000 characters per question, but only two passages, usually ranked first and second, hold the answer. They make up 33% of the text sent. This suggests the budget could shrink, so we tested it.
| Keep the top k passages | Questions with every answer passage kept | Share of evidence text kept |
|---|---|---|
| 13 (current) | 96.4% | 99% |
| 6 | 93.2% | 75% |
| 4 | 86.4% | 60% |
| 2 | 69.0% | 39% |
Table 5. Evidence coverage under a fixed top-k cut, all 500 questions. With every answer passage present, the current configuration answered 91.9% correctly (n = 482); with one missing, 38.9% (n = 18).
| Sonnet 5.5, all 500 questions, paired | Current (13) | Top 4 |
|---|---|---|
| Accuracy | 90.0% | 86.8% |
| Difference (95% CI), exact McNemar | −3.2 pts (−5.4 to −1.2), p = 0.004 | |
| Every answer passage within the top 4 (n = 432) | 93.8% | 94.4% |
| An answer passage cut (n = 68) | 66.2% | 38.2% |
| Reader input tokens, median | 12,993 | 7,870 (−39%) |
| Reader cost per question (uncached list prices) | $0.029 | $0.020 |
Table 6. Fixed top-4 trimming. The whole loss comes from the 68 questions where the cut removed an answer passage; multi-session (−4.6 pts) and temporal questions (−6.0 pts) absorb it. Applying the cut only to single-session questions (a replay of the same answers) gave 89.6%, two questions below current, with 13% fewer tokens.
A fixed cut buys tokens at a measurable accuracy cost, so we do not recommend it. The data point toward cutting by relevance score or question type, keeping every high-scoring passage. We have not yet tested that variant.
5.1 Larger evidence budgets
The opposite direction is to send more. We re-ran retrieval and the Sonnet 5.5 reader on all 500 questions at three more character budgets, keeping the retriever, prompt and judge unchanged.
| Evidence budget (characters) | Accuracy | vs full history (95% CI), p | vs 40,000 (95% CI), p | Input tokens, median | Fewer than full | Reader cost / question | Cost ratio |
|---|---|---|---|---|---|---|---|
| 20,000 | 86.0% | −9.0 (−12.0 to −6.2), < 0.001 | −4.0 (−6.4 to −1.6), 0.002 | 6,588 | 96.1% | $0.017 | 20× |
| 40,000 (current) | 90.0% | −5.0 (−7.6 to −2.6), < 0.001 | 12,993 | 92.3% | $0.029 | 11.6× | |
| 60,000 | 92.4% | −2.6 (−5.0 to −0.4), 0.047 | +2.4 (+0.6 to +4.4), 0.023 | 19,198 | 88.6% | $0.041 | 8.3× |
| 80,000 | 93.0% | −2.0 (−4.2 to +0.2), 0.11 | +3.0 (+0.8 to +5.4), 0.017 | 25,180 | 85.0% | $0.050 | 6.7× |
| Full history | 95.0% | 167,862 | $0.339 | 1× |
Table 6b. Evidence budget, measured. Sonnet 5.5, all 500 questions, paired, exact McNemar p. Costs and ratios at uncached list prices; Table 3b's cached ratios are for the 40,000-character setting and would be smaller at larger budgets.
Unlike a fixed passage count, a larger budget buys accuracy back, because it raises the chance that every answer passage is included. At 80,000 characters HeyBrain answered 93.0%, 2 points below the full history and no longer significantly different (p = 0.11), while still sending 85% fewer input tokens at about one-seventh of the uncached reader cost. At 60,000 characters the gap is 2.6 points with 89% fewer tokens. Cutting to 20,000 characters saves 96% but loses 9 points. The budget is a direct dial between tokens and accuracy; where accuracy matters most, 60,000 to 80,000 characters gives up much less than the current setting.
6. Experiment 4: a memory brief for a coding agent
Coding agents also restart. A new session must re-read files and re-learn the task. We tested whether a HeyBrain-style brief from an earlier session reduces that cost.
6.1 Setup
- Tasks. 20 SWE-bench Lite2 instances (12 django, 8 sympy) from a fixed sample of every sixth instance by id.
- Session 1 (shared by both arms, read-only tools) investigates the issue and ends with a plan.
- Session 2 starts fresh from the base commit, in two arms: the issue alone (default), or the issue plus session 1's plan as a brief of at most 2,400 characters (median 1,530).
- Agent. Claude Code in headless mode (
claude -p --bare --strict-mcp-config), model Claude Sonnet 5.5, API billing. Session 2 could read, search and edit files; shell commands were blocked. - Measures. Tokens and cost from Claude Code's own usage report. Success graded by the official
swebenchharness (version 5.0.2): an instance is resolved when its FAIL_TO_PASS and PASS_TO_PASS tests pass.
6.2 Results
| Session 2, 20 tasks | Default | With brief | Change |
|---|---|---|---|
| Cost, all tasks summed | $0.662 | $0.607 | 8.3% lower |
| Tokens, all tasks summed | 2.6% higher | ||
| Cost per task, median change | 6.1% higher 12 of 20 cost more | ||
| Tokens per task, median | 12,936 | 12,630 | median change 11.0% higher; 14 of 20 used more |
| Turns, median | 4.5 | 4.0 | |
| Whole task (sessions 1 + 2), summed | $1.25 | $1.20 | 4.4% lower summed; median per task 3.9% higher |
| Resolved | 15/20 | 16/20 | 1 task differs; exact McNemar p = 1.0 |
Table 7. Coding-agent resume experiment. Costs are Claude Code's own reported cost, which includes its prompt caching. Summed cost falls because a few long default sessions dominate the bill; on the typical task the brief costs slightly more. Adding a typical 12,000-token Claude Code system prompt per turn (estimated; --bare uses a minimal prompt) moves the median change to about 1%.
Result: no consistent saving, same task success. An analytic model we built before this run predicted about 15% fewer tokens. The measurement did not confirm it. The model assumed a new session spends many tokens re-orienting. In practice the default agent found the fix in a median 4.5 turns; the brief itself is re-sent with every turn; and Claude Code must read a file before editing it, so a brief cannot remove the reads of the files being changed.
These tasks are small (median patch about 750 characters) and shell access was blocked, so this is a lower bound for long, multi-session engineering work. It is not evidence that memory never helps coding agents, and it is not evidence that it does.
6.3 Pilot: Claude Code and Codex across a chain of issues
Experiment 4 tested one hand-off. In real use an agent works through a series of sessions in the same repository, so we ran a pilot with both vendors' coding agents and two kinds of memory.
- Agents. Claude Code 2.1.321 (
claude-sonnet-5-5,--bare; read, search and edit tools, shell blocked) and OpenAI Codex CLI 0.167.2 (gpt-6.2-sol, default reasoning effort,workspace-writesandbox without network, an isolated configuration with its own memory features off). Both ran headless. - Tasks. The same 20 instances as Experiment 4, as 5 chains of 4 issues from one repository each (3 django, 2 sympy). Every issue is a new session.
- Arms. None: the issue only. Notes: a notes file the agent keeps itself (under 300 words), shown in each new session's prompt, like a project instructions file. HeyBrain: a search tool (MCP) over the chain's earlier sessions, captured automatically (issue text and the agent's final summary); the agent decides when to call it.
- Recall. After each chain, three read-only questions asking which file and function the agent changed for an earlier issue.
- Measures. Tokens are all input the model processed, including cache reads and writes, plus output, as each agent reports them. Claude Code costs are its reported cost; Codex costs use
gpt-6.2-sollist prices, including its cached-input and cache-write rates.
| Agent, memory | Coding tokens, median | vs none, median (95% CI) | Sessions using more tokens | Recall, right file | Recall tokens vs none | Resolved |
|---|---|---|---|---|---|---|
| Claude Code, none | 12,078 | 13/15 | 16/20 | |||
| notes | 14,300 | +32% (+3 to +65%) | 12/15 | 15/15 | +12% | 15/20 |
| HeyBrain | 14,606 | +7% (+3 to +38%) | 11/15 | 15/15 | +159% | 15/20 |
| Codex, none | 84,092 | 13/15 | 13/20 | |||
| notes | 109,279 | +31% (+21 to +40%) | 14/15 | 15/15 | −49% | 14/20 |
| HeyBrain | 103,118 | 0% (−2 to +39%) | 7/15 | 14/15 | 0% | 18/20 |
Table 8. Coding-agent pilot, issues 2 to 4 of each chain (memory available, n = 15 sessions per arm), paired with the same issue in the none arm. Changes are medians of per-session ratios with bootstrap 95% CIs, so they are not the ratio of the medians shown. Resolved counts all 20 issues, graded by the official swebench harness; a test run over the harness's 1,800-second limit counts as unresolved (4 runs of sympy__sympy-18057 and 1 of sympy__sympy-15346). Against none, exact McNemar: Claude Code notes and HeyBrain each 0 better, 1 worse (p = 1.0); Codex notes 2 better, 1 worse (p = 1.0); Codex HeyBrain 5 better, 0 worse (p = 0.06, two of the five being timeouts in the none arm), so no resolved-rate difference is significant at n = 20. Token counts compare arms within an agent, not agents: each Codex turn re-sends a base prompt of about 20,000 tokens, mostly billed as cached input. Claude Code made 8 HeyBrain calls across its 15 coding sessions; Codex made none. Issue 1 of each chain has no memory in any arm, yet its median tokens differed by up to 15% between arms (n = 5), so differences below about 20% are within noise. Spend: $9.61 for 210 sessions.
Result: memory did not reduce coding tokens for either agent. A notes file the agent keeps cost about a third more on both, because the agent reads and rewrites it every session. HeyBrain cost about 7% more on Claude Code and nothing on Codex, which never called it while coding. The issue text already points at the code, so earlier sessions add little. Memory did help recall: without it both agents named the right file for 13 of 15 earlier issues, and with it 14 or 15. Codex with notes answered recall questions in about half the tokens. The recall questions were easy to guess from the issue text, and the pilot is small, so it cannot show a recall gain; a full study needs questions about earlier decisions that leave no trace in the code.
7. Experiment 5: coding agents across sessions and after an interruption
The pilot's tasks left memory little to carry: each issue text already pointed at the code, and the recall questions could be guessed from it. We therefore ran a larger study, with endpoints, analysis code, task specifications and hidden tests fixed before any paid run. It has three parts. S1 asks whether an agent keeps decisions made in earlier sessions of a project, and what that costs. S2 asks whether it can recall those decisions. S3 asks what it costs to finish a larger task after the session that started it was interrupted.
7.1 Setup
- Agents. The pilot's versions of Claude Code (
claude-sonnet-5-5) and Codex CLI (gpt-6.2-sol). This time both could run shell commands, each in its own sandbox without network access. - Five arms per agent. Fresh: the task only. Resume: the vendor's own continuation of the previous session (
claude --resume,codex exec resume), so the full earlier conversation. Notes: a file the agent keeps itself (under 300 words), shown at the start of each session. HeyBrain tool: asearch_documentstool over earlier sessions, captured automatically (the task, the user's messages and the agent's final summary); the agent decides when to call it. HeyBrain brief: the same search, run on the new task text by the harness, with the result (at most 6,000 characters) placed at the start of the session, as a session-start hook would. The brief is a HeyBrain configuration we would ship, and we report it separately from the tool. - HeyBrain implementation. A local server with production's
search_documentsinterface, ranking passages with HeyBrain's own retrieval code, over a store holding only that project's earlier sessions. No data went to the production service. - S1, multi-session projects. Six small Python projects written for this study (standard library only, 400 to 800 lines, so absent from any model's training data), each with two feature chains of four sessions: 48 sessions per arm per agent. A later session refers to earlier work only by name ("extend the exporter from last time") and depends on decisions a simulated user stated in an earlier session, such as a naming rule, a rejected library or a file format. Each session has hidden tests, added only after the session ends. Some test the new feature; decision tests check that earlier decisions were kept.
- S2, decision recall. 36 read-only questions (three per chain) whose answers were given only in conversation. Before the run we checked by search that no answer appears in the code, comments or version history.
- S3, an interrupted larger task. 30 SWE-bench Verified11 instances whose reference fix touches at least two files and exceeds 2,000 characters, sampled in proportion to repository (seed 7). A fresh reference run measures how many tool calls the task takes in one sitting. A first session gets the same prompt, which asks the agent to keep a notes file as it works, and is interrupted after half that many tool calls (at least two). Each arm then finishes the task. The notes file is removed for the fresh and HeyBrain arms. Graded by the official
swebenchharness. - Measures and statistics. Tokens are all input the model processed, including cache reads and writes, plus output, compared only within an agent. Claude Code usage and cost come from its own reported totals in S1 and S2 and from its saved transcript, at list prices, in S3; Codex costs use
gpt-6.2-sollist prices with its cache rates. Codex reports a resumed thread's running total, so a resumed session's usage is the difference between consecutive totals, and output tokens (which include reasoning) are priced once. Comparisons are paired: S1 by session (sessions 2 to 4, n = 36), with bootstrap intervals that resample whole chains (12 per agent); S3 by task (n = 30), resampling tasks. 4,000 resamples, seed 7; exact McNemar tests for pass rates.
7.2 S1: keeping earlier decisions
| Agent, arm | Tokens per session, median | Tokens vs resume (95% CI) | Cost vs resume | Earlier decisions kept | All hidden tests pass |
|---|---|---|---|---|---|
| Claude Code, fresh | 39,194 | −33% (−47 to −15%) | +16% | 1/36 | 1/36 |
| resume | 53,481 | 35/36 | 32/36 | ||
| notes | 46,040 | −15% (−27 to +2%) | +35% | 32/36 | 30/36 |
| HeyBrain tool | 43,514 | −20% (−34 to −5%) | +35% | 17/36 | 13/36 |
| HeyBrain brief | 57,340 | −7% (−24 to +23%) | +38% | 33/36 | 29/36 |
| Codex, fresh | 114,625 | +11% (−2 to +35%) | +160% | 2/36 | 1/36 |
| resume | 108,362 | 36/36 | 36/36 | ||
| notes | 116,768 | +11% (−6 to +21%) | +170% | 29/36 | 27/36 |
| HeyBrain tool | 139,102 | +18% (+11 to +41%) | +180% | 16/36 | 7/36 |
| HeyBrain brief | 115,627 | +12% (+4 to +29%) | +172% | 36/36 | 36/36 |
Table 9. S1, sessions 2 to 4 (n = 36 per arm). Changes are medians of per-session ratios against the same session in the resume arm. "Earlier decisions kept": the session's decision tests pass. "All hidden tests pass": every test of this and all earlier sessions in the chain. Feature tests alone passed in 31 to 36 of 36 sessions in every arm. Each agent called the HeyBrain tool 17 times in 36 sessions. Against a fresh session, the brief used 37% more tokens on Claude Code (+4 to +91%) and 3% more on Codex (−5 to +7%). In session 1, where no arm has memory, arm medians differed by up to 30% on Claude Code (wide intervals) and about 2% on Codex; on Claude Code fresh already cost 15% more than resume there, so the +16% in this table is not evidence of a resume effect.
Without memory, agents broke almost every earlier decision: a fresh session kept them in 1 or 2 of 36 sessions, while still building the requested feature. Resume, notes and the brief kept most of them. The brief matched resume on Codex (36 of 36, every test passing) and came close on Claude Code (33 against 35). The tool kept fewer than half, because agents seldom called it while coding: 17 calls in 36 sessions, for each agent.
While coding, resume was the cheapest way to keep decisions on both agents. Codex's resumed sessions used a median 108,362 tokens against 115,627 with the brief (12% more with the brief, +4 to +29%), and the brief cost 172% more than resume (+157 to +202%). Resume also cost 62% less than starting fresh on Codex (−66 to −59%). On Claude Code the brief used 7% fewer tokens than resume (not significant) but cost 38% more; resume cost 13% less than fresh there, but session 1, where resume has nothing to resume, shows the same 13%, so we cannot attribute it to resume. On Codex, 97% of resume's input was read from the prompt cache, against 80% for a fresh session and 79% with the brief, so input not read from the cache (mostly cache writes) was 23% of resume's cost against about 72% of theirs. The median cost of S1 sessions 2 to 4 was never lower with notes, the tool or the brief than in a session that starts with nothing, on either agent; what they bought was keeping the earlier decisions. Each resumed S1 session started within about half a minute of the one before, on both agents, so resume read a warm cache. We did not measure resuming after the cache expires, but it could reverse the Codex cost result: re-pricing only the cached part of each resumed session's first request as a cache write (modeled), resume would cost 17% more than fresh (+7 to +28%), and the brief 12% less than resume (−14 to −8%).
7.3 S2: recalling decisions
| Arm | Claude Code, correct | Claude Code, tokens | Codex, correct | Codex, tokens |
|---|---|---|---|---|
| Fresh | 2/36 | 10,423 | 1/36 | 95,822 |
| Resume | 36/36 | 23,809 | 36/36 | 35,731 |
| Notes | 26/36 | 3,032 | 19/36 | 18,695 |
| HeyBrain tool | 36/36 | 6,542 | 35/36 | 56,901 |
| HeyBrain brief | 35/36 | 4,049 | 36/36 | 19,577 |
Table 10. S2, 36 questions per arm, asked after each chain; tokens are medians per question. Every memory arm beats fresh (exact McNemar p < 0.001). An answer counts as correct when it contains every key term of the decision stated in conversation (case-insensitive, no model judge). Agents called the HeyBrain tool for almost every question (37 and 35 calls).
Asked directly, agents with HeyBrain recalled 35 or 36 of 36 decisions, as resume did. The brief did it with fewer tokens, 83% fewer on Claude Code and 45% fewer on Codex; the tool used fewer on Claude Code but 59% more on Codex. Fewer tokens did not mean lower cost: a brief question cost a median $0.0061 against $0.0037 for resume on Claude Code and $0.0492 against $0.0042 on Codex, where 99% of resume's input was read from a warm cache and none of the brief's was; after the cache expires the first resumed question would cost more (not measured). Notes cost about the same as resume on Claude Code ($0.0039) but kept only 26 of 36 decisions. A notes file the agent keeps itself lost a quarter to half of the decisions, because the agent decides what to write down.
7.4 S3: finishing an interrupted task
| Agent, finishing arm | Tokens, median | Tokens vs fresh (95% CI) | Tokens vs resume (95% CI) | Cost, median | Cost vs fresh (95% CI) | Resolved |
|---|---|---|---|---|---|---|
| Claude Code, one sitting (reference) | 31,876 | 9/30 | ||||
| fresh | 31,214 | +38% (+16 to +50%) | $0.0334 | 10/30 | ||
| resume | 23,157 | −27% (−33 to −14%) | $0.0253 | −34% (−42 to −20%) | 9/30 | |
| notes | 31,840 | +1% (−4 to +7%) | +40% (+24 to +57%) | $0.0337 | −3% (−12 to +3%) | 13/30 |
| HeyBrain tool | 33,222 | +9% (−3 to +20%) | +45% (+11 to +83%) | $0.0343 | +1% (−7 to +7%) | 11/30 |
| HeyBrain brief | 33,636 | +5% (−5 to +16%) | +41% (+18 to +77%) | $0.0341 | −2% (−12 to +5%) | 14/30 |
| Codex, one sitting (reference) | 328,237 | 15/30 | ||||
| fresh | 279,554 | +23% (−1 to +50%) | $0.1100 | 16/30 | ||
| resume | 239,436 | −19% (−33 to +1%) | $0.0457 | −58% (−61 to −52%) | 17/30 | |
| notes | 299,390 | +2% (−11 to +13%) | +32% (+12 to +61%) | $0.1105 | +1% (−7 to +17%) | 16/30 |
| HeyBrain tool | 290,164 | +2% (−18 to +23%) | +24% (−15 to +59%) | $0.1087 | −2% (−11 to +13%) | 15/30 |
| HeyBrain brief | 258,308 | +4% (−14 to +16%) | +20% (+9 to +59%) | $0.1100 | +4% (−5 to +14%) | 15/30 |
Table 11. S3, 30 SWE-bench Verified tasks per agent; tokens and cost are for the finishing session only, compared by task; changes are medians of per-task ratios. Costs are computed from measured token usage at list prices with cache rates: Sonnet 5.5 for Claude Code, gpt-6.2-sol for Codex. Resolved by the official swebench harness (version 5.0.2); an empty patch counts as unresolved. No resolved-rate difference is significant: for Claude Code with the brief, 4 better and 0 worse than fresh (exact McNemar p = 0.13) and 5 better and 0 worse than resume (p = 0.06); every Codex comparison has p ≥ 0.5. The interrupted first sessions resolved 1 of 30 (Claude Code) and 8 of 30 (Codex). The HeyBrain tool was called 0 times by Claude Code and 4 times by Codex. Spend: $29.30 for 420 sessions.
After an interruption, we detected no change in the cost of finishing with notes, the tool or the brief compared with starting fresh: median changes were within 10% of fresh in tokens and 5% in cost, and every interval spans zero (the widest reach −18% to +23% in tokens and −12% to +17% in cost). Resume cost less than fresh on both agents: 27% fewer tokens and 34% lower cost on Claude Code, 19% fewer tokens (not significant) and 58% lower cost on Codex. Resumes started soon after the interrupted session (Codex: median one minute, at most five; Claude Code: median 36 seconds, at most five minutes), so these costs reflect a mostly warm cache. Re-priced the same way as S1 (modeled), a cold first request on Codex would put resume about level with fresh (−5%, −9 to +13%) and with the brief (brief +5%, −5 to +16%). Task success did not change significantly. The one hint, which needs a repeat run before anyone relies on it, is Claude Code with the brief: it resolved 14 tasks against 10 fresh and 9 resumed, and lost none that those arms solved.
The interruption was early for Claude Code. It finished a task in one sitting in a median of 6 tool calls, so its first session stopped after 3; only 5 of its 30 interrupted sessions had changed any code and 10 had written notes. Codex's interrupted sessions ran longer (median 5 tool calls), and all 30 had written notes. S3 therefore says little about resuming after a long stretch of work.
8. Discussion
The saving tracks the gap between history size and evidence size. On histories of about 100,000 tokens, retrieval sends roughly 8,000, and the share saved is near 92% regardless of tokenizer or Claude model. Below about five sessions the gap disappears, and in short coding sessions there is little to re-orient, so there is little to save.
Accuracy depends on recall, and the budget matters through recall. When every answer passage reaches the reader, accuracy is high; when one is missing, it collapses. Any further token reduction has to protect coverage, which is why a fixed passage count fails while a larger budget recovered 3 of the 5 points. A budget sized to the question type might keep most of that gain at fewer tokens; we have not tested it.
Retrieval trades a small amount of accuracy for a large saving, and the trade has moved as readers improved. An older reader, gpt-4.1-mini, did better with HeyBrain than with the full history (+3.6 points), probably because a long history buried the answer. Current readers handle 168,000-token histories well, so the full history now wins by 2 to 5 points on most of them, at 11 to 13 times the reader cost at uncached list prices, or about 4 times (Sonnet 5.5) when the prompt is already cached. The exception is the smallest current model, Haiku 5.5, which still did slightly better with retrieval. The loss sits mostly in multi-session questions, where an answer depends on facts spread across sessions and a single missed passage is enough to get it wrong. That makes recall on multi-session questions the clearest target for improving the memory layer.
For coding agents the question is less "how many tokens does memory save" than "what does keeping the project's history cost". A session that starts with nothing silently drops what the user decided earlier, and it was not always the cheapest option: with a warm cache, resuming cost 62% less than starting fresh on Codex in S1, and 34% (Claude Code) and 58% (Codex) less in the interrupted tasks (S3). In S1 on Claude Code we could not tell resume and fresh apart on cost. While coding, resume was the cheapest way to keep decisions on both agents, as long as the earlier session can be resumed soon after it ends. The brief is for when it cannot be: it keeps the decisions, at about 4% above the cost of starting fresh on Codex and about 20% above it on Claude Code (S1). Once the cache has expired, our model suggests the brief becomes the cheaper way on Codex in S1 and costs about the same as resume in S3; we have not measured either. The brief worked where the tool did not: agents called the tool when asked a question about the past (S2), but seldom while coding (S1), so pushing memory into the session mattered more than offering it.
Context limits matter alongside price. OpenAI lists a 54K context window for ChatGPT Plus in its Instant mode,8 which a 100,000-token history does not fit, while the retrieved evidence does. That is a capability difference, not a token saving, and we do not count it in the percentages above.
9. Limitations
- Five readers compared on 48 questions. Only Sonnet 5.5 has a paired full-history comparison on all 500 questions. For the other five readers the paired comparison uses the stratified 48-question sample, which cannot resolve gaps smaller than about ±8 points; their HeyBrain accuracy is measured on all 500.
- Reader settings differ. Opus 5.5 and Fable 5.2 cannot run with thinking off and used low effort; the GPT-6.2 models used low reasoning effort; Sonnet 5.5 had a 1,024-token output limit while the others had 16,000. Each reader used the same setting in both arms, so the paired comparisons are fair, but readers are not compared with each other at equal settings.
- One benchmark. LongMemEval-S histories are synthetic and similar in length, which makes the token medians tight. Real users' histories vary far more; Table 4b shows how much that matters.
- LLM judge. Grading uses gpt-4o, following the benchmark's protocol. Judge errors affect both arms equally but are not zero.
- Tokenizer proxy. OpenAI's current model tokenizers are not published; o200k_base stands in. Percentages are tokenizer-insensitive on this text; absolute counts are not.
- Coding experiment scope. Experiment 4: 20 small tasks, one agent, minimal system prompt, no shell. Experiment 5: one model per agent at default settings, small authored projects with decisions given by a simulated user, and 30 SWE-bench Verified tasks, each run once. Claude Code's interrupted S3 sessions were very short (Section 7.4).
- Warm cache. Every resumed coding session started within minutes of the one before it, so resume costs assume a warm prompt cache. Costs after the cache expires are modeled, not measured.
- Task review. The S1 task specs were reviewed by the study agent, not an independent human. The specs, hidden tests and the validation script are available on request, so others can check them.
- HeyBrain stand-in for coding. The coding experiments used a local server with production's search interface and retrieval code over a per-project store, not the production service, and captured only the task, the user's messages and the agent's final summary.
- Sweeps on one reader. The history-size and budget sweeps used Sonnet 5.5 only, and the history sweep used 100 questions.
- Single runs. Each configuration was run once; we did not measure run-to-run variance of the reader.
- Authorship. This study was designed and run by the team that builds HeyBrain (see Disclosure).
10. Reproducibility
| Item | Value |
|---|---|
| Datasets | LongMemEval-S (cleaned release), 500 questions; SWE-bench Lite test split; SWE-bench Verified test split (Parquet, sha256 030cfd7f…a3b41230b1d3517f9c915ad7ea5be3fa25), 30 instances; 6 authored Python projects (S1, S2) |
| Readers | claude-fable-5-2, claude-opus-5-5 (thinking always on, effort: low); claude-sonnet-5-5 (thinking only between tool calls, so none here; 1,024 output tokens); claude-haiku-5-5 (thinking disabled); gpt-6.2-astra, gpt-6.2-sol (reasoning_effort: low); gpt-4.1-mini-2025-04-14. Official LongMemEval "cot" reader prompt; no fallback models. |
| Judge | gpt-4o-2024-08-06, LongMemEval prompt |
| Coding agents | Claude Code 2.1.321 headless, --bare --strict-mcp-config, claude-sonnet-5-5; OpenAI Codex CLI 0.167.2, codex exec (--ephemeral except where resumed), gpt-6.2-sol, isolated CODEX_HOME with its memory features off; Experiment 5 with shell in each agent's sandbox, no network |
| Tokenizers | o200k_base via js-tiktoken; Anthropic count_tokens |
| Statistics | Paired bootstrap, seed 7: 4,000 resamples for accuracy differences, 2,000 for token medians; exact McNemar test on discordant pairs |
| Grading | swebench 5.0.2, official Docker images (linux/amd64) |
| Paid model spend | $661.35: 48-question parity $18.58, trimming $9.31, coding $1.86, coding pilot $9.61, coding study (S1 to S3, with dry runs) $90.90 (this and the total include about $15 of overcounted usage, from the Codex resume and reasoning errors and the Sonnet 5.5 cache price; dry runs not recounted), budget and history sweeps $91.26, Sonnet 5.5 full history on the remaining 452 questions $153.89, five further readers $285.94 (judge included in each) |
| Code and per-question data | Available on request, including the S1 projects, chains, hidden tests and recall questions |
Disclosure
This study was conducted by HeyBrain, which develops the memory system evaluated here. No model vendor sponsored or reviewed it. Descriptions of Claude, Claude Code, ChatGPT and Codex behavior come only from those vendors' own documentation, retrieved on 26 November 2026. Results reflect the models and configurations named above on that date and may change as products change.
References
- Wu, D., Wang, H., Yu, W., Zhang, Y., Chang, K.-W., and Yu, D. LongMemEval: Benchmarking Chat Assistants on Long-Term Interactive Memory. ICLR 2025. arXiv:2410.10813.
- Jimenez, C. E., Yang, J., Wettig, A., Yao, S., Pei, K., Press, O., and Narasimhan, K. SWE-bench: Can Language Models Resolve Real-World GitHub Issues? ICLR 2024. arXiv:2310.06770.
- Anthropic. Manage costs effectively (Claude Code documentation). code.claude.com/docs/en/costs. Retrieved 26 Nov 2026.
- Anthropic. Context windows (Claude API documentation). platform.claude.com. Retrieved 26 Nov 2026.
- Anthropic. Using Claude's chat search and memory to build on previous context. support.claude.com. Retrieved 26 Nov 2026.
- OpenAI. Unrolling the Codex agent loop. openai.com. Retrieved 26 Nov 2026.
- OpenAI. Memory FAQ. help.openai.com. Retrieved 26 Nov 2026.
- OpenAI. ChatGPT pricing. chatgpt.com/pricing. Retrieved 26 Nov 2026.
- McNemar, Q. Note on the sampling error of the difference between correlated proportions or percentages. Psychometrika 12(2), 153–157, 1947.
- Efron, B., and Tibshirani, R. J. An Introduction to the Bootstrap. Chapman and Hall, 1993.
- OpenAI. Introducing SWE-bench Verified. openai.com, 2024.
Correction in version 1.5
Version 1.4 counted Codex's resumed sessions wrongly. Codex reports a resumed thread's running total, and we treated each total as one session's usage, so earlier sessions were counted again. This made resume look more expensive than it is. Version 1.4 said the HeyBrain brief used 60% fewer tokens and cost 40% less than Codex's resume. That was wrong: the brief used 12% more tokens and cost 172% more. Two other Codex claims were wrong for the same reason: that resume was 39% dearer than fresh in interrupted tasks (it used 19% fewer tokens, not significant, and cost 58% less) and that the brief used 96% fewer tokens than resume when recalling decisions (45% fewer, at about 12 times the cost). Section 7.1 now also states where Claude Code usage comes from in each experiment. The corrected figures are in the abstract, the key results, Tables 9 to 11 and Sections 7 and 8. Codex reasoning tokens were also priced twice, which raised Codex costs by 0.4% in S1 and S2 and by 1 to 2% in S3.
Version 1.4 also priced Sonnet 5.5 cache reads at 0.1 times the input price; Anthropic's list price is 0.05 times ($0.10 per million tokens). This changes the cached-price ratios in Table 3b (with the prompt already cached, HeyBrain costs about one-quarter as much as the full history, not one-sixth) and the S3 spend total; the Claude Code costs now shown in Table 11 use the list price. Uncached cost figures, accuracy and token counts for the chat benchmark are unchanged. The raw session data and the decision and test results are unchanged.
Other wording corrections: the abstract now gives the 500-question token counts (168,000 to 13,000) in place of a 60-question tokenizer count; Section 8 no longer says that a fresh session is always the cheapest; Section 7.2 states its cost comparison for sessions 2 to 4; Section 7.4 gives token and cost changes separately and says no change was detected rather than that none occurred; Sections 7.2 to 8 state the cache condition; Table 9 gives session 1 differences of up to 30% on Claude Code and about 2% on Codex (version 1.4 said 20% and 1%); and Table 11 adds costs. No model run was repeated; all changes come from re-analysing the recorded usage.