A minimal Claude Code clone built in Go — an LLM-powered coding assistant that reads files, writes files, and executes shell commands through an agentic tool-calling loop. Built as a CodeCrafters "Build Your Own Claude Code" challenge solution.
go install github.com/ImperishableMe/claude-code/cmd/claude-code@latestMake sure $GOPATH/bin is in your PATH:
export PATH="$PATH:$(go env GOPATH)/bin"# Set your API key
export OPENROUTER_API_KEY="your-api-key"
# Run with a prompt
claude-code -p "your prompt here"
claude-code --prompt "your prompt here"
# Show help
claude-code --helpThe agent follows a standard LLM tool-calling loop:
Prompt → LLM → Tool Calls → Execute Tools → Feed Results Back → LLM → ... → Final Response
- User prompt is sent to the LLM along with tool definitions
- The LLM responds with either a final message or tool calls
- Tool calls are executed locally and results are appended to the conversation
- The loop repeats (up to 10 iterations) until the LLM produces a final response
All tools implement a common Tool interface with Name(), Definition(), and Execute() methods, registered in a simple map-based dispatch table.
| Tool | Description |
|---|---|
| Read | Reads file contents from disk (os.ReadFile) |
| Write | Writes content to a file with 0644 permissions |
| Bash | Executes shell commands via sh -c and returns combined stdout/stderr |
- Go 1.25+
- An OpenRouter API key
| Environment Variable | Required | Default | Description |
|---|---|---|---|
OPENROUTER_API_KEY |
Yes | — | OpenRouter API key for authentication |
OPENROUTER_BASE_URL |
No | https://openrouter.ai/api/v1 |
API base URL |
OPENROUTER_BASE_MODEL |
No | anthropic/claude-haiku-4.5 |
Model to use for completions |
# Build locally
go build -o claude-code ./cmd/claude-code/
# Run locally
./claude-code -p "your prompt here"
# Or use the wrapper script
./your_program.sh -p "your prompt here"cmd/claude-code/
├── main.go # Entry point, agent loop, OpenRouter client setup
└── tools.go # Tool interface and implementations (Read, Write, Bash)