Skip to content

Zen-Open-Source/SimpleCLI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AI CLI

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.


Prerequisites


Setup

# 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-here

Run it

npm start

You'll see this prompt:

AI CLI  |  /quit to exit  |  /history to inspect context

You: _

Type anything and hit enter. Claude responds in real time.


Built-in commands

Command What it does
/quit or /exit Exit the CLI
/history Print the full conversation context as JSON

How it works

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.


Project structure

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

Extending it

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.js

Persist 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.).


Troubleshooting

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.


Cost

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.

About

A simple AI-native CLI

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors