chatty/CLAUDE.md

50 lines
1.4 KiB
Markdown

# Chatty
CLI chat client for OpenAI models with conversation persistence.
## Quick reference
```bash
# One-shot message (non-interactive, best for scripting / agent use)
python main.py "Your message here"
# One-shot with a named conversation (creates or resumes)
python main.py -n my-thread "Follow-up question"
# One-shot with a specific model
python main.py -m gpt-4o "Hello"
# Interactive mode
python main.py
python main.py -n my-thread
# Resume by conversation ID
python main.py --resume 3
# List saved conversations
python main.py --list
# Custom system prompt
python main.py -s "You are a pirate." "Ahoy?"
```
## Architecture
Single-file app: `main.py`. SQLite database `conversations.db` stores all conversations and messages.
Key functions:
- `send_message()` - one-shot: send a message, get a response, no UI
- `chat_loop()` - interactive REPL with streaming output
- `get_or_create_conversation()` - upserts by name
- `load_messages()` / `save_message()` - DB read/write
## Environment
Requires `OPENAI_API_KEY` in environment or `.env` file. Dependencies: `openai`, `python-dotenv`.
## Conventions
- Default model: `gpt-4.1` (set via `DEFAULT_MODEL`)
- Messages are saved to DB only after a successful API response
- System prompt is stored as the first message in a conversation
- Named conversations are resumed automatically; unnamed ones always create new entries