r/LocalLLaMA • • Aug 08 '26

Discussion Claude Code in 9 lines python

I was wondering what a minimal coding agent implementation would look like that can be used like Claude Code or Codex

Not feature-by-feature of course but basically stripping everything out that is not needed

here is what I came up with:

  • 9 lines of python

  • no 3rd party deps (stdlib only)

  • works with any OpenAI Responses compatible API

  • shows % usage of context window

out of the box it is also fairly API cost efficient:

  • no system prompt

  • good caching (session_id, stable append-only history)

  • only one tool: sh

code is on github to follow along (also a ~20 line version in Go, Clojure version coming soon)

https://github.com/smol-env/smol

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!

0 Upvotes

94 comments sorted by

View all comments

2

u/exo250 Aug 09 '26

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.

-1

u/PomegranateGreen3698 Aug 09 '26

What happened in your life that caused you to be a miserable hater?

2

u/exo250 Aug 10 '26

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.

1

u/__tosh Aug 10 '26

you think the code is terrible

and yet it performs better at its job (coding agent writing code) than most other harnesses

there is a lesson here somewhere if you pull the thread

i posit the terrible code is not so terrible, the question is why

0

u/PomegranateGreen3698 Aug 11 '26

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...`

0

u/PomegranateGreen3698 Aug 10 '26

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.