A Python reimplementation of the Claude Code agent architecture β local models, full control.
This repository reimplements the Claude Code npm agent architecture entirely in Python, designed to run with local open-source models via an OpenAI-compatible API server.
Built on the public porting workspace from instructkr/claw-code, the active development lives at HarnessLab/claw-code-agent.
Goal: Not to ship the original npm source, but to reimplement the full agent flow in Python β prompt assembly, context building, slash commands, tool calling, session persistence, and local model execution.
| Feature | Description |
|---|---|
| π€ Agent Loop | Full agentic coding loop with tool calling and iterative reasoning |
| π§° Core Tools | File read / write / edit, glob search, grep search, shell execution |
| π¬ Slash Commands | Local commands: /help, /context, /tools, /memory, /status, /model, and more |
| π§ Context Engine | Automatic context building with CLAUDE.md discovery and usage reporting |
| π Session Persistence | Save and resume agent sessions across runs |
| π Permission System | Granular control: --allow-write, --allow-shell, --unsafe |
| ποΈ OpenAI-Compatible Runtime | Python client targets an OpenAI-compatible API, with vLLM as the documented setup |
| π Qwen3-Coder | First-class support for Qwen3-Coder-30B-A3B-Instruct via vLLM |
- Python CLI agent loop
- OpenAI-compatible local model backend
- Qwen3-Coder support through vLLM with
qwen3_xmltool parser - Core tools:
list_dir,read_file,write_file,edit_file,glob_search,grep_search,bash - Context building and
/context-style usage reporting - Slash commands:
/help,/context,/context-raw,/prompt,/permissions,/model,/tools,/memory,/status,/clear - Session persistence and
agent-resumeflow - Permission system (read-only, write, shell, unsafe tiers)
- Unit tests for the Python runtime
-
pyproject.tomlpackaging withsetuptools
- Full MCP support
- Full plugin system
- Full slash-command parity
- Full interactive REPL / TUI behavior
- Exact tokenizer / context accounting
- Hooks parity
- Remote modes parity
- Voice / VIM parity
- Some deeper runtime details from the npm source
- Cost tracking and budget limits
claw-code/
βββ README.md
βββ pyproject.toml
βββ .gitignore
βββ images/
β βββ logo.png
βββ src/ # Python implementation
β βββ main.py # CLI entry point & argument parsing
β βββ agent_runtime.py # Core agent loop (LocalCodingAgent)
β βββ agent_tools.py # Tool definitions & execution engine
β βββ agent_prompting.py # System prompt assembly
β βββ agent_context.py # Context building & CLAUDE.md discovery
β βββ agent_context_usage.py # Context usage estimation & reporting
β βββ agent_session.py # Session state management
β βββ agent_slash_commands.py # Local slash command processing
β βββ agent_types.py # Shared dataclasses & type definitions
β βββ openai_compat.py # OpenAI-compatible API client
β βββ session_store.py # Session serialization & persistence
β βββ permissions.py # Tool permission filtering
β βββ tools.py # Mirrored tool inventory
β βββ commands.py # Mirrored command inventory
β βββ ... # 75+ modules across 30+ packages
β βββ plugins/ # Plugin subsystem (WIP)
β βββ hooks/ # Hook system (WIP)
β βββ remote/ # Remote runtime modes (WIP)
β βββ voice/ # Voice mode (WIP)
β βββ vim/ # VIM mode (WIP)
βββ tests/ # Unit tests
βββ test_agent_runtime.py
βββ test_agent_context.py
βββ test_agent_context_usage.py
βββ test_agent_prompting.py
βββ test_agent_slash_commands.py
βββ test_porting_workspace.py
| Requirement | Details |
|---|---|
| π Python | 3.10 or higher |
| π₯οΈ Model Server | vLLM, Ollama, or LiteLLM Proxy, with tool calling support |
| π§ Model | Qwen/Qwen3-Coder-30B-A3B-Instruct (recommended) |
vLLM must be started with automatic tool choice enabled. Use the qwen3_xml parser for Qwen3-Coder tool calling:
python -m vllm.entrypoints.openai.api_server \
--model Qwen/Qwen3-Coder-30B-A3B-Instruct \
--host 127.0.0.1 \
--port 8000 \
--enable-auto-tool-choice \
--tool-call-parser qwen3_xmlVerify the server is running:
curl http://127.0.0.1:8000/v1/modelsπ References: vLLM Tool Calling Docs Β· OpenAI-Compatible Server
claw-code-agent can also work with Ollama because the runtime targets an OpenAI-compatible API. Use a model that supports tool calling well.
Example:
ollama serve
ollama pull qwen3Then configure:
export OPENAI_BASE_URL=http://127.0.0.1:11434/v1
export OPENAI_API_KEY=ollama
export OPENAI_MODEL=qwen3Notes:
- prefer tool-capable models such as
qwen3 - plain chat-only models are not enough for full agent behavior
- Ollama does not use the
vLLMparser flags shown above
π References: Ollama OpenAI Compatibility Β· Ollama Tool Calling
claw-code-agent can also work through LiteLLM Proxy because the runtime targets an OpenAI-compatible chat completions API. The routed model still needs to support tool calling for full agent behavior.
Quick start example:
pip install 'litellm[proxy]'
litellm --model ollama/qwen3LiteLLM Proxy runs on port 4000 by default. Then configure:
export OPENAI_BASE_URL=http://127.0.0.1:4000
export OPENAI_API_KEY=anything
export OPENAI_MODEL=ollama/qwen3Notes:
- LiteLLM Proxy gives you an OpenAI-style gateway in front of many providers
- tool use still depends on the underlying routed model and provider behavior
- if you configure a LiteLLM master key, use that instead of
anything
π References: LiteLLM Docs Β· LiteLLM Proxy Quick Start
export OPENAI_BASE_URL=http://127.0.0.1:8000/v1
export OPENAI_API_KEY=local-token
export OPENAI_MODEL=Qwen/Qwen3-Coder-30B-A3B-InstructIf you want to try another model, keep the same vLLM server setup and change the --model value when you launch vLLM.
Example:
python -m vllm.entrypoints.openai.api_server \
--model your-model-name \
--host 127.0.0.1 \
--port 8000 \
--enable-auto-tool-choice \
--tool-call-parser your_parserThen update:
export OPENAI_MODEL=your-model-nameNotes:
- the documented path in this repository is
vLLM - the model must support tool calling well enough for agent use
- some model families require a different
--tool-call-parser - slash commands such as
/help,/context, and/toolsare local and do not require the model server
# Read-only question
python3 -m src.main agent \
"Read src/agent_runtime.py and summarize how the loop works." \
--cwd .
# Write-enabled task
python3 -m src.main agent \
"Create TEST_QWEN_AGENT.md with one line: test ok" \
--cwd . --allow-write
# Shell-enabled task
python3 -m src.main agent \
"Run pwd and ls src, then summarize the result." \
--cwd . --allow-shell| Command | Description |
|---|---|
agent <prompt> |
Run the agent with a prompt |
agent-prompt |
Show the assembled system prompt |
agent-context |
Show estimated context usage |
agent-context-raw |
Show the raw context snapshot |
agent-resume <id> <prompt> |
Resume a saved session |
| Flag | Description |
|---|---|
--cwd <path> |
Set the workspace directory |
--model <name> |
Override the model name |
--base-url <url> |
Override the API base URL |
--allow-write |
Allow the agent to modify files |
--allow-shell |
Allow the agent to execute shell commands |
--unsafe |
Allow destructive shell operations |
--show-transcript |
Print the full message transcript |
--system-prompt <text> |
Set a custom system prompt |
--append-system-prompt <text> |
Append to the system prompt |
--add-dir <path> |
Add extra directories to context |
These are handled locally before the model loop:
| Command | Aliases | Description |
|---|---|---|
/help |
/commands |
Show built-in slash commands |
/context |
/usage |
Show estimated session context usage |
/context-raw |
/env |
Show raw environment & context snapshot |
/prompt |
/system-prompt |
Render the effective system prompt |
/permissions |
β | Show active tool permission mode |
/model |
β | Show or update the active model |
/tools |
β | List registered tools with permission status |
/memory |
β | Show loaded CLAUDE.md memory bundle |
/status |
/session |
Show runtime/session status summary |
/clear |
β | Clear ephemeral runtime state |
python3 -m src.main agent "/help"
python3 -m src.main agent "/context" --cwd .
python3 -m src.main agent "/tools" --cwd .
python3 -m src.main agent "/status" --cwd .python3 -m src.main summary # Workspace summary
python3 -m src.main manifest # Workspace manifest
python3 -m src.main commands --limit 10 # Command inventory
python3 -m src.main tools --limit 10 # Tool inventoryThe agent has access to 7 core tools:
| Tool | Description | Permission |
|---|---|---|
list_dir |
List files and directories | π’ Always |
read_file |
Read file contents (with line ranges) | π’ Always |
write_file |
Write or create files | π‘ --allow-write |
edit_file |
Edit files via exact string matching | π‘ --allow-write |
glob_search |
Find files by glob pattern | π’ Always |
grep_search |
Search file contents by regex | π’ Always |
bash |
Execute shell commands | π΄ --allow-shell |
Each agent run automatically saves a resumable session:
session_id=4f2c8c6f9c0e4d7c9c7b1b2a3d4e5f67
session_path=.port_sessions/agent/4f2c8c6f...
Resume a previous session:
python3 -m src.main agent-resume \
4f2c8c6f9c0e4d7c9c7b1b2a3d4e5f67 \
"Continue the previous task and finish the missing parts."Inspect saved sessions:
ls -lt .port_sessions/agentNote: Run
agent-resumefrom the sameclaw-code/directory where the session was created. A resumed session continues from the saved transcript, not from scratch.
Run the full test suite:
python3 -m unittest discover -s tests -vSmoke tests:
python3 -m src.main agent "/help"
python3 -m src.main agent-context --cwd .
python3 -m src.main agent \
"Read src/agent_session.py and summarize the message flow." \
--cwd .Claw Code Agent uses a tiered permission system to keep the agent safe by default:
| Tier | Capability | Flag Required |
|---|---|---|
| Read-only | List, read, glob, grep | None (default) |
| Write | + file creation and editing | --allow-write |
| Shell | + shell command execution | --allow-shell |
| Unsafe | + destructive shell operations | --unsafe |
- This repository is a Python reimplementation inspired by the Claude Code npm architecture.
- It does not ship the original npm source.
- It is not affiliated with or endorsed by Anthropic.
Built with π Python Β· Powered by π HarnessLab Team.

