Skip to content

apoorvdarshan/claw-c

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

claw-c

      _                          
  ___| | __ ___      __       ___ 
 / __| |/ _` \ \ /\ / /___  / __|
| (__| | (_| |\ V  V /|___|| (__ 
 \___|_|\__,_| \_/\_/        \___|

AI coding agent in your terminal. Pure C. No bloat.


me building an HTTP client from scratch instead of linking libcurl

install

git clone https://github.com/apoorvdarshan/claw-c.git
cd claw-c && ./install.sh

that's it. builds, installs to ~/.local/bin/claw-c, adds to PATH. on macOS it auto-installs mbedTLS via brew. on linux you need mbedTLS 4.x first.

then from anywhere:

claw-c

first run asks you to pick a provider and enter your key. config saved to ~/.claw-c/config.json. next time just type claw-c.

$ claw-c

Welcome to claw-c! Let's get you set up.

  1  anthropic   (claude-sonnet-4-6, claude-opus-4-6)
  2  openai      (gpt-4o, o3, o4-mini)
  3  gemini      (gemini-2.5-flash, gemini-2.5-pro)
  4  groq        (llama-3.3-70b-versatile)
  5  xai         (grok-3)
  6  openrouter  (any model)
  7  ollama      (local, no key needed)
  ...

Pick a provider [1-10]: 3
Model [gemini-2.5-flash]:
API key: AIza...

Config saved to ~/.claw-c/config.json

to change provider/model/key: claw-c --setup or /setup inside the REPL.

what it does

you type a prompt. claw-c talks to the LLM. the LLM can run commands, read/write/edit files, search code — claw-c executes it all, feeds results back, and loops until the task is done. just like claude code but ~3500 lines of C.

$ claw-c

  gemini | gemini-2.5-flash | main

> write hello.c that prints "built by claw-c", compile and run it

── write_file ──
  /tmp/hello.c
Wrote 81 bytes to /tmp/hello.c

── bash ──
$ cc /tmp/hello.c -o /tmp/hello && /tmp/hello
built by claw-c

Done.

> find all functions with "parse" in their name

── grep ──
  /parse/
c/src/json.c:228:json_value_t *json_parse(const char *src, size_t len) {
c/src/sse.c:27:static int parse_frame(const char *frame, ...) {
...

> /quit

tools

6 built-in tools, same as claude code:

tool what it does
bash shell commands via /bin/sh -c (120s timeout, 512KB cap)
read_file read file with line numbers
write_file create/overwrite file (auto-creates parent dirs)
edit_file find-and-replace exact string match
glob recursive file pattern matching (*.c, src/**/*.h)
grep recursive regex search with line numbers

providers

auto-detected from model name. 10 providers, 3 API formats built from scratch.

provider models env var
Anthropic claude-* ANTHROPIC_API_KEY
OpenAI gpt-* o1-* o3-* o4-* OPENAI_API_KEY
Gemini gemini-* GEMINI_API_KEY
xAI grok-* XAI_API_KEY
Groq llama* mixtral* GROQ_API_KEY
Together deepseek* qwen* TOGETHER_API_KEY
OpenRouter any (-p openrouter) OPENROUTER_API_KEY
Ollama any (-p ollama) none
Minimax -p minimax MINIMAX_API_KEY
Kimi moonshot* MOONSHOT_API_KEY

usage

claw-c                                        # REPL (uses saved config)
claw-c "find all TODO comments"               # one-shot
claw-c -m gpt-4o -k sk-... "explain this"    # override model/key
claw-c -p ollama -m llama3.2 "hello"          # local
claw-c -p openai -b my-server:8080 "hi"       # custom endpoint
claw-c --setup                                # change provider/model/key

flags: -m MODEL -k KEY -p PROVIDER -b HOST:PORT -h -v --setup

repl: /help /status /clear /setup /quit

keys: Ctrl-C cancel Ctrl-D exit Up/Down history

how it works

prompt → JSON request (per provider format)
       → raw TCP socket → TLS handshake → HTTP/1.1 POST
       → SSE stream → text printed live
       → tool calls? → execute (fork/exec, file I/O, regex)
       → feed results back → loop until done (max 25 turns)

everything from scratch: JSON parser, HTTP client, SSE streaming, TLS (via mbedTLS). no curl, no libevent, no external JSON lib.

reads CLAUDE.md from your project (walks up to git root). shows git branch + status in context.


tokens streaming through the hand-rolled SSE parser

source

c/src/
  claw.h       all types + declarations (single header)
  strbuf.c     dynamic string buffer
  json.c       recursive descent JSON parser/serializer
  tls.c        raw POSIX TCP + mbedTLS 4.x TLS
  http.c       HTTP/1.1 with chunked streaming
  sse.c        SSE event parser
  api.c        multi-provider API client (3 format families)
  tools.c      6 tools: bash, read, write, edit, glob, grep
  agent.c      agent loop with tool execution
  terminal.c   raw mode REPL with history
  main.c       CLI, config, onboarding, CLAUDE.md, git context

build from source

brew install mbedtls          # macOS
cd c && make                  # dynamic
make static                   # portable static binary
make install                  # → ~/.local/bin/claw-c

disclaimer

this repo was originally cloned from ultraworkers/claw-code (a Rust/Python reimplementation of Claude Code). i stripped all of that out and rewrote the whole thing from scratch in pure C — different language, different architecture, different code. the Rust implementation was used as a behavioral reference to understand how the agent loop, tool system, and API streaming should work.

not Claude Code. not affiliated with Anthropic, OpenAI, Google, or any provider. hobby project. use at your own risk — this thing runs shell commands.

ownership / affiliation

  • this repository does not claim ownership of the original Claude Code source material.
  • this repository is not affiliated with, endorsed by, or maintained by Anthropic.

author

Apoorv Darshan

X Email GitHub

About

Claude Code reimplemented in pure C — the lowest level it's ever been done

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages