A simple command-line chat demo using Claude Agent SDK with OAuth Token authentication, available in both TypeScript and Python versions.
claude-chat-demo/
├── ts_demo/ # TypeScript/JavaScript version
│ ├── index.js
│ ├── package.json
│ ├── .env.example
│ └── README.md
├── py_demo/ # Python version
│ ├── main.py
│ ├── requirements.txt
│ ├── .env.example
│ └── README.md
├── README.md # This file (English)
└── README_zh.md # Chinese documentation
- ✅ OAuth Token authentication (recommended for Claude Pro/Max users)
- ✅ API Key authentication
- ✅ Simple command-line interface
- ✅ Real-time conversation experience
- ✅ Available in both TypeScript and Python
Requirements: Node.js 18+
cd ts_demo
npm install
cp .env.example .env
# Edit .env file and add your CLAUDE_CODE_OAUTH_TOKEN or ANTHROPIC_API_KEY
npm startSee ts_demo/README.md for detailed instructions.
Requirements: Python 3.8+
cd py_demo
python3 -m venv venv
source venv/bin/activate # macOS/Linux
# or: venv\Scripts\activate # Windows
pip install -r requirements.txt
cp .env.example .env
# Edit .env file and add your CLAUDE_CODE_OAUTH_TOKEN or ANTHROPIC_API_KEY
python main.pySee py_demo/README.md for detailed instructions.
If you have a Claude Pro or Claude Max subscription:
# 1. Install Claude CLI (if not already installed)
npm install -g @anthropic-ai/claude-code
# 2. Get OAuth Token
claude setup-token
# 3. Copy the generated token and add to .env file
CLAUDE_CODE_OAUTH_TOKEN=your-oauth-token-hereGet your API Key from Anthropic Console:
ANTHROPIC_API_KEY=sk-ant-your-api-key-here🤖 Claude Agent SDK CLI Chat Demo
==================================================
✅ SDK initialized
💡 Tip: Type 'exit' or 'quit' to exit
You: Hello, introduce yourself
🤔 Claude is thinking...
Claude: Hello! I'm Claude, an AI assistant developed by Anthropic...
You: Write a bubble sort in Python
🤔 Claude is thinking...
Claude: Here's a bubble sort implementation:...
You: exit
👋 Goodbye!
| Variable | Description | Required |
|---|---|---|
CLAUDE_CODE_OAUTH_TOKEN |
OAuth Token (from claude setup-token) |
Either/Or |
ANTHROPIC_API_KEY |
API Key (from Anthropic Console) | Either/Or |
MODEL |
Model to use, default: claude-sonnet-4-5-20250929 |
No |
- OAuth Token: For Claude Pro/Max users, uses subscription quota, fixed cost
- API Key: Pay-per-use, suitable for developers and enterprises
Run claude setup-token command, which will open a browser for authentication and output the token in the terminal.
- Check if the token/key in
.envfile is correctly copied - If using OAuth Token, try running
claude setup-tokento get a new one - Ensure there are no extra spaces or line breaks in the token/key
- TypeScript version: If you're familiar with Node.js/JavaScript ecosystem
- Python version: If you prefer Python development environment
Both versions have identical functionality - choose the one you're most comfortable with.
You can configure the MODEL variable in .env file. Supported models include:
claude-sonnet-4-5-20250929(default, latest)claude-3-5-sonnet-20241022claude-3-opus-20240229- And more
- Node.js: JavaScript runtime
- @anthropic-ai/claude-agent-sdk: Claude Agent SDK (v0.1.30)
- dotenv: Environment variable management
- readline: Node.js built-in module for CLI interaction
- Python 3.8+: Programming language
- claude-agent-sdk: Claude Agent SDK Python version
- python-dotenv: Environment variable management
MIT