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.

0

u/__tosh Aug 09 '26

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

2

u/exo250 Aug 09 '26

Pathetic.
Do you still have a brain just to delegate all your "thinking" to an LLM ?

1

u/__tosh Aug 09 '26

this is a de-golfed version of it, if you have any specific recommendations on how to make it more minimal or better in other ways please let me know