DEV Community

Cover image for I gave my local Claude Code a smaller prompt. It made up fewer answers.
JustJinoIT
JustJinoIT

Posted on Edited on AI-assisted

I gave my local Claude Code a smaller prompt. It made up fewer answers.

I gave my local Claude Code a smaller prompt, and it got more answers right.

Claude Code loads a memory index (MEMORY.md) into every request. On a 16GB MacBook (Apple M5) running qwen3.5:9b through Ollama, I replaced that with a hook that attaches only the memory lines related to the prompt. On 45 questions about my own past work (about 80 memory files), graded blind by two LLM judges:

  • correct answers: 20 → 37
  • made-up answers: 11 → 3
  • time per question: 90s → 56s

The full index is mostly pointers to files, not answers. A bigger prompt full of pointers did worse than a smaller prompt with the right lines. All numbers are from one Mac, one model and my own memory. The full table:

Full index Relevant lines
First-request input tokens (median, 50 pairs) 11,450 8,030
Time to finish one question (median, 50 pairs) 90.4s 56.4s
Memory questions answered correctly (45) 20 37
Made-up answers (45) 11 3

A pair is one question run once on each setup. Timing uses 50 pairs: the 45 memory questions plus 5 questions unrelated to memory. A made-up answer states a specific fact about my records that contradicts the memory files. The new setup was faster in 42 of 50 pairs. On correctness, only the old setup was right on 4 questions and only the new one on 21. Both gaps are statistically significant on paired tests (Wilcoxon and McNemar, p<0.001).

Why the full index hurts

The index (MEMORY.md) is a list of links to memory files. It is long, and it rarely holds the answer itself. So the local model:

  1. reads about 11k tokens before your question (tools, system prompt and the index together; reading about 12k tokens took 38s on a cold start in my runs), then
  2. still has to open files to find the actual fact, spending more turns.

What the hook does

It is a UserPromptSubmit hook, plain python3, no packages.

  1. Splits memory files into line chunks.
  2. Scores each chunk against the prompt two ways: local embeddings (bge-m3 on Ollama) and keyword search (BM25). The two rankings are merged with RRF (reciprocal rank fusion, which scores each chunk by 1/(60 + rank) in each list and adds them up).
  3. Attaches the best chunks with the line before and after, up to 2,400 characters. Each file's block is labeled with that file's last-modified date.
  4. Attaches nothing for short replies like "ok do it" (fewer than 3 search terms).
  5. If Ollama is down it falls back to keywords. If that fails it attaches nothing, and Claude Code continues without it.

Retrieval check on 45 questions never used for tuning: the expected answer appeared in the attached text for 36. My earlier keyword-only hook got 17.

How I measured

I wanted numbers I could not tune my way into.

  • Criteria were written down before each scored run, and every change was logged with its reason.
  • Questions were written by a separate agent that never saw the retrieval code. Any question set I looked at while tuning was retired. Final numbers come from a set never used for tuning.
  • Old and new setups ran each question back to back, alternating which went first (ABBA).
  • Two judges (Sonnet and Opus) graded answers without knowing which setup wrote them. They agreed on 89 of 90 verdicts. For the one split, I used the stricter verdict.
  • Charger and sleep state were logged for every run. Closing the lid once put the Mac to sleep mid-run, which made 3 timings wrong, so I reran those with the charger in and the lid open.

The first 20 questions went 11 → 17, but that was not significant (p=0.15). So I wrote down a follow-up plan before running it: 25 unused questions. They came out 9 → 20 (p=0.003), and the pooled 45 are in the table above.

What did not work

Tried Result
A rule to skip prompts unrelated to memory Worked on one question set, failed on the next. Removed as overfitting
Also attaching later updates from the same file Added unrelated lines on dev data. Not shipped

I also checked 40 random real prompts against the memory files. The attached text was helpful for 8, neutral for 23, and possibly misleading for 9. Most misleading cases came from files where an old fact sits next to its update. Each attached block now shows its file's last-modified date, and the kit's rules tell the model that memory can be outdated and to check that files and commands exist before recommending them. The bigger fix is on the memory side: when a fact changes, edit the old line instead of appending a new one.

Try it

Needs macOS, Ollama, Claude Code and python3.

git clone https://github.com/JustJinoIT/claude-local-kit && cd claude-local-kit
./install.sh                 # pulls qwen3.5:9b (64k context) and bge-m3
claude-local                 # Claude Code on the local model, in the current folder
Enter fullscreen mode Exit fullscreen mode

It does not touch your normal Claude Code settings. ./uninstall.sh moves everything to the Trash.

There is also cl. When a Claude session stops, for example at a usage limit, run cl in the same folder. It builds a handoff note from that conversation (first request, last prompts, edited files) and continues in local mode.

One setting worth changing: Ollama unloads a model after 5 minutes idle by default, and the next request stalls while it reloads.

launchctl setenv OLLAMA_KEEP_ALIVE 4h   # then restart Ollama
Enter fullscreen mode Exit fullscreen mode

The repo's bench/ folder has the preregistration log, the scripts, and a fictional memory set, so you can rerun the retrieval test yourself.

Before you load memory into a local model

  • How many tokens does your first request carry before the question?
  • Does your memory index contain answers, or only pointers to files?
  • When a fact changes, do you edit the old line or append a new one?
  • Did you compare setups on questions you never tuned on?

Written with help from an AI assistant (Claude). I checked every number against my measurement logs.

Top comments (0)