GPT-AGI/Clawd-Code
Claude-Code-Python: Reconstructing Claude Code in Python
📚 What is Clawd‑Code?
Clawd‑Code is a Python re‑implementation of Anthropic’s Claude Code agent. The original Claude Code was written in TypeScript; this project ports the same architecture to idiomatic Python (3.10+), adds type hints, tests, and a ready‑to‑run command‑line interface.
It isn’t just a code dump – it ships a fully functional CLI REPL that can:
- stream LLM responses token‑by‑token,
- invoke tools (file read/write, web fetch, bash, etc.) in a loop, and
- be extended with markdown‑driven “skills” (slash commands) that limit which tools they may use.
The goal is to give developers a production‑ready, hackable Claude‑style coding assistant that works locally with any of the supported LLM providers.
✨ Core Features (as described in the README)
| Feature | What it does |
|---|---|
| Streaming Agent Experience | Real‑time token streaming, /stream toggle, /render-last to re‑render the previous answer as Markdown. |
| Programmable Skill Runtime | Skills are defined in SKILL.md files (markdown front‑matter). They can declare arguments, allowed tools, and a description. |
| Multi‑Provider Support | Works with Anthropic Claude, OpenAI GPT, and Zhipu GLM out of the box; providers are easy to add. |
| Interactive REPL | Rich terminal UI with history, tab‑completion, multiline mode, session save/load, and built‑in commands (/help, /save, /load, …). |
| Complete CLI | clawd starts the REPL, clawd login configures API keys, clawd config shows settings, clawd --version prints the version. |
| Tool System | 30+ built‑in tools (file ops, Bash, web fetch/search, task management, agent‑level tools, configuration, etc.) with validation and sandboxing. |
| Session Persistence | Sessions can be saved locally and re‑loaded later. |
| Tests & Docs | Core test suite covering skills, providers, REPL, tools, and context; >10 markdown docs and a changelog. |
🚀 Getting Started
# Clone the repo
git clone https://github.com/GPT-AGI/Clawd-Code.git
cd Clawd-Code
# Create a virtual environment (uv is recommended)
uv venv --python 3.11
source .venv/bin/activate
# Install dependencies
uv pip install -r requirements.txt
Configure your LLM provider
python -m src.cli login # interactive wizard
The wizard asks you to pick a provider (Anthropic, OpenAI, or GLM), enter the API key, optional base URL, and a default model. The configuration is saved to ~/.clawd/config.json.
Run the agent
python -m src.cli # start the REPL
python -m src.cli --help # show CLI options
You can now type natural language, use /stream on for live output, or invoke a skill, e.g.:
>>> /explain-code qsort.py
🛠️ Extending with Skills
- Create a directory under the project (or
~/.clawd) like:.clawd/skills/explain-code/SKILL.md - Write a markdown front‑matter block:
--- description: Explain code with analogies and diagrams allowed-tools: - Read - Grep - Glob arguments: [path] --- Explain the code in $path. Start with an analogy, then draw a diagram. - Call it from the REPL with
/explain-code <file>.
The skill system enforces the listed allowed-tools, substitutes $path with the argument, and runs inside the same sandboxed tool loop.
📦 Project Layout
Clawd-Code/
├─ src/
│ ├─ cli.py # entry point
│ ├─ providers/ # Anthropic, OpenAI, GLM adapters
│ ├─ repl/ # interactive REPL implementation
│ ├─ skills/ # loader for SKILL.md files
│ └─ tool_system/ # registry, validation, loop logic
├─ tests/ # unit & integration tests
├─ .clawd/skills/ # example project‑level skills
└─ FEATURE_LIST.md # detailed feature status
🤝 Contributing
The repo follows a typical Python open‑source workflow:
pip install -e .[dev] # install in editable mode with dev extras
pytest -v tests/ # run the test suite
Guidelines are in CONTRIBUTING.md; pull requests are welcomed.
⚡ Performance & Security
- Startup < 1 s, Memory < 50 MiB.
- API keys are stored base‑64‑encoded in the user config and
.envfiles are ignored. - No secret data is committed to the repository.
📄 License
MIT – see LICENSE.
Clawd‑Code gives you a Claude‑style coding assistant that runs locally, is fully scriptable, and can be extended with your own markdown‑based skills—all in pure Python.
Related
- Project
- Project
- Project
- Project