Skip to content

wrencode

wrencode is a minimal agent harness for coding, in a single Python file. A harness is everything around the model that turns it into an agent: the tool-calling loop, the tools, the system prompt, and context management. Where Claude Code is the batteries-included harness, wrencode is the one you can understand and own: the whole loop fits in one readable file, runs against local or hosted models, and is yours to hack.

Named after Harold Wren, the alias of a genius who built a superintelligent AI and operated quietly in the background.

wrencode on GitHub →

  • Headless mode. -p / --print runs one prompt without the interactive UI, for scripts, CI, and evals.
  • Typed answers. --json-schema makes the answer a JSON value that matches your schema.
  • Verified runs. --verify CMD checks the agent’s claim of being done and sends failures back to it.
  • Automatic compaction. Long sessions are summarized before they overflow the context window.
  • OpenAI-compatible backend. Talk to vLLM, llama.cpp, Hugging Face, or any server that implements OpenAI chat completions.
  • NanoGPT backend, with native OpenAI-format tool calls.
  • AGENTS.md. Project instructions are loaded into the system prompt.
  • Sturdier loop. Retries on dropped connections, timeouts, and HTTP 429/5xx, recovery from cut-off responses and garbled tool calls, and a more forgiving edit tool.

Full history in the changelog.

The guided installer detects your OS and architecture, downloads the matching binary from the latest GitHub Release, and installs it to ~/.local/bin (no sudo).

Terminal window
curl -LsSf https://almostly.ai/wrencode/install.sh | sh

Pin a version or change the install location:

Terminal window
curl -fsSL https://almostly.ai/wrencode/install.sh \
| WRENCODE_INSTALL_DIR=/usr/local/bin WRENCODE_VERSION=0.2.0 sh

Grab the binary for your platform from the latest GitHub Release:

  • macOS Apple Silicon: wrencode-macos-arm64
  • macOS Intel: wrencode-macos-x64
  • Linux x64: wrencode-linux-x64

Make it executable and move it onto your PATH:

Terminal window
chmod +x wrencode-macos-arm64
sudo mv wrencode-macos-arm64 /usr/local/bin/wrencode

Single file, standard library only (except the backend you choose).

Terminal window
git clone https://github.com/almostly/wrencode
cd wrencode
python3 wrencode.py

Backend-specific dependencies, if you need them:

Terminal window
pip install mlx-lm # MLX on Apple Silicon
pip install transformers torch # HuggingFace Transformers

First launch prompts for a backend and saves it to ~/.wrencode/config.json. Re-pick at any time:

Terminal window
wrencode --configure

Override the saved choice for a single session (useful in CI):

Terminal window
BACKEND=anthropic wrencode
BACKEND=openai MODEL=gpt-4o wrencode
BACKEND=openrouter MODEL=anthropic/claude-3-haiku wrencode
BACKEND=nanogpt MODEL=z-ai/glm-5.3-flash wrencode
BACKEND=bedrock AWS_REGION=us-east-1 wrencode
BACKEND=ollama MODEL=llama3.2 wrencode
BACKEND=openai-compatible wrencode
BACKEND=transformers MODEL=deburky/gpt-oss-claude-code python3 wrencode.py
BACKEND=local LOCAL_PORT=8082 wrencode

Skip the y/N confirmation on writes and shell commands:

Terminal window
wrencode --yes

--yes runs writes and shell commands without asking, so use it only in a workspace you are happy for the agent to change.

BackendDescriptionAvailability
anthropicClaude via the Anthropic APIbinary + source
openaiGPT models via the OpenAI APIbinary + source
openrouterAny model via OpenRouterbinary + source
nanogptAny model via NanoGPTbinary + source
bedrockAny model on AWS Bedrock via the Converse API, using your AWS credentialsbinary + source
ollamaLocal models via a running ollama servebinary + source
openai-compatiblevLLM, llama.cpp, Hugging Face, any OpenAI-compatible serverbinary + source
localLocal proxy via an Anthropic-compatible APIbinary + source
transformersHuggingFace Transformers (CPU / MPS / GPU)source install only
mlxApple Silicon via MLXsource install, macOS

The standalone binary can’t bundle the heavy ML stack, so mlx and transformers are only offered when running from source.

Default local models: deburky/gpt-oss-claude-code (transformers) and deburky/gpt-oss-claude-mlx (MLX). Override either with MODEL=....

openai-compatible talks to any server that implements OpenAI chat completions, using native tool calls. Point it at the server with OPENAI_COMPATIBLE_BASE_URL (default http://localhost:8000/v1). If the server serves exactly one model, wrencode uses it. Otherwise set MODEL.

Terminal window
# vLLM (tool calling needs these flags; pick the parser for your model)
vllm serve Qwen/Qwen2.5-Coder-7B-Instruct --enable-auto-tool-choice --tool-call-parser hermes
BACKEND=openai-compatible wrencode
# llama.cpp (--jinja enables tool calling)
llama-server -m qwen2.5-coder-7b-instruct-q4_k_m.gguf --jinja --port 8080
BACKEND=openai-compatible OPENAI_COMPATIBLE_BASE_URL=http://localhost:8080/v1 wrencode
# Hugging Face Inference Providers
BACKEND=openai-compatible OPENAI_COMPATIBLE_BASE_URL=https://router.huggingface.co/v1 \
OPENAI_COMPATIBLE_API_KEY=$HF_TOKEN MODEL=Qwen/Qwen2.5-Coder-32B-Instruct wrencode

No GPU to hand? The repo has a Modal script that serves vLLM to test against.

-p / --print runs a single prompt without the interactive UI:

Terminal window
wrencode -p "Why is test_parse failing?"
git diff | wrencode -p "Review this diff" # prompt from stdin
wrencode --yes -p "Fix the lint errors" --max-turns 20
wrencode -p "List the TODOs" --output-format json | jq -r .result
wrencode --yes -p "Make the tests pass" --verify "python3 -m unittest -q"
  • stdout carries only the final answer, or one JSON object with --output-format json (result, is_error, stop_reason, num_turns, backend, model). Progress and tool output go to stderr.
  • Each run starts from a fresh history and doesn’t touch the saved one.
  • Without --yes, writes and shell commands are declined (the model is told why) instead of waiting for approval. Read-only tools always work.
  • The exit code is 0 when the agent finishes, 1 if it errors, hits --max-turns, or stops on repeated tool errors, and 2 for bad arguments.

--verify CMD checks the agent’s claim of being done. wrencode runs CMD in the workspace when the agent finishes. If it fails, the output goes back to the agent and it continues, up to 3 attempts in all. The result says verified: true/false, and a final failure exits 1 with stop_reason: "verify_failed". --max-turns applies to each attempt.

--json-schema makes the answer a JSON value that matches a schema, given as a file or inline:

Terminal window
wrencode -p "Review this repo for bugs" --json-schema bugs.schema.json
wrencode -p "Is the build green?" --json-schema '{"type": "object", "properties": {"green": {"type": "boolean"}}, "required": ["green"]}'

The agent gets a respond tool whose arguments are your schema, and the run ends when it calls respond with a valid answer. If the answer doesn’t match, the validation errors go back to the model so it can fix them. If it never calls respond, the run fails with stop_reason: "no_structured_output". stdout is the JSON value, or with --output-format json the usual object with a structured_output field. Validation is built in and covers the common keywords: type, enum, const, properties, required, additionalProperties, items, length and numeric bounds, pattern, and anyOf / oneOf / allOf.

The agent has seven tools available in the loop:

  • read: read a file with line numbers, or list a directory
  • write: write content to a file
  • edit: replace a unique string in a file. If the text only matches with its indentation shifted by a consistent amount, the edit is applied with the replacement shifted to match. Otherwise the error shows the closest lines in the file
  • glob: find files by pattern, sorted by modification time
  • grep: search files for a regex using rg when available, falling back to grep
  • bash: run a shell command with timeout and streaming output
  • task: delegate a self-contained subtask to a fresh subagent (its own context, same tools) that returns only its final result

All file operations are restricted to the workspace root by default. Set WRENCODE_UNRESTRICTED_PATHS=1 to allow paths outside the workspace.

The task tool runs a nested agent loop on a fresh message history, so the parent’s context only grows by the returned summary. Useful for context-heavy subtasks. Recursion is capped by WRENCODE_MAX_SUBAGENT_DEPTH (default 2). For autonomous runs, enable --yes or WRENCODE_AUTO_APPROVE=1 so sub-tool calls don’t block on confirmation.

wrencode reads AGENTS.md files and adds them to the system prompt, so conventions you’ve written for other agents apply here too. It looks in ~/.wrencode/, then in every directory from the git root down to the workspace (outside a git repo, only the workspace). A directory without an AGENTS.md falls back to CLAUDE.md. Files closer to the workspace come later and take precedence. The total is capped at 32,000 characters, and the files loaded are listed at startup.

Long sessions are compacted automatically. Before each model call wrencode estimates the prompt size (about 4 characters per token), and once it passes WRENCODE_COMPACT_AT (default 75%) of WRENCODE_CONTEXT_TOKENS (default 128,000) it has the model summarize the older messages: the request, files touched, commands and results, decisions, and what’s left to do. The most recent messages, about a quarter of the window, are kept verbatim along with your latest request, so it works mid-task, between tool calls. If a request still fails with a context-length error, wrencode compacts and retries once.

Set WRENCODE_CONTEXT_TOKENS to your model’s window, especially for local models with small ones. /compact summarizes on demand.

wrencode synthesize fuses chat transcripts into one synthesis, like a semantic git merge of conversations:

Terminal window
wrencode synthesize # pick from this project's chat history
wrencode synthesize notes/ --out synthesis.md
wrencode synthesize diff notes/ # divergences only
wrencode synthesize log # decision timeline

--out FILE writes the result to a file, and --all skips the picker.

CommandDescription
/helpShow available commands
/backend or /configureSwitch backend
/modelSwitch model, or set one directly with /model <id>
/cClear conversation history
/compactSummarize history to reduce context
/q or exitQuit
VariableDefaultDescription
BACKENDchooser / saved configOverride the saved inference backend
MODELbackend-dependentModel path or ID
WRENCODE_CONFIG_DIR~/.wrencodeDir for config.json (saved backend / key)
WRENCODE_WORKSPACEcwdRoot directory for file operations
WRENCODE_HISTORY_FILE~/.wrencode/history.jsonConversation history file path
WRENCODE_UNRESTRICTED_PATHS0Allow paths outside the workspace
WRENCODE_AUTO_APPROVE0Skip y/N confirmation for writes / shell (also --yes)
WRENCODE_MAX_SUBAGENT_DEPTH2Max nested subagent recursion depth (task tool)
MAX_TOKENS8192Max tokens per response
WRENCODE_HTTP_TIMEOUT600Seconds to wait for a model response
WRENCODE_HTTP_RETRIES2Retries on HTTP 429/5xx and network errors, with backoff
WRENCODE_CONTEXT_TOKENS128000Model context window, for auto-compaction
WRENCODE_COMPACT_AT0.75Compact at this fraction of the window (0 disables)
MAX_READ_BYTES4MBMax file size to read
MAX_READ_LINES800Max lines returned per read
GREP_MAX_MATCHES80Max grep results
BASH_TIMEOUT120Shell command timeout in seconds
MAX_TOOL_OUTPUT_CHARS48000Max tool output before truncation
GLOB_SKIP_DIRS.git,node_modules,...Directories to skip in glob
ANTHROPIC_API_KEYAnthropic API key
OPENAI_API_KEYOpenAI API key
OPENROUTER_API_KEYOpenRouter API key
NANOGPT_API_KEYNanoGPT API key
AWS_REGION, AWS_PROFILERegion and credentials profile for bedrock (standard AWS credential variables also work)
OPENAI_COMPATIBLE_BASE_URLhttp://localhost:8000/v1OpenAI-compatible server base URL
OPENAI_COMPATIBLE_API_KEYKey for that server, if it needs one
LOCAL_API_KEYlocalLocal proxy API key
LOCAL_PORT8082Local proxy port
OLLAMA_HOSThttp://localhost:11434Ollama server base URL

Conversation history is persisted to ~/.wrencode/history.json by default and restored on the next launch. Override the path with WRENCODE_HISTORY_FILE. Clear it with /c in-session, or delete the file.

Terminal window
wrencode --uninstall

Removes the saved config and shows how to delete the binary.

MIT. Copyright 2026 Almostly.