A Python reimplementation of the Claude Code agent architecture โ local models, full control.
--- ## ๐ About This repository reimplements the [Claude Code](https://docs.anthropic.com/en/docs/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](https://github.com/instructkr/claw-code), the active development lives at [HarnessLab/claw-code-agent](https://github.com/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. --- ## โจ Key Features | 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 | --- ## ๐ Roadmap ### Done - [x] Python CLI agent loop - [x] OpenAI-compatible local model backend - [x] Qwen3-Coder support through vLLM with `qwen3_xml` tool parser - [x] Core tools: `list_dir`, `read_file`, `write_file`, `edit_file`, `glob_search`, `grep_search`, `bash` - [x] Context building and `/context`-style usage reporting - [x] Slash commands: `/help`, `/context`, `/context-raw`, `/prompt`, `/permissions`, `/model`, `/tools`, `/memory`, `/status`, `/clear` - [x] Session persistence and `agent-resume` flow - [x] Permission system (read-only, write, shell, unsafe tiers) - [x] Unit tests for the Python runtime - [x] `pyproject.toml` packaging with `setuptools` ### In Progress - [ ] Full plugin and MCP server parity - [ ] Complete slash-command parity with npm runtime - [ ] Full interactive REPL / session persistence parity - [ ] Tokenizer-accurate context accounting - [ ] Remote runtime modes (SSH, teleport, deep-link) - [ ] Voice and VIM modes - [ ] Hooks system - [ ] Cost tracking and budget limits --- ## ๐๏ธ Architecture ```text 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 ``` --- ## ๐ฆ Requirements | Requirement | Details | |-------------|---------| | ๐ Python | `3.10` or higher | | ๐ฅ๏ธ Model Server | `vLLM` or `Ollama`, with tool calling support | | ๐ง Model | [`Qwen/Qwen3-Coder-30B-A3B-Instruct`](https://huggingface.co/Qwen/Qwen3-Coder-30B-A3B-Instruct) (recommended) | --- ## ๐ Quick Start ### 1. Start vLLM with Qwen3-Coder vLLM must be started with automatic tool choice enabled. Use the `qwen3_xml` parser for Qwen3-Coder tool calling: ```bash 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_xml ``` Verify the server is running: ```bash curl http://127.0.0.1:8000/v1/models ``` > ๐ **References:** [vLLM Tool Calling Docs](https://docs.vllm.ai/en/v0.13.0/features/tool_calling/) ยท [OpenAI-Compatible Server](https://docs.vllm.ai/en/v0.13.0/serving/openai_compatible_server.html) ### Optional: Use Ollama Instead of vLLM `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: ```bash ollama serve ollama pull qwen3 ``` Then configure: ```bash export OPENAI_BASE_URL=http://127.0.0.1:11434/v1 export OPENAI_API_KEY=ollama export OPENAI_MODEL=qwen3 ``` Notes: - prefer tool-capable models such as `qwen3` - plain chat-only models are not enough for full agent behavior - Ollama does not use the `vLLM` parser flags shown above > ๐ **References:** [Ollama OpenAI Compatibility](https://docs.ollama.com/api/openai-compatibility) ยท [Ollama Tool Calling](https://docs.ollama.com/capabilities/tool-calling) ### 2. Configure Environment ```bash 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-Instruct ``` ### Use Another Model With vLLM If you want to try another model, keep the same `vLLM` server setup and change the `--model` value when you launch `vLLM`. Example: ```bash 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_parser ``` Then update: ```bash export OPENAI_MODEL=your-model-name ``` Notes: - 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 `/tools` are local and do not require the model server ### 3. Run the Agent ```bash # 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 ``` --- ## ๐ ๏ธ Usage ### Agent Commands | Command | Description | |---------|-------------| | `agentBuilt with ๐ Python ยท Powered by ๐ HarnessLab Team.