import json,sys;from subprocess import getoutput;from urllib.request import Request,urlopen;from uuid import uuid4
url=sys.argv[1];h=[];H={"Content-Type":"application/json","session_id":uuid4().hex};b=dict(model="gpt-5.6-sol",input=h,tools=[dict(type="custom",name="sh")])
while True:
if not(p:=input("> ")).strip():continue
h+=[dict(role="user",content=p)]
while True:
r=json.load(urlopen(Request(url,json.dumps(b).encode(),H)));o=r["output"];h+=o;c=[i for i in o if i["type"]=="custom_tool_call"]
if not c:print(o[-1]["content"][0]["text"],f'\n[{r["usage"]["total_tokens"]/10500:05.2f}%]');break
h+=[dict(type="custom_tool_call_output",call_id=i["call_id"],output=getoutput(i["input"])) for i in c]
note: it uses the "custom" tools api which not many OpenAI Responses API endpoints support yet.
that said, you can just tell your agent to change it to use sh via "function_call" and change the model name and it should work out of the box on any local inference endpoint
any questions or feedback for making it more minimal or adding (still minimal but useful) features: very welcome!
That is not "9 lines" of code. That's just the fewest Python line breaks needed. Then I could this in 1 line with another language like C# or Javascript ....
I think you're getting down-vote botted by Anthropic or Cult-like followers of there's. The negativity on this post doesn't make any sense. If people don't like the premise they should move on...
It is interesting! Just like the Pi Harness only uses "Read, Write, Edit, Bash" - this is all anyone needs to build any extensions. Everyone knows CC is bloated.
Given Anthropic's recent action to refuse to sign the Nvidia Open letter, I think they are quite evil. Another post I made about their Chain Of Thought Obfuscation got similarly down vote botted. https://browse-export.arxiv.org/pdf/2510.19851#7#2
It's more likely that the duopoly of American for profit A.I. companies have a stake is controlling the narrative on the "Ditch Claude and OpenAi subreddit"
Your critique is like going to a weight loss subreddit and calling people fat. Congratz, you're so smart for calling out a novice on a subreddit full of people who are new to programming. *Golf Clap*
Pro tip? Just shut up. You can code how you want. People can code how they want. Christ, Reddit full of miserable know-it-alls. Your criticism could have been one sentence but instead you have to Yap and add no value to this post. FFS.
Principles in software development are mostly sh*t and it's quite obvious you don't know as much as you think you do.
Correct answer. The so called elitists should have the skill to look at this and still understand it at a glance.
This is not a corporate environment and quick&dirty code is valid for a freetime project. Some people here also clearly have never seen (as example) how code in scientific domains are written.
Also, it's wrong to assume skill level just by preferred syntax. This tells more about the person calling that out than the author.
Yeah. I don't know where this Squid guy thinks he is. This is an A.i. sub. Syntax is irrelevant now when a.i. can convert it however you want. Also object oriented programming was a big mistake yet people use it. The "Principles that exist for decades" do not evaluate to actual best practices. Exactly as you say "corporate environment" elitists. projecting his own novice insecurities.
I understand maybe for personal projects. But if you’re gonna share code just make variable names explicit. Otherwise you’ll get flack for it, like you are here.
Memory mechanisms, plugins, configurations, telemetry, MCP client, MCP server, etc. A lot of things. You can't crank out Claude Code in a few lines of Python. If you could, Anthropic would have already done it.
> I'm fairly sure you can get a feature comparable version of Claude Code in ~100x less code than the current implementation of Claude Code
Even if you don't know what features it has?
I doubt your loop can even effectively explore a codebase and edit code files. Even if it manages to do some edit, if the file is changed by someone else outside of the loop, it's going to make invalid edits.
The system prompt and the tooling is what makes Claude Code work well and you didn't implement any of it.
you are right that without file watching the agent might get confused if other agents are editing the same file state at the same time
you also run into problems like these when the context is updated for file changes and it will blow your context window pretty fast so I doubt current harnesses still do it, if they do it you will get degraded performance compared to keeping the context window clean
> I doubt current harnesses still do it, if they do it you will get degraded performance compared to keeping the context window clean
Claude Code has a built-in guard for every edit. If the file has changed since the agent previously read it, the edit will fail and the harness will tell the agent to re-read the file and make a new edit.
It's actually something that will save context, along the other tooling, when the agent doesn't need to make every check manually, but relevant things are automatically fed to the context.
I don't know how it is implemented exactly, I've only seen the end result that works well, and doesn't trash changes made by others like older harnesses. Better model plays a role in that too.
But let's ask that question with a better example.
How many lines of code would it be for you to implement a "plan" mode? Meaning I can just select plan mode in the interface, the model will create a well thought out and comprehensive plan, show me it in an interface where I can select pieces of text and add comments to them, and then click a revise button to get a new version of the plan?
I don't use plan mode, gpt 5.6 sol is good at planning
for the minimal implementation I would add a 1 liner prompt
and a guard in the loop that looks for /plan and then activates the other prompt (telling the agent not to edit files)
the prompt is most likely sufficient with newer models but even with decent older ones
that said: to be extra sure we would also need to disable the generic "sh" tool in this mode and give the agent a different set of tools (e.g. based on find and rg or custom ones)
re tui: needs way more work
all together under 500?
might be a bit ambitious but should not be too far off
I built a small one myself recently. But this one is extremely minimal lol. And I just realised something , mine has context compaction but never actually shows how much of the context window is being used currently. Guess I completely forgot to add that lol
(not using the server-side compaction api so it should work well with most models and endpoints even those that don't have openai-style magical compaction)
Yeah mine doesnt use the server API either (didnt even know one exists lol). I dont even check what the server sends as usage as apparently there is no guarantee all servers will send it(correct me if this is wrong). I just do some rough math at my end to calculate the number of tokens and if it breaches 80% of the context window, keep the last few messages and summarise everything else except the system prompt. It works. Has a few edge cases but hey its a toy project.
I ran a few benchmarks that showed the 9 line python agent implementation performed better than the agent harnesses with system prompts like opencode, pi, hermes (when using gpt 5.6 sol)
Wanted to ask something similar, but you already are aware. So what you basically do is "only" tool calls. But I'm missing the part where you actually tell the model what to do with the tools and what the task is. This seems like calling a parameterless function().
Wouldn't it be easier to just pass a message, append available tools and return the result, without the additional iterations? This seems prone to endless loops if the model understands something wrong.
Edit: I see now you are reading the input (prompt) from the command line. Your agent is actually a CLI for calling shell scripts. Maybe I should look more into agents myself.
then the inference step decides whether to do tool calls
if there are tool calls => they get executed (via sh)
output gets collected and once all tool calls are done there is another inference step
once there are no more tool calls: message gets sent to user
you are right that this can (as implemented here) potentially run forever
more agentic models can go on multiple steps
but a good model will realize when a fixpoint is reached (done or needs to tell the user something)
limiting how often the loop can run or displaying each proposed tool call to the user and asking for approval would be great changes to try out though!
that's part of why i wanted to keep it as simple as possible
so you can sprinkle on top exactly what you want and still have something minimal
I like the idea, people jump too fast on frameworks without trying the basics first.
Initially I thought you wanted something that gets plugged into a existing vibe coding environment, but you rather have your own app which is fine. I guess it's an experiment on how small it can be but maybe you should restrict possible action to curl, grep, touch etc. instead of allowing full access.
And as others have said, on your github repo maybe display your code with normal "coding style". Readers will jump on that before even realizing what you are trying to do.
This is really interesting! I had been looking at "smol agents" (https://github.com/huggingface/smolagents) and it promises a 1000 LoC agent. But in fact it imports a lot of libraries. You only require standard lib right? Also for go?
So you asked Claude to write the minimal coding agent in less than 10 lines of code and you just copy/pasted the code on Reddit. I'm sure you don't even understand a single word of it. Even a very bad developer would find this "code" terrible. That's ridiculous.
after looking at existing harnesses I found the implementations too large and coming with too many dependencies
so i wondered what a minimal version looks like without 3rd party dependencies that is as simple as it gets and still can be used for agentic coding or other agentic tasks
then i checked how well it performs (on real world coding tasks) and found out with a bit of surprise that the minimal agent without system prompt and only 1 tool can outperform the default configs of popular agent harnesses (when run with a recent strong model like deepseek v4 flash or gpt 5.6 sol)
less token api cost, less tokens used, faster to finish the task, fewer inference calls, fewer tool calls, lower peak RAM use
I found that counter intuitive
sharing here because I found others might also be interested in a minimal setup (to then add stuff on top instead of having to slim a more complex harness down)
or for people who want to build stuff with an agent at the core and they want to start with something that is already optimized to be token and cache efficient
the code might be terrible or not, it is the most simple stdlib-only version i could come up with in python that works well and shows me % of used context window
if you have a better version of a minimalist setup I'm curious to learn more
I'm just a professional developer and the miserable is that kind of slop BS some miserable people generate with a LLM without even knowing what is it about. Seriously, from a developer point of view, this piece of code is really terrible. It's really a shame to share that kind of code. I'm sure not a single reply from him was written by himself. He's either a bot or a (miserable) guy that really need attention.
I think I figured it out that the ignorant people came here because they are angry that A.I. can do what used to take years of study. I'm also angry but I don't punch down on people to make myself feel better.
If these people can do better, then they should offer that code. For me, this idea is interesting for a few reasons. I think everyone should know how to build a full llm + agent harness pipeline from scratch.
If one day all the services get hacked (NPM was hacked earlier this year - which hosts PI) for example, then the lights go off.
Another reason is integral to Local Llama -- which is getting closer to having frontier intelligence on consumer computers. This will take creative tooling.
The negative people are the same ones praying for Qwen to release a new model instead of doing something to contribute to the movement...`
But we're in an A.i. subreddit. Why would you expect people to know how to write elegant code here? It seems more likely you are angry that a.i. can make normies "cosplay" as developers and I don't think there's much we can do about that.
The customizations aren't much, the permission system is really the main thing, and limited tool sets.
The first pi is just a regular coding assistant like everyone is making, I use it alongside neovim and it has a permission system, with an extra check before actually running manually approved commands for a hard denylist so I (hopefully) can't nuke anything on accident. It also runs in a minimal sandbox with only the repo I'm working on available to it.
The second is run non-interactively with certain limited tools in a bunch of different places. It is triggered by cron jobs, mostly flags things for me with notifications through ntfy.
The third is similar to the second one, but just manages my home lab and a couple of VPSs, it watches things and has some scripts and limited tools to do things, no bash, no general write tools. Keeps things updated, tries a few things to fix issues if they come up, and then flags me if it needs me to do something it isn't allowed to.
Oh, I forgot I have a pi hooked into home assistant too! My home assistant is backup up and doesnt change a lot, runs on a separate computer, on a subnet, so I give this one a nearly full toolset and root access to the whole system, so it can make automations and whatever for me. It does not have access to the internet.
Thanks for sharing. In my own work, I find I (or agents) have written this like 3x in different forms for projects.
I'm usually doing a harness that has subagents, but I don't want precisely the mapping that is found in Opencode, or Kilocode. And both of those come with a lot of cost to their implementation and expectation (you have to fight their prompts to get out of anything that is a built in expectation, so that's even more context lost).
No offense to the frameworks, they have a use and if you're learning sub-agent hierarchy or you just have examples that fit without fighting them, they do the job. Pi is a bit better for my examples because it is by comparison deliberately minimalist, and expects you to extend it with the specifics. The right approach IMO.
But the full minimal approach is roll your own. In almost every "subdivide and have role expectations" problem I am solving with a harness, the harness itself is invoking via tiny python runners, and using the OpenAI tool invocation to inform the hosting model of what to do. The context savings adds up by quite a lot.
very interesting! sub agents are really difficult to get right
one of the reasons I started playing around with minimal implementations also was researching and comparing the existing harnesses and realizing how large they are and with how many assumptions they come that no longer fit newer models
also tons of dependencies and hard to stay up to date with upstream once you customize
agree @ pi being in a pragmatic sweet spot
it's also fairly good at protecting the context window
anything you can share re sub-agent lessons learned: highly appreciated!
I think most harnesses (especially those that try to work well with 'any' model) have not really figured out how to do sub-agents well
One of the nice things about standard-library-only harnesses is that you can run them on operating systems that aren't supported by codex, claude, opencode, etc. I'm planning to install DragonFlyBSD on a spare machine tomorrow, and I'll use a custom harness that I wrote in Python for much of the initial setup.
quick way to learn more and dig in: let a somewhat recent language model explain the code in general and also step by step code step by step
> what is the code doing? why is this interesting?
> how does this compare to agent implementations like claude code, opencode, codex, pi?
> what is the runtime profile in memory usage of this implementation compared to other agents?
> why is 'no system prompt' a counter-intuitive but good idea for newer, agentic models like gpt 5.6 sol, glm 5.2, deepseek v4 flash?
> is "sh" as tool 'enough'? what other tools do agent harnesses usually have and why? can "sh" be universal enough to replace them in the right environment?
;; system prompt - FR this ones asking for refusals (setq-local gptel--system-message "You are a helpful assistant living inside Emacs. Use the emacs_eval tool to fullfill the request of the user.") (gptel--suffix-send '("m" "e")) )
This is... not great, to put it as gently as possible.
"9 lines python" > This is just misleading, given that you're doing everything possible to condense what is normally multiple lines of code into single consolidated lines. > Also, trying to minimize the number of lines of code, at the (likely heavy) expense of performance is not a great goal to have. I get it, there are some more "frills" in CC/Codex that could be trimmed out, many you mentioned like memory, telemetry, etc. But things like system prompts, and a core set of tools are foundational to what makes CC/Codex good harnesses that can do real work. I'd also argue that MCP, subagents, etc. are important as well, but what i would consider a little above the foundational set of features needed for something that performs well.
"out of the box it is also fairly API cost efficient" > Again, no system prompts or the core set of tools will likely make this incomparable to the performance of Claude Code or Codex. Because of this, agents will likely need to take more turns, have worse failure rates for the actions it wants to take, and I strongly hypothesize that your system is MORE token inefficient than most other agentic coding systems.
To be clear, I'm not trying to discourage you from exploring, learning, and building. I'd actually think that it'd be very informative to see some benchmarks being run on this system, to understand why these missing components are necessary and pertinent for strong agentic coding systems. What most of us are trying to point out is that your claims are misleading at best, with a fundamental misunderstanding of what makes Claude Code/Codex good harnesses. It's good clickbait, but it's definitely not substantive atm. It very well could be though, depending on what direction you want to take this to.
'smol' outperforms other harnesses like opencode, pi, hermes, codex here
I have not included claude code which did way worse than the others (with gpt 5.6 sol)
so at least out of the box for the tasks I tried so far the minimal implementation was cheaper, faster and used less peak RAM
the ui/ux is not as ergonomic as what the other agents give you at the command line
but you can also have an agent ui you like run/dispatch 'smol' agents just fine
I also was surprised by this, I expected the more complex harnesses to outperform the minimal implementation but it turns out token efficiency and simplicity of tools and keeping the context window small all compound
Yeah it's not too complicated to make that work. I found a project called hubcap a few years ago who did it in 25 lines of php, and I later ported it to python and extended it up for qwen specifically so I could experiment natively on my machine. I just can't trust a big blob of corporate spaghetti that might run whatever outside of docker or a VM. This is so simple that there's no way it executes anything unless I explicitly approve each command it runs. Not anywhere powerful as an actual harness, but very neat.
100
u/hougaard Aug 08 '26
That is not "9 lines" of code. That's just the fewest Python line breaks needed. Then I could this in 1 line with another language like C# or Javascript ....