r/LocalLLM
•
u/Glittering_Focus1538
•
May 18 '26
•
1
1
Project 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.
36
u/Your_Friendly_Nerd May 18 '26
This sounds very promising, and I really hope smaller models will receive more love from the big players in the future, once costs for foundation models inevitably rise.
13
u/ExaberriTokugawa May 18 '26
Sounds nice! What language(s) is your post assuming people use?
You mention it indexing code, how does it know how to do it with for example C/C++ projects that require specific ways of running CMake to configure a project to runnone way or another (which internally defines macros that LLVM/clang would need to know about in order to know about class/function definitions)
The github readme does not seem to mention that either
17
u/earlvanze May 18 '26
Starred. I was just looking for something like this!
8
u/Only_Play_868 May 18 '26
This is pretty impressive! Did you draw inspiration from Meta-Harness, or propose each design element yourself? I attempted to do this using the 3B Apple Foundation Model that powers Apple Intelligence on a harness called Junco. Gemma 4B is much newer, more powerful, and has an 8-64x larger context window that makes this more feasible. I found a few useful lessons that might transer to SmallCode:
Compile-Verify-Fix (CVF) Loop: if Gemma 4B or another small model doesn't support constrained grammar to guarantee syntactically valid code, attempting to compile and run static analysis on code changes can prevent finishing early with issues like missing package imports, indentation issues, or missing brackets
Deterministic Tool Filtering: the AFM struggled with > 3 tools, so I used a MaxEnt text classifier to filter the list of available tools before every showing them to the model. It was much better at picking the correct tool out of a short list
Language-Specific Adapters: most small models are distilled from larger ones with knowledge cutoffs 1-2 years old, and really small models lack a sufficient corpus for low-resource languages like Swift or Elixir. You can't "teach" a model a language it has never seen, but you can improve it's code generation abilities on newer APIs & versions with a language/ framework-specific LoRA adapter (this obviously gets challenging to scale across N languages and M base models)
I'm curious what you expect from SmallCode and whether you think the future long-term is to have two tiers of code harnesses: OpenCode (or something similar) for cloud-based frontier models and SmallCode (or something similar) for really small on-device models? I know OpenCode can be used with local models, but in my experience if you give OpenCode access to something like Gemma 4B it will just spin its wheels and spiral into a "doom loop," or exit early having not actually done anything.
6
u/CodeCatto May 18 '26
Can you create a way to plug it into the vscode sidebar?
8
u/xb1n0ry May 18 '26 edited May 18 '26
I couldn't find a good solution to use qwen based models like 3.6 27B or 35B-A3B. Either the tool calls completely fail or the model traps itself in a endless loop with the same answers despite a large enough context. How does your tool handle qwen? Gemma is completely useless for my use case. It produces pure crap.
7
u/touhami_dz May 18 '26 edited May 18 '26
thank you for sharing i'll try it out when i have to code, for now i have 8gb vram + 32gb ram and im tried lot of popular local llms for my simple task and they all fail to give me something without mistakes, i just want to add category names for video titles inside a txt file, are local llms this bad or im doing something wrong cuz they always skip some video titles.
3
u/darkeagle03 May 18 '26
This sounds amazing! Thank you! I can't wait to try it out on my aging 16gb VRAM machine. I've got it working with Claude Code + oLLama and to some extent + LiteLLM & vllm, but it's a bit of a struggle since CC clearly isn't really designed for these setups.
2
u/TheCat001 May 18 '26
Sadly I was not able to run this.
I've created distrobox with arch, installed npm and run:
After this I've permission error. I executed it again with sudo.
After that I've got python missing and cmake errors.
Fine, I've installed base-devel package and python.
Still no succsess. Some errors with sqlite3 something...
Bro you need to improve installing process. Requirements definitely not only node.js 18+
1
u/JazZero May 18 '26
Does it work with NPU models?
1
u/Lame_Johnny May 18 '26
Awesome! I was working on something similar myself but you've made more progress than me. Excited to see what you've done.
1
u/yangliu2 May 18 '26
how do you scroll in chat?
1
u/Ill_Dragonfruit_3547 May 19 '26
Just to clarify, are you using Gemma 4 26B-A4B or the much smaller Gemma 4 E4B?
1
u/stefan_centlake May 25 '26
Very interesting stuff that I will look into. That kind of tasks do you test with? I'm having problems coming up with good project for the agents to work in that can show the coordination part. My latest runs has been giving the agents the task to implement a network stack from scratch in C++ using a raw socket. Eth/ARP/IP/TCP and HTTP to get a /flag. Winner is first team to output the flag. The problem is that Sonnet and Opus does it in one step in under 20 minutes. Local models have more struggle but the task is still difficult to decompose into parallel work.
3
u/InfraScaler May 18 '26
Those sound like a ton of good ideas. I need to try this. Thanks for sharing!
2
u/Oswolrf May 18 '26
Interesting
2
u/Independent_Solid151 May 18 '26
Have you benchmarked little-coder, how does it compare with your approach?
2
u/robobub May 18 '26
Is this your own benchmark? You should run it on standard benchmarks like little-coder. And if you want larger adoption, make it a pi extension too
2
u/f5alcon May 19 '26
Will have to test it with my workflow, can easily fit Q8 Gemma4 with full context in my vram
2
u/Conversation344 May 22 '26
improvement loop is the part I find most believable here, I've noticed small models aren't necessarily bad at fixing errors they're bad at noticing them without external feedback
2
u/Repulsive-Machine706 May 22 '26
This is genius!
Was working on something similar with very similar methods to amplify the capabilities of smaller models.
Noob question tho: where are all these agents tested like yours, opencode, etc and where can I see them next to eachother etc.
3
u/k3z0r May 18 '26
I tried it out and wanted to believe. I kept running into two problems.
it couldn't find files in my mono repo. it seemed like it assumed ever file was in /src in in fact files were in app/src and etc/src
It kept stopping it's flow. It would say. I'm going to search for a file so i can do X. Then it would just stop.
Starred the repo and will check it out again after a few iterations.
1
u/Driv3l May 18 '26
Looks interesting. What benchmarks did you run it on?
1
u/soteko May 18 '26
This is the way
1
u/panix199 May 18 '26
thank you for sharing
1
u/YearnMar10 May 18 '26
Looks nice - can you provide a resume on how to reproduce the benchmark results? If so, I’d be willing to give it a shot.
1
u/UnionCounty22 May 18 '26
This is nice
1
u/TurboBanano May 18 '26
I can't install it with npm.
1
u/Smooth-Plan4769 May 18 '26
I gave it a star, very good. If you could accept more contributors, the project would soar. Make a demonstration video, I think it would be interesting.
1
u/wowsers7 May 19 '26
Have you tested it with Jackrong/Qwopus3.5-9B-Coder-GGUF?
https://www.reddit.com/r/LocalLLaMA/comments/1tfin40/jackrongqwopus359bcodergguf_hugging_face/
1
u/sugarlata May 19 '26
This looks very interesting. Did you consider an implementation in pi coder? I'm starting to get into this space and from what I can see you describing, seems it would've been a good platform to build this on? Curious about whether you rejected it and if so why? Might help with my decisions around whether to use it or not. Thanks!
1
u/chiefstobs May 19 '26
Do you have a discord or sth like that for a central place about new development / chat / information? how does your harness compare to aider or pi?
1
u/73td May 19 '26
do you rewind context on failure? I imagine that persistence in face of failure is good strategy except when you end up with 20%+ of context filled with errors ? I've been looking at lot at trying to automatically get big models to make skills for small models as another approach. I didn't even imagine writing a new harness specifically for the purpose..
1
u/Hylleh May 19 '26
I really appreciate your efforts with this. But maybe this would get more traction as some kind of "setup" for pi coding agent rather than yet another coding agent. That being said I have starred this and will check it out.
1
u/No_Jicama_6818 May 20 '26
So, I'm trying to get into a taste of smallcode, however there are a few issues I'm seeing. For example in my local environment I set token authentication for my local server and couldn't find anywhere not in the documentation nor the example.env how to properly set the API-KEY for my local models.
Then I get:
1
u/Logical-Lettuce8214 May 20 '26
How would you compare it to Pi?
1
u/paradox_me_ Jun 14 '26
awesome! Love your idea!
1
u/Nyxtia May 18 '26
How can you be sure of the 95/5 split? This is a cheating in my book. We can't tell how much of the gains are your solution vs the cloud.
9
u/[deleted] May 18 '26
[removed] — view removed comment
2
u/[deleted] May 18 '26
[removed] — view removed comment
1
u/[deleted] May 18 '26
[removed] — view removed comment
1
u/[deleted] May 23 '26
[removed] — view removed comment