r/opencodeCLI • u/Glittering_Focus1538 • May 18 '26
I built a coding agent that gets 87% on benchmarks with a 4B parameter model, here's how
I was frustrated that every coding agent (OpenCode, Cursor, Claude Code) assumes you're running GPT-5.4 or Claude Opus. If you try them with a local model like Gemma or Qwen they fall apart. I find that often tool calls fail, context overflows, multi-step tasks collapse.
So I built SmallCode. It's designed from the ground up for small local models.
The result: 87/100 benchmark tasks pass with a Gemma 4 model that only activates 4B parameters per token. OpenCode scores ~75% with 14B models. The harness does the heavy lifting, not the model size.
How it works (the tricks that make small models reliable):
Compound tools: Instead of making the model chain 4 tool calls (find file → read file → edit file → verify), SmallCode gives it one tool that does all 4. Small models lose coherence after 3+ sequential calls. This cuts failures in half.
Improvement loop: Every time the model writes code, SmallCode instantly compiles/lints it. If it fails, it feeds the errors back automatically. The model doesn't need to be smart enough to get it right first try — it just needs to fix errors when shown them.
Decompose on failure: If the model fails the same thing twice, SmallCode stops retrying and instead breaks the problem into smaller pieces. "Fix this 200-line file" becomes "fix line 45 only."
Escalation: If even decompose fails and you have a Claude/OpenAI key configured, it auto-escalates to the bigger model for just that one task. You stay local 95% of the time, cloud 5%.
Token budgeting: Small models have 32k-256k context. SmallCode never dumps a whole file in. It summarizes, truncates, and manages every token so the model never sees "..." truncation in the middle of important code.
Code graph: Instead of grep-searching your codebase, SmallCode indexes your code into a symbol graph (functions, classes, who-calls-what). When you ask "how does auth work," it walks the graph and returns just the relevant connected code — not 15 random file snippets.
What it looks like:
Full-screen terminal UI (like OpenCode/vim), scrollable chat, command palette with /, plugin system, persistent memory across sessions.
What it doesn't do:
No LSP integration (yet)
No multi-session (yet)
No desktop app
Doesn't compete with Claude Code for frontier model users
Install:
npm install -g smallcode
cd your-project
smallcodePoint it at LM Studio, Ollama, or any OpenAI-compatible endpoint.
MIT licensed, everything's on GitHub: https://github.com/Doorman11991/smallcode
Happy to answer questions about the architecture or benchmark methodology.
28
u/ponyportal512 May 18 '26
This is awesome. I truly think that optimised harnesses like that are better even for larger models. How did you benchmark it? I'm really interested in how good this harness is at ProgramBench, where llm recreates cli tools. Why didn't you use qwen3.6 9b and it's not a recommended model? I find q3.6-9b-deepseek-v4-flash (distil) very good.
11
u/Glittering_Focus1538 May 18 '26
I wanted to use the smallest model possible to get the highest tok/s and see what was possible, so I benchmarked with gemma4 instead of a bigger model. As I think most people can run gemma 4 e4b on a tablet or laptop.
8
u/ponyportal512 May 18 '26
I understand. What was your benchmark process?
5
u/Glittering_Focus1538 May 18 '26
I ran a custom made benchmarking tool, 50 different multi file tests across 5 different coding languages. I then averaged for the result.
6
u/ponyportal512 May 18 '26
Is benchmark included in the repo? Have you considered publishing it (as a separate repo, or included)?
12
u/ZireaelStargaze May 18 '26
Looks very promising, I'll give it a try when I get home. If I may make some suggestions, have a look at lean-ctx and magic context (https://github.com/cortexkit/magic-context) and maybe qartez-mcp. They are all about graphing the repository, cutting down tool output spam and keeping context window in check. Maybe you will find some new inspirations. Especially magic context works well for me in opencode - really recommend you see what it does under the hood. I was playing around with chaining LSP from ast-grep in opencode native tools - it needs some work, but you get many languages coverage from one tool.
4
u/Glittering_Focus1538 May 18 '26
thanks for the recs! I WILL look into them!
2
u/ZireaelStargaze May 18 '26
Also, have you thought about representing the goal/todo (and model's internal scratch pad memory) as a graph rather than flat text file? A goal/epic (type: code implementation/debugging/research/docunentation/chore) With nodes that are objectives/references/constraints/tests/dependants/gates/acceptance-criteria/closure notes/metadata/decisions-ADR/task-specific-agent-instructions-to-use/skills-to-use/tools-to-use/etc.
All nodes written in machine friendly caveman-speak. Basically a simplified version of Beads ( https://github.com/gastownhall/beads )
2
u/Glittering_Focus1538 May 18 '26
the internal scratchpad memory is already graphed and searched almost the same way we search the indexed codebase. it's all permanent and efficient for context.
2
u/Glittering_Focus1538 May 18 '26
smallcode uses this mcp I made, skim the docs https://github.com/Doorman11991/budget-aware-mcp
6
u/gandazgul May 18 '26 edited May 18 '26
I'm building a harness with similar aims although less focused on smaller models and more on engineering standards. But I love a lot of the compensations you have here perhaps we can collaborate. For code base symbol indexing take a look at https://github.com/1broseidon/cymbal/ and for memory https://github.com/gandazgul/mnemosyne/ They are clis you can just install them call rather than integrating and maintaining your own thing.
My harness https://github.com/gandazgul/harns
I will borrow your idea of composite tools. I haven't benchmarked mine yet been using it to code other projects and squashing bugs.
Edit: typo
5
2
u/vaff May 18 '26
I didn't know Markiplier coded. But we agree this is a harness not a agent ?
1
u/Glittering_Focus1538 May 18 '26
yeahh, sorry about that, Not the best title. But it doesn't exactly work the same way other harness's tend to. I hardcoded more restraints around what the ai could do and how.
3
5
u/WhiskyAKM May 18 '26
Hey im also building my own harness: https://github.com/PTFOPlayer/TinyHarness
And my goal is also to focus on local models. Neat that there are more people that have similar goals.
Your idea to compact file content before putting it in context sounds great, I might also try that
4
4
1
u/r_sukumar May 18 '26
What kind of context window does the small models for coding recommended for smooth experience especially when inference setup done in a laptop with single GPU?
3
u/Glittering_Focus1538 May 18 '26
32k is the sweet spot for single-GPU laptops. SmallCode's token budgeting keeps actual usage well under that. SmallCode auto-compacts history, summarizes large files to signatures, and never dumps raw content. You rarely hit the ceiling even on 32k models.
128k is nice-to-have but honestly unnecessary for most work. The context management is designed to work within small windows, not rely on large ones. If you're choosing between a 14B model at 32k and an 8B model at 128k on limited VRAM, take the larger model with less context, the reasoning quality matters more than window size.
1
u/Typhoon-UK May 20 '26
How about ultra small models like qwen3.5-3b or omnicoder-9b. I have an old laptop with 4gb nvidia vram. Will this work well?
1
1
May 18 '26
This looks great. Is the harness adaptable enough to work with the cheaper, larger models as well? Like deepseek flash and kimi?
I love the idea of a local model but my m1 probably isn't going to handle it.
3
u/Glittering_Focus1538 May 18 '26
I doubt you m1 can't handle gemma 4 e4b, I made a python tower defense game with it earlier as a proof of concept.
2
u/Glittering_Focus1538 May 18 '26
It can't hurt a larger model, just make the token usage more effecient, so small models get their hand held and large models get an effecient template to work within.
1
u/CorrectTemperature65 May 18 '26
does this offer any benefit for the bigger models?
1
u/Glittering_Focus1538 May 18 '26
It's much more token efficient, so outputs don't take as long, built in project guards so you don't have to say "continue" a million times, it will continue till it's done with the task it's been given. Ships with a memory and codebase MCP which massively cuts down on context usage leaving more for your coding tasks, try it out, there's much more I haven't even mentioned yet
0
u/Maddolyn May 18 '26
that's not how ai models work. if you have to keep saying continue that means your prompt is too open to interpretation and then the ai takes the shortest route, especially if the reasoning is not strong enough to make it think about what you actually want
1
u/That_Frame_964 May 18 '26
Your comment isn't entirely accurate dude. That is ONE of many reasons. Models, depending on training data also can naturally want to include humans in the loop and will ask, even without instructions to do so, whether to continue or ask for additional idea. Even reasoning models will sit back and try to include humans in the loop UNLESS even if they've been told not to. For example, Minimax even in PI and a good prompt gears towards human input more than other models.
2
u/CorrectTemperature65 May 18 '26
You've obviously never watched a thinking model think itself into a cycle of doubt: aha moment, realising it's wrong, and think loops
0
1
1
u/g-giannis May 22 '26
Why you didn’t use the existing pi agentic tool? 🙂 It’s already so thin client and produces veryyy good results with local small models.
1
3
u/Deep_Ad1959 May 19 '26 edited May 24 '26
the gap that benchmarks miss is that swe-bench style scoring rewards 'patch compiles and tests pass on a clean repo' but most agent failures in real work are environment failures: stale lockfile, wrong python version, the package manager wants a credential, the test suite needs a service that isn't running. a 4B model can absolutely hit 87 on a curated set and still faceplant on day one of someone's actual repo because the agent can't read its own shell prompt to notice that pip just printed a warning. the differentiator I'd watch for in your next eval is how the agent recovers when stdout returns something other than what the harness expected, not whether the diff was right on the first try.
fwiw runner is the production-side of this for non-coding agent work, drives 40+ real business apps with the same agent loop and the env failures you described (stale auth, missing service, half-loaded ui) are exactly what we instrument and recover from, the benchmark-vs-reality gap shows up identically there, https://s4l.ai/r/5shysjhz
3
1
1
u/sdcasimiro May 18 '26
That is good news. I'm using OpenCode with Deepseek V4 Flash and I'm having really descent results. Imagining what Deepseek is capable of with SmallCode. Thanks!
1
1
u/sdcasimiro May 18 '26
Just tried. But the agent doesn't work at all, sorry. It keeps processing with no actual response.
1
1
1
1
1
u/Competitive_Lie5326 May 31 '26
That's sensational at first glance, what you've created there. I haven't tried it yet. But a lot of thought has gone into it. 87%? That's a bit too much intelligence for such a small model. But a lot of effort has gone into your project! i testet gemma 4 lokal, qwen models local are much better!
1
u/lucasbennett_1 May 31 '26
compound tools approach solves the actual prblm nobody actually bothers.... small models dont fail because they are dumb rather they fail bcz harnesses designed for frontier models give them 6 sequential tool calls when one would do. the improvement loop + decompose on failure combo is solid engineering
1
0
-2
u/charmander_cha May 18 '26
Como foi criada a parte do grafo? Apenas uma representação lógica em texto?
3
May 18 '26
[removed] — view removed comment
5
u/Glittering_Focus1538 May 18 '26
Pi's philosophy is "get out of the model's way." SmallCode's is "compensate for the model's weaknesses." Those are opposite design goals, building it as a Pi extension would mean fighting the framework. Started from scratch so the architecture could be designed around intervention (improvement loops, token budgeting, tool scoring) from day one. Code is MIT though, anyone can port the techniques to Pi if they want.

7
u/jixbo May 18 '26
Cool project. I does not seem to read the smallcode.toml in the root of the project (which is not the right place for it anyways), so it's a pain to get models working.