A Minimal Claude Code Clone in 200 Lines
The mental model that a coding agent is just an LLM plus filesystem and shell access, orchestrated by a stateless loop, demystifies tools like Claude Code and Devin. Understanding this loop makes it practical to build custom agents for niche workflows without heavy frameworks.
The core of a Claude Code-style coding agent fits into roughly 200 lines of JavaScript. An LLM receives a task like "create a react+vite todolist," breaks it into steps, and decides which tool to invoke at each turn. The tool palette is deliberately minimal: write files and run shell commands. LangChain handles model abstraction and tool binding, while four message types (System, Human, AI, ToolMessage) maintain the conversation context across stateless LLM calls. The agent runs inside a `while(true)` loop that invokes the model, executes any requested tool calls in parallel via `Promise.all`, feeds results back as ToolMessages keyed by `tool_call_id`, and exits only when the model returns a response with no further tool calls. Five common pitfalls are flagged: forgetting to push AI responses back into the messages array, omitting `tool_call_id` on ToolMessages, missing loop exit protection, skipping try/catch on tool execution, and treating async functions as synchronous.
LangChain's value proposition is not enabling new capabilities but reducing the friction of switching LLM providers and parsing tool-call responses.
The `tool_call_id` field is the linchpin of multi-tool parallelism: without it, the LLM cannot match results to the calls that produced them.
Wrapping tool execution in try/catch and feeding errors back to the LLM as structured results lets the model self-correct rather than crashing the agent.
The entire agent architecture is stateless at the model level; all continuity lives in the messages array that grows with each loop iteration.