Skip to content

Repository files navigation

CodeCode

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.

Features

  • ๐Ÿง  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

Quick start

# 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

Select a provider

# 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

Environment variables

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

Architecture

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

How it works

  1. The agent loop (loop.ts) sends the conversation + available tool definitions to the LLM
  2. The LLM responds with either a text reply or one or more tool calls
  3. If tool calls are requested, the loop executes them via the tool registry (tools/index.ts) and feeds results back to the LLM
  4. This continues until the LLM produces a final text response

Tools

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.

Development

# TypeScript compilation check
npm run typecheck

# Build
npm run build

License

ISC

Releases

Packages

Contributors

Languages