This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
nanocode is a minimal, single-file Claude Code alternative - an interactive coding assistant CLI that uses the Anthropic Claude API with tool-calling capabilities. Built with TypeScript and Bun runtime (~345 lines, zero external dependencies).
# Set API key first
export ANTHROPIC_API_KEY=your_key
# Run the assistant
bun run index.ts
# or
./index.tsBuilt-in commands:
/qorexit- quit the assistant/c- clear conversation history
Single-file design (index.ts) with these sections:
- Configuration & Constants (lines 1-13): Environment variables, color codes, platform detection
- Types (lines 15-42): TypeScript interfaces for tools, messages, API responses
- Utility Functions (lines 44-50): Path resolution, ignore pattern matching
- Tool Implementations (lines 52-208): Ten async functions using Bun APIs:
read- Read files with line numbers (supports offset/limit)write- Write content to filesedit- Find and replace in files (single or all occurrences)glob- Find files by pattern (sorted by mtime, newest first)grep- Search files with regex (capped at GREP_LIMIT)exec- Execute shell commands with live output streaming (timeout: 1ms-300s)list- List directory contents (supports recursive)delete- Delete files/directories (supports recursive)move- Move or rename filescopy- Copy files/directories (supports recursive)
- Tool Registry (lines 210-229):
TOOLSrecord mapping names to[description, params, fn]tuples, plusmakeSchema()for API format - API Layer (lines 231-246): Direct fetch calls to Anthropic API
- UI Utilities (lines 248-252): Markdown rendering, separator formatting
- Signal Handlers (lines 254-260): Graceful shutdown on SIGINT/SIGTERM
- REPL Loop (lines 262-328): Agentic loop using
consoleasync iterator for input
Bun-specific APIs used:
Bun.file()/Bun.write()for file I/OBun.spawn()for shell commandsBun.Globfor file pattern matchingconsoleasync iterator for stdin
Key Features:
- Smart Filtering: Auto-ignores
.git,node_modules,dist,build,.next,coverage,.cache - File Size Limit: Prevents reading files larger than MAX_FILE_SIZE (default 10MB)
- Live Output:
exectool streams stdout/stderr in real-time with prefixes - Error Handling: Graceful error handling with detailed error messages
- Cross-Platform: Auto-detects Windows (cmd /c) vs Unix (sh -c)
Key Constraints:
- Exec commands: timeout range 1ms - 300,000ms (5 minutes)
- Grep results: capped at GREP_LIMIT (default 50)
- Model:
claude-opus-4-5with 8192 max tokens - System prompt:
NANOCODE: Concise coding assistant. OS: {platform} {arch}. Time: {ISO timestamp}. CWD: {working directory}
Add entry to TOOLS record:
tool_name: ["Description for Claude", { param: "string", optional_param: "number?" }, async (args) => {
// Implementation
return "result";
}],Schema types: string, number (becomes integer), boolean. Append ? for optional params.
- No /info or /help commands: These were planned but not implemented in current code
- No session logging: Logging features documented but not present in index.ts
- Minimal REPL: Only
/q,exit, and/ccommands are active - Simple system prompt: Just OS info, time, and CWD - no local time formatting