A bare-bones, AI-native command line chat interface powered by Claude. One file, no framework, streams tokens as they arrive. Open Source, created by Morgan Linton.
- Node.js v18 or higher
- An Anthropic API key
# 1. Clone or download this project, then enter the folder
cd ai-cli
# 2. Install dependencies
npm install
# 3. Create your environment file
cp .env.example .env
# 4. Open .env and paste your API key
ANTHROPIC_API_KEY=sk-ant-your-key-herenpm startYou'll see this prompt:
AI CLI | /quit to exit | /history to inspect context
You: _
Type anything and hit enter. Claude responds in real time.
| Command | What it does |
|---|---|
/quit or /exit |
Exit the CLI |
/history |
Print the full conversation context as JSON |
Stateless API, stateful array. The Claude API remembers nothing between calls. This app keeps a history array of every message and sends the whole thing on every request. That array is the memory.
Streaming. Uses client.messages.stream() instead of client.messages.create() so tokens print as they arrive, not after the full response is ready.
One file. The entire app lives in index.js. Read it top to bottom in about 5 minutes.
ai-cli/
├── index.js # The entire app
├── package.json # Dependencies and scripts
├── .env # Your API key (never commit this)
├── .env.example # Safe template to copy from
└── .gitignore # Excludes node_modules and .env
A few natural next steps if you want to go further:
Make it a global command — add this to package.json, then run npm link:
"bin": { "ai": "index.js" }Now you can type ai from any directory.
Pipe input — already works out of the box:
echo "summarize this in one sentence: $(cat somefile.txt)" | node index.jsPersist sessions — write history to a JSON file on exit, load it on startup to continue where you left off.
Clear context — add a /clear command that resets the history array to [].
Switch models — change the model field in the chat() function. Available options: claude-opus-4-6, claude-sonnet-4-6, claude-haiku-4-5-20251001.
Add tools — pass a tools array to the API call to give Claude the ability to run functions (web search, code execution, file access, etc.).
Error: ANTHROPIC_API_KEY is missing — your .env file is missing or the key isn't set. Double-check the file exists and the key starts with sk-ant-.
Cannot use import statement — make sure "type": "module" is in your package.json. It should be there already.
command not found: node — install Node.js from nodejs.org. v18+ required.
Claude Sonnet charges per token. A typical back-and-forth message costs a fraction of a cent. Long sessions with large history accumulate tokens faster since the full history is sent every turn. Use /history to see how large your context has grown.