CodeCode is a minimal, scratch-built AI coding agent client written in TypeScript, inspired by Claude Code and Open Code.
Why build from scratch?
To deeply understand how coding agents work under the hood โ tool-calling loops, multi-provider LLM integration, and file-system tooling โ without any framework abstraction like LangChain.
- ๐ง Multi-provider LLM support โ OpenAI, DeepSeek, MiniMax, Kimi, GLM (OpenAI-compatible), and Anthropic / Claude
- ๐ ๏ธ Native tool calling โ tools are defined as JSON schemas and dispatched by the LLM natively (no string parsing)
- ๐ Workspace-aware file operations โ read, write, edit files with path-traversal protection
- ๐ Code search & discovery โ
grep(regex over file contents),glob(file-pattern match),ls(directory listing) โ all sandboxed, no shell-out - ๐ Bash execution โ run shell commands inside the current workspace
- ๐งฎ Calculator โ evaluate mathematical expressions
- ๐ Agent loop โ the LLM autonomously decides which tool to call, receives results, and iterates until the task is done
- ๐๏ธ Zero-abstraction design โ two runtime dependencies (
dotenv+js-yaml) + TypeScript toolchain
# Install dependencies
npm install
# Copy environment config and add your API keys
cp .env.example .env
# Edit .env with your provider API key and preferred model
# Start the REPL
npm start# Default (Anthropic Claude)
npm start
# OpenAI
npm run openai
# DeepSeek
npm run deepseek
# MiniMax
npm run minimax
# Kimi
npm run kimi
# GLM
npm run glm| Variable | Description |
|---|---|
LLM_PROVIDER |
Provider name: openai, anthropic, deepseek, minimax, kimi, glm, claude (alias for anthropic) |
OPENAI_API_KEY |
OpenAI / DeepSeek / MiniMax / Kimi / GLM API key |
ANTHROPIC_API_KEY |
Anthropic API key |
LLM_MODEL |
(Optional) Override the default model for the selected provider |
src/
โโโ index.ts # Entry point
โโโ utils/
โ โโโ file-utils.ts # File sandboxing utilities (safePath)
โโโ agent/
โ โโโ loop.ts # Agent loop โ orchestrates tool calls
โ โโโ prompt.ts # System prompt builder
โ โโโ permission-manager.ts # Tool-call deny/ask rules
โ โโโ hooks.ts # LoopListener lifecycle
โ โโโ tools/
โ โ โโโ index.ts # Tool registry & exports
โ โ โโโ tool-registry.ts
โ โ โโโ bash.ts # Shell command execution
โ โ โโโ calculate.ts # Mathematical expression evaluator
โ โ โโโ edit.ts # File text replacement
โ โ โโโ glob.ts # File finder by glob pattern (exports globToRegex + walk)
โ โ โโโ grep.ts # Regex content search (reuses glob helpers)
โ โ โโโ ls.ts # Directory listing
โ โ โโโ read.ts # File reader
โ โ โโโ write.ts # File writer
โ โ โโโ memory/ # save-memory-tool + memory-manager
โ โ โโโ skill/ # load-skill + skill-registry
โ โ โโโ todo/ # todo + todo-tool
โ โโโ commands/ # /help /compact /new /list /list-perm-rule /prompt
โ โโโ compact/ # Three-layer context compression
โ โโโ subagent/ # dispatch_task + subagent runtime
โ โโโ hooks/ # usage-hook
โโโ cli/
โ โโโ repl.ts # Interactive REPL
โโโ config/
โ โโโ config-loader.ts # codecode.yml loader
โโโ llm/
โ โโโ factory.ts # Model factory (dispatches by API framework)
โ โโโ providers.ts # Provider configuration
โ โโโ openai-chat-model.ts # OpenAI-compatible API client
โ โโโ anthropic-chat-model.ts # Anthropic API client
โโโ session/
โ โโโ session-manager.ts # Persist turns to {CODEDIR}/sessions/
โโโ types/
โโโ index.ts # Shared types & interfaces
โโโ messages.ts # Message classes
- The agent loop (
loop.ts) sends the conversation + available tool definitions to the LLM - The LLM responds with either a text reply or one or more tool calls
- If tool calls are requested, the loop executes them via the tool registry (
tools/index.ts) and feeds results back to the LLM - This continues until the LLM produces a final text response
| Tool | Description |
|---|---|
calculate |
Evaluate a mathematical expression |
bash |
Run a shell command in the current workspace |
read |
Read the contents of a file |
write |
Write content to a file (creates parent dirs) |
edit |
Replace text in a file (first occurrence by default; replace_all: true for every match) |
glob |
Find files by glob pattern (e.g. src/agent/tools/*.ts) |
grep |
Search file contents by regex; returns files / lines / counts |
ls |
List entries in a directory (non-recursive) |
load_skill |
Load a skill into the current context |
todo |
Update the session plan for multi-step work |
save_memory |
Persist a memory across sessions (user / feedback / project / reference) |
dispatch_task |
Spawn a read-only subagent with a fresh context for complex sub-tasks |
File I/O tools (read/write/edit) are sandboxed to the current workspace โ paths that escape via .. traversal are rejected. bash is gated by the permission system's deny/ask rules.
# TypeScript compilation check
npm run typecheck
# Build
npm run buildISC