Live data from Hacker News

How to code Claude Code in 200 lines of code

mihaileric.com

11–20 of 249 posts

Re: How to code Claude Code in 200 lines of code

#11
post #6

This article was more true than not a year ago but now the harnesses are so far past the simple agent loop that I'd argue that this is not even close to an accurate mental model of what claude code is doing.

it seems to have changed a ton in recent versions too — I would love more details on what exactly I find it doing what I in the past had to interrupt and tell it to do fairly frequently now

For one thing it seems to splitting up the work and making some determination of complexity, then allocating it out to a model based on that complexity to save resources. When I run Claude with Opus 4.5 and run /cost I see tokens for Opus 4.5, but also a lot in Sonnet and Haiku, with the majority of tokens actually being used by Haiku.

Re: How to code Claude Code in 200 lines of code

#13

This article was more true than not a year ago but now the harnesses are so far past the simple agent loop that I'd argue that this is not even close to an accurate mental model of what claude code is doing.

But does that extra complexity actually improve performance? https://www.tbench.ai/leaderboard/terminal-bench/2.0 says yes, but not as much as you'd think. "Terminus" is basically just a tmux session and LLM in a loop.

I'm not a good representative for claude code because I'm primarily a codex user now, but I know that if codex had subagents it would be at least twice as productive. Time spent is an important aspect of performance so yup, the complexity improved performance.

Re: How to code Claude Code in 200 lines of code

#14

This article was more true than not a year ago but now the harnesses are so far past the simple agent loop that I'd argue that this is not even close to an accurate mental model of what claude code is doing.

Obviously modern harnesses have better features but I wouldn't say it invalidates the mental model. Simpler agents aren't that far behind in performance if the underlying model is the same, including very minimal ones with basic tools.

I'd say it's similar to how a "make your own relational DB" article might feature a basic B-tree with merge-joins. Yeah, obviously real engines have sophisticated planners, multiple join methods, bloom filters, etc., but the underlying mental model is still accurate.

Re: How to code Claude Code in 200 lines of code

#15

here's my take, in 70 lines of code: https://github.com/kirjavascript/nanoagent/blob/master/nanoa...

I mean, if you take out the guard rails, here's codex in 46 lines of bash:

    #!/usr/bin/env bash
    set -euo pipefail
    
    # Fail fast if OPENAI_API_KEY is unset or empty
    : "${OPENAI_API_KEY:?set OPENAI_API_KEY}"
    MODEL="${MODEL:-gpt-5.2-chat-latest}"
    
    extract_text_joined() {
      # Collect all text fields from the Responses API output and join them
      jq -r '[.output[]?.content[]? | select(has("text")) | .text] | join("")'
    }
    
    apply_writes() {
      local plan="$1"
      echo "$plan" | jq -c '.files[]' | while read -r f; do
        local path content
        path="$(echo "$f" | jq -r '.path')"
        content="$(echo "$f" | jq -r '.content')"
        mkdir -p "$(dirname "$path")"
        printf "%s" "$content" > "$path"
        echo "wrote $path"
      done
    }
    while true; do
      printf "> "
      read -r USER_INPUT || exit 0
      [[ -z "$USER_INPUT" ]] && continue
      # File list relative to cwd
      TREE="$(find . -type f -maxdepth 6 -print | sed 's|^\./||')"
      USER_JSON="$(jq -n --arg task "$USER_INPUT" --arg tree "$TREE" \
        '{task:$task, workspace_tree:$tree,
          rules:[
            "Return ONLY JSON matching the schema.",
            "Write files wholesale: full final content for each file.",
            "If no file changes are needed, return files:[]"
          ] }')"
      RESP="$(
        curl -s https://api.openai.com/v1/responses \
          -H "Authorization: Bearer $OPENAI_API_KEY" \
          -H "Content-Type: application/json" \
          -d "$(jq -n --arg model "$MODEL" --argjson user "$USER_JSON" '{model:$model,input:[{role:"system",content:"You output only JSON file-write plans."},{role:"user",content:$user}],text:{format:{type:"json_schema",name:"file_writes",schema:{type:"object",additionalProperties:false,properties:{files:{type:"array",items:{type:"object",additionalProperties:false,properties:{path:{type:"string"},content:{type:"string"}},required:["path","content"]}}},required:["files"]}}}')"
      )"
      PLAN="$(printf "%s" "$RESP" | extract_text_joined)"
      apply_writes "$PLAN"
    done

Re: How to code Claude Code in 200 lines of code

#16
post #8

This article was more true than not a year ago but now the harnesses are so far past the simple agent loop that I'd argue that this is not even close to an accurate mental model of what claude code is doing.

The article was also published one year ago on january 2025. (Should have 2025 in the title? Time flies)

Claude Code didn't exist in January 2025. I think it's a typo and should be 2026.

Re: How to code Claude Code in 200 lines of code

#19
There's a bit more to it!

For example, the agent in the post will demonstrate 'early stopping' where it finishes before the task is really done. You'd think you can solve this with reasoning models, but it doesn't actually work on SOTA models.

To fix 'early stopping' you need extra features in the agent harness. Claude Code does this with TODOs that are injected back into every prompt to remind the LLM what tasks remain open. (If you're curious somewhere in the public repo for HolmesGPT we have benchamrks with all the experiments we ran to solve this - from hypothesis tracking to other exotic approaches - but TODOs always performed best.)

Still, good article. Agents really are just tools in a loop. It's not rocket science.

Re: How to code Claude Code in 200 lines of code

#20
This reflects my experience. Yet, I feel that getting reliability out of LLM calls with a while-loop harness is elusive.

For example

- how can I reliably have a decision block to end the loop (or keep it running)?

- how can I reliably call tools with the right schema?

- how can I reliably summarize context / excise noise from the conversation?

Perhaps, as the models get better, they'll approach some threshold where my worries just go away. However, I can't quantify that threshold myself and that leaves a cloud of uncertainty hanging over any agentic loops I build.

Perhaps I should accept that it's a feature and not a bug? :)

Post reply on HN