teenycode
v0.1.1
Published
A tiny coding agent in TypeScript (under 200 LOC)
Readme
TeenyCode
A tiny code‑editing agent in TypeScript (200 LOC) — a minimal, hackable CLI that talks to OpenAI and can read, list, and edit files in your working directory.
This repository is for educational purposes, to demonstrate the core elements of a minimal CLI coding agent.
It's adapted from How to build an agent by Amp.
Features
- Chat-based CLI that calls OpenAI and uses tool calls
- File tools:
read_file,list_files,edit_file(single, unique replacement or create new file) - Prefers reading files over guessing; makes the smallest edit that satisfies a request
- Minimal dependencies and simple code you can tweak
[!NOTE] No
bashtool added since this is just for educational purposes, you can easily add it yourself.
Requirements
- Node.js 22+
- npm for
npx teenycode, or Vite+ (vp) for local development - An OpenAI API key
Quickstart
export OPENAI_API_KEY=sk-...
npx teenycodeOr put OPENAI_API_KEY=sk-... in a .env file in the directory where you run npx teenycode.
If you prefer a one-liner:
OPENAI_API_KEY=sk-... npx teenycodeIf OPENAI_API_KEY is missing, the CLI prints setup instructions and exits.
Local development
vp install
cp .env.example .env
# edit .env and set your API key
vp run startYou'll see a prompt like Chat with <model>. Type your requests. Quit with exit, quit, :q, or Ctrl‑C.
How it works (quick tour)
src/index.ts: Entry point; checksOPENAI_API_KEY, starts the agentsrc/agent.ts: Chat loop, tool routing, and message statesrc/tools.ts: Three built-in tools implemented with NodefsAPIs
The agent uses OpenAI Chat Completions with function/tool calling. Tool inputs are validated with Zod, and schemas are exported to JSON Schema for the model.
Example
➜ teenycode git:(main) ✗ OPENAI_API_KEY=sk-... npx teenycode
Chat with gpt-5 (type 'exit' or 'quit' or use Ctrl-C to quit)
You: What is this repo about?
tool: list_files({"path": ""})
tool: read_file({"path":"README.md"})
tool: read_file({"path":"package.json"})
tool: read_file({"path":"src/index.ts"})
tool: read_file({"path":"src/agent.ts"})
tool: read_file({"path":"src/tools.ts"})
Agent: TeenyCode is a tiny, hackable CLI coding agent written in TypeScript (~200 LOC) for educational purposes. It chats with OpenAI and can operate on your local files via three tools:
- read_file: read a file’s contents
- list_files: list files/dirs at a path
- edit_file: make a single, unique text replacement or create a new fileTools
The agent exposes three file tools:
read_file(path: string): Reads and returns the text contents of a file at a relative path.list_files(path: string): Lists files and directories at the given path (use "." for the current dir).edit_file(path: string, old_str: string, new_str: string): Replaces exactly one occurrence of old_str with new_str in the given file.
Conventions:
- All paths are relative to your current working directory.
- The agent prefers reading over guessing and aims to make the smallest possible change.
Notes
- Edits are surgical by design. Keep your work in git and commit often.
- The agent operates relative to your current working directory.
Quality checks
vp check
vp lint --fix
vp fmt
vp test
vp buildAcknowledgements
Adapted from How to build an agent by Amp.
