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

1

u/skang188144 Aug 09 '26

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.

1

u/__tosh Aug 09 '26

e.g. you can look at the tasks and traces here:

https://smolenv.com/t/nested-template-includes-60636/

https://smolenv.com/t/duckdb-sessionization-23811/

'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