Home / Blog / Build your own Claude Code. But brilliant and utterly…
Tech News

Build your own Claude Code. But brilliant and utterly indifferent

An open-source blueprint demonstrates how to build an autonomous coding agent using Python 3.12 and Claude Haiku in 150 lines of code with three tools.

By Dillip Chowdary β€’ Nov 09, 2026 β€’ Source: github.com

Build your own Claude Code. But brilliant and utterly indifferent

Developer Vitalik released Marvin Code, an open-source architecture that constructs an autonomous coding assistant using Python 3.12 and language model APIs in 150 lines of code. According to github.com's report, the implementation demonstrates how to build a terminal programming agent from fundamental primitives rather than complex framework wrappers. The architecture pairs an OpenAI-compatible completion endpoint, such as OpenRouter running Claude Haiku, with an active agentic feedback loop and native operating system tools to inspect, modify, and test application source code directly inside a local workspace.

This technical breakdown analyzes the mechanics of the Marvin Code agent, examining how the implementation transitions from a basic chat interface to an iterative tool-calling engine. Software engineers and systems architects seeking to understand how commercial coding companions like Claude Code operate under the hood will find a concrete blueprint for context management, tool definition schemas, and local execution sandboxes. The analysis walks through the developmental phases required to implement stateful conversation history, wire file system input and output handlers, and execute shell subprocesses safely.

What shipped in Build your own Claude Code. But brilliant

The core deliverable is a transparent terminal coding assistant implemented in 150 lines of clean Python 3.12 code designed to work across OpenAI-compatible API gateways. The system establishes its foundation through an initial interaction that pays tribute to Brian Kernighan by verifying connectivity with a standard greeting instruction. The architecture defaults to the OpenRouter gateway at https://openrouter.ai/api/v1 utilizing Anthropic Claude Haiku 5.5, though developers can swap in alternative model providers by modifying standard environment variables. Stripping away heavy auxiliary dependencies proves that an autonomous agent requires only standard Python networking libraries and structured JSON payloads.

Beyond raw text completion, the release ships a functional tool execution engine containing three concrete operational capabilities: file inspection, file generation, and shell execution. The read_tool function opens target paths in read-only mode to extract file contents directly into the conversation history, while the write_tool function creates or overwrites disk files with newly generated code. To execute compiler checks and test suites, the bash_tool function runs arbitrary shell strings through subprocess.run. These three functions are registered inside an internal TOOLS dispatch dictionary, which converts their docstrings into formal function calling schemas and supplies them to the language model.

What improved in Build your own Claude Code. But brilliant

The transition from an isolated prompt script to an agentic architecture represents a fundamental improvement in runtime state and capability management. In the earliest introductory phase, the script executed a single stateless request that discarded conversation data immediately upon completion, leaving the model unable to recall previous instructions or context. By introducing an in-memory message history array in forty lines of code, the system allows user prompts and assistant completions to accumulate continuously across turns. This persistent message context transforms the model into an interactive assistant that references earlier decisions and tracks iterative changes across complex multi-turn discussions.

Architectural DimensionStateless PrototypeAgentic Implementation
Codebase Footprint40 lines of code150 lines of code
Active Local Tools0 tools supported3 tools (write, read, bash)
Context Retention0 turns retainedFull message history array
Execution ArchitectureSingle request-responseIterative while True feedback loop
Exception HandlingProcess terminationModel tool-role feedback and recovery

The second major improvement replaces passive text generation with an autonomous while loop that provides continuous execution feedback to the model. Rather than crashing when an operating system operation encounters an invalid file path or a broken shell command, the system captures Python exceptions and converts them into structured tool role messages. The language model receives the exact error output matched against the unique tool_call_id, giving it the necessary context to analyze the failure, adjust its parameters, and attempt alternative solutions. This self-healing operational loop elevates the script into a resilient development environment capable of evaluating failures and iterating independently.

What you gain from Build your own Claude Code. But brilliant

Adopting this minimalist agent design grants engineers complete visibility into the mechanisms governing automated code synthesis. Because the entire agentic loop resides within 150 lines of straightforward Python, developers avoid the opacity, latency overhead, and breaking changes typical of heavyweight orchestration frameworks. Developers gain precise authority over token expenditures by seeing exactly how prompts, message arrays, and tool manifests are encoded into raw JSON payloads before transmission to the inference provider. This direct inspection ensures teams can audit system behavior, enforce custom security boundaries around file system writes, and inspect raw API roundtrips without navigating layers of indirection.

Furthermore, the architecture introduces project-level behavioral control by standardizing instructions through configuration files such as AGENTS.md or CLAUDE.md. By reading these markdown documents at initialization and pre-pending them to the prompt context, engineers can enforce coding standards, architectural guidelines, and repo-specific rules before the model executes any bash or file operation. Teams gain an extensible foundation where adding capabilities requires nothing more than writing a standard Python function, annotating it with a JSON schema docstring, and registering it in the TOOLS dictionary. This modular pattern makes it straightforward to integrate specialized tools, subagents, or domain-specific workflows.

Build your own Claude Code. But brilliant and utterly indifferent
Illustration Β· Pexels

How to get Build your own Claude Code. But brilliant

Deploying the custom agent environment requires Python 3.12 or newer alongside an active API token configured in the local terminal environment. Developers running commercial command-line agents can update their installations or set up the official Claude Code CLI via the global package manager to establish a baseline development environment. Running the global installation command ensures system dependencies and command-line entry points are fully resolved across Unix and Linux platforms:

Advertisement

Tech Pulse Daily

Get tomorrow's pulse first

Join engineers who read Tech Pulse before stand-up. Free, weekday mornings.

Command
npm install -g @anthropic-ai/claude-code

To refresh an existing CLI deployment with upstream patches, engineers execute the built-in update utility:

Command
claude update

Connecting the custom Marvin Code architecture requires exporting the inference endpoint and target model parameters, pointing the client to OpenRouter or an equivalent OpenAI-style provider:

Command
export API_KEY="your-api-key"
export BASE_URL="https://openrouter.ai/api/v1"
export MODEL="anthropic/claude-haiku-5.5"

Once environment variables are active, developers can launch sessions pinned to specific model versions or alter target models directly during active terminal sessions. When launching a dedicated agent session from the shell with a pinned model identifier, engineers pass the model parameter flag on startup:

Command
claude --model fable

Within an active interactive session, operators switch reasoning backends dynamically without restarting the process by typing the slash command directly into the prompt:

Command
/model fable

Alternatively, targeting the extended release identifier provides precise version pinning:

Command
/model claude-fable-5-1

To establish permanent session defaults without passing parameters repeatedly, developers configure the default model identifier within shell configuration profiles:

Command
export ANTHROPIC_MODEL="claude-haiku-5.5"

What to watch after Build your own Claude Code. But brilliant

While the 150-line implementation successfully replicates core agent capabilities, running unrestricted shell commands and file writes exposes significant operational limits that require careful engineering oversight. The bash_tool runs commands directly through the host shell without process isolation, sandbox containers, or permission gates, creating risks of unintended file deletion or command injection if the model hallucinates commands. Production environments require adding boundary enforcement, approval checkpoints, and restricted file system path filters before delegating autonomous tasks. Developers must also monitor non-deterministic outputs from underlying providers, where minor variations in prompt formatting can trigger unexpected tool calls or produce invalid JSON arguments.

The roadmap highlighted by the project emphasizes three critical architectural extensions: token compaction routines, modular skill registries, and hierarchical subagent coordination. As conversational context expands during prolonged development sessions, repeatedly transmitting full chat histories quickly saturates context limits and inflates API costs. Implementing context pruning or summarizing older messages will be essential to sustain long-running refactoring workflows. Furthermore, extending the single-agent loop to delegate subtasks across specialized child agents will enable teams to run parallel code reviews and test generation without polluting the primary context window, providing a structured path from an educational script to an enterprise-grade programming harness.

Developer Action Items

  • ☐ Diff the official changelog for OpenAI / Anthropic / Claude 3.12 before you bump β€” APIs, defaults, and removed flags only.
  • ☐ Install through the vendor's documented channel in staging; keep a one-command rollback and time-box the canary.
  • ☐ Grep your repo for old flag names, lockfile pins, and plugin versions that the notes mark as breaking.
  • ☐ Prefer the first patch cut over the day-zero tag unless you have a reason to be on the leading edge.
  • ☐ If HN Claude/Codex/Fable did not name a region, plan, or SKU, screenshot the official availability line before you promise it to users.

Build your own Claude Code. But brilliant FAQ

What programming language and dependencies are required to run Marvin Code?

Marvin Code requires Python 3.12 or newer and an API key for an OpenAI-compatible provider like OpenRouter. It relies on standard library modules such as json, os, subprocess, and urllib without requiring third-party agent orchestration frameworks.

Which local tools are built into the Marvin Code architecture?

The architecture implements three core tools: write_tool for creating or overwriting files, read_tool for reading file contents, and bash_tool for executing shell commands via subprocess.run. The language model requests these tools using standard JSON function calling schemas.

How does Marvin Code maintain conversation context across turns?

The agent stores all user prompts, assistant completions, and tool outputs inside a growing in-memory message history list. This entire conversation array is sent with each API request so the model retains full context of earlier interactions.

How does the agent handle tool errors during execution?

When a tool execution encounters an exception, the system catches the error and packages it as a structured message with role tool and the matching tool_call_id. The model receives this error feedback directly, allowing it to analyze the failure and self-correct its parameters.

Sources

Dillip Chowdary

Author

Dillip Chowdary

Writes Tech Bytes coverage of AI, engineering, and the tools that actually ship. Editor of Tech Pulse Daily.

Related on Tech Bytes

Advertisement

5-min tech signal

Weekday briefing for engineers who skip the noise.

No spam Β· Unsubscribe anytime

Advertisement

✈️ CareerPilot

Your AI job-search copilot

Match your resume against live Ashby, Greenhouse & Lever openings β€” fit scores, job-specific resume optimization and email alerts.

Find matching jobs β†’

Free Tools

Browse all tools β†’