A lightweight, Python-based CLI tool that integrates LLMs directly into your terminal
Project description
Whai - A Terminal assistant for developers who want control
https://github.com/user-attachments/assets/cbe834f0-2437-405b-9c95-88f02f6f69d9
Table of Contents
- What is it
- Core Features
- Quick Examples
- Installation
- Quick Start
- Key Features
- FAQ
- Contributing
- Changelog
- Acknowledgments
What is it
whai is a lightweight AI terminal assistant that integrates directly into your native shell and workflow.
The philosophy of whai is to supplement your normal terminal usage without taking control.
You don't have to start a chat loop, alt-tab or copy paste.
When you get stuck, need a command, or encounter an error, just call whai for help on demand.
Core Features
-
Analyze Previous Errors: If a command fails, you can call
whai(no arguments needed!) or askwhai why did that fail?. It reads the failed command and its error output from your terminal history to provide a diagnosis and solution. Note: Command output is available when running inside tmux or awhai shellsession. Otherwise, the model will only see your commands but not their outputs. -
Persistent Roles (Memory):
whaiuses simple, file-based "Roles" to provide persistent memory. You define your context once, what machine you are on, what tools are available, your personal preferences, and how you like to work, andwhairetains this context for all future interactions. -
Session Context: When running inside
tmuxor awhai shellsession,whaireads your command history and outputs to understand both what you ran and what happened. -
Help On Demand: Get help as you're using your shell:
> whai check my docker containers logs for errors> whai "Is this resource usage normal?" -
Requires Approval: Every
whaicommand requires your explicit[a]pprove/[r]ejectconfirmation. -
Model-Agnostic: Use models from OpenAI, Gemini, Anthropic, local Ollama models, and more.
Quick Examples
Example 1: Running a command
$ whai give me the biggest folder here
Info: Model: gpt-5-mini | Role: default
I'll list all top-level directories (including hidden ones),
compute their disk usage, sort them, and show the largest
few with human-readable sizes.
I'll run this command:
find . -maxdepth 1 -mindepth 1 -type d -print0 | \
xargs -0 du -sk 2>/dev/null | \
sort -n | tail -n 5 | \
awk '{print $1 "\t" $2}' | \
numfmt --to=iec-i --suffix=B --field=1,1
Breakdown of what each part does:
- find . -maxdepth 1 -mindepth 1 -type d: Find directories at
current level only (excludes . and ..)
- -print0: Use null separator to safely handle spaces in
directory names
- xargs -0 du -sk: Pass each directory to du to get disk usage
in kilobytes, 2>/dev/null suppresses errors
- sort -n: Sort numerically by size
- tail -n 5: Show the 5 largest entries
- awk '{print $1 "\t" $2}': Format output as size (tab) path
- numfmt --to=iec-i --suffix=B --field=1,1: Convert sizes to
human-readable format (KiB, MiB, etc.)
╭─────────────────────── Proposed command ────────────────────────╮
│ find . -maxdepth 1 -mindepth 1 -type d -print0 | │
│ xargs -0 du -sk 2>/dev/null | │
│ sort -n | tail -n 5 | │
│ awk '{print $1 "\t" $2}' | │
│ numfmt --to=iec-i --suffix=B --field=1,1 │
╰─────────────────────────────────────────────────────────────────╯
[a]pprove / [r]eject / [m]odify: a
╭─────────────────── Output ────────────────────╮
│ 440B ./tests │
│ 1.4KiB ./.git │
│ 87KiB ./.venv_tmp │
│ 108KiB ./.venv │
│ 123KiB ./.venv-linux │
╰───────────────────────────────────────────────╯
Result (interpretation)
- The largest top-level directory here is ./.venv-linux
with ~123KiB.
Next steps (options)
- Show the top N largest items anywhere under the current
tree (files+dirs):
- du -ah . 2>/dev/null | sort -rh | head -n 30
- Show only directories, recursively, largest first:
- du -h --max-depth=3 2>/dev/null | sort -hr | head -n 30
Example 2: Troubleshooting terminal output
$ uv pip install requirements.txt
Using Python 3.11.9 environment at: .venv-linux
× No solution found when resolving dependencies:
╰─▶ Because requirements-txt was not found in the package registry...
$ whai what is the problem
Info: Model: gpt-5-mini | Role: default
What's happening
- You ran: uv pip install requirements.txt
- pip treated "requirements.txt" as the name of a package to
download from the package index, not as a file of requirements.
- The resolver tried to find a package called (normalized)
"requirements-txt" on PyPI and failed, so it reports the
dependencies are unsatisfiable.
How to fix it
- Use the -r (or --requirement) flag so pip reads the file
instead of treating it as a package name.
Commands you can run
1) Check the requirements file exists:
ls -l requirements.txt
2) Install from the file (match how you invoked pip):
uv pip install -r requirements.txt
Do you want me to:
- run the ls to confirm the file exists, or
- run the install command for you now?
Example 3: Calling whai without arguments
$ git push origin main
To https://github.com/user/repo.git
! [rejected] main -> main (non-fast-forward)
error: failed to push some refs to 'https://github.com/user/repo.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
$ whai
Info: Model: gpt-5-mini | Role: default
What's happening
- You tried to push your local branch "main" to the remote,
but git rejected it.
- Your local branch is behind the remote branch—someone else
pushed changes to the remote that you don't have locally.
- Git won't let you push because it would overwrite those
remote changes.
How to fix it
- Pull the remote changes first, then push. This integrates
the remote commits with your local ones.
Commands you can run
1) See what commits are on the remote but not locally:
git fetch
git log HEAD..origin/main
2) Pull and merge the remote changes:
git pull origin main
3) After resolving any merge conflicts (if they occur), push again:
git push origin main
Do you want me to run git pull for you now?
Example 4: Asking questions
$ whai "Quick how do I exit Vim??"
Info: Model: gpt-5-mini | Role: default
I'll show the quick ways to exit Vim and what each one does.
1) Get to Normal mode
- Press Esc (or Ctrl-[) until you stop inserting text. If Esc doesn't respond, try Ctrl-C.
2) Common exit commands (type them in Normal mode, then press Enter)
- :q
- Quit (works only if no changes since last save).
- :q!
- Quit and discard any unsaved changes.
- :wq
- Write (save) and quit.
- :x
- Write (only if changed) and quit (similar to :wq).
3) Shortcuts
- ZZ (Shift+Z twice) — save and quit (same as :wq if there are changes).
- ZQ — quit without saving (same as :q!).
Installation
Option 1: uv (Recommended)
uv tool install whai
Or even without installing it!
uvx whai "your command"
Option 2: pipx
pipx install whai
Option 3: pip
pip install whai
Option 4: From source
git clone https://github.com/gael-vanderlee/whai.git
cd whai
pip install -e .
Quick Start
1. Configure your API key
On first run, whai launches an interactive configuration wizard:
whai --interactive-config
Or edit ~/.config/whai/config.toml directly:
[llm]
default_provider = "openai"
[llm.openai]
api_key = "sk-proj-your-key-here"
default_model = "gpt-5-mini"
Get API keys from:
- OpenAI Platform
- Anthropic Console
- Azure Portal (for Azure OpenAI)
- Google AI Studio (for Gemini)
Using Local Models (LM Studio)
To use a local model with LM Studio:
-
Enable the server in LM Studio:
- Open LM Studio
- Go to the Developer menu
- Enable the server toggle
-
Configure whai:
whai --interactive-config- Select
lm_studioas the provider - Enter the API base URL:
http://localhost:1234/v1 - Enter the API key (optional, leave empty if not required)
- Enter the model name without prefix (e.g.,
llama-3-8b-instruct)
Note: Model names are stored without provider prefixes in the config file. Prefixes are automatically added at runtime when needed.
- Select
-
Check available models:
curl http://localhost:1234/v1/models
2. Start using whai
Getting Help: For a complete list of command-line options and flags, run
whai --help.
whai "your question"
That's it! whai will:
- Read your terminal context (commands + output if in tmux or
whai shell, commands only otherwise) - Send your question to the configured LLM
- Suggest commands with
[a]pprove/[r]eject/[m]odifyprompts - Execute approved commands and continue the conversation
Tip: Quotes are not necessary, but do use them if you use special characters like
'or?whai show me the biggest file here whai "what's the biggest file?"
Key Features
Roles
Roles allow you to customize whai's behavior and responses, and let you save information you don't have to repeat yourself in every conversation.
- Your system information (OS, available tools, paths)
- Your preferences (shell style, preferred commands, workflows)
- Environment constraints (what you can/can't do, security policies)
- Project-specific context (tools in use, conventions, setup)
Let's create a toy role that tells whai to respond only in emoji:
$ whai role create emoji # "Answer using only emojis"
$ whai can you tell me the plot of the first Shrek movie --role emoji
Info: Model: gpt-5-mini | Role: emoji
👑👸💤🐉🏰
👹🏞️🕳️➡️🏰🐴😂
⚔️🐉🔥💨👸
👹❤️👸💚
🌅💋✨💚💚
🎉🎶🧅
# Create a new role
whai role create my-workflow
# Use it
whai "help me with this task" -r my-workflow
# List all roles
whai role list
For a complete list of role management commands, run whai role --help.
Roles are stored in ~/.config/whai/roles/ as Markdown files with YAML frontmatter, like so:
---
provider: openai
model: gpt-5-mini
# Optional parameters you can add:
# temperature: 0.3 # Only used when supported by the selected model
---
You are a helpful terminal assistant.
Describe context, behaviors, tone, and constraints here.
Available Providers:
You can specify any of the following providers in the provider field:
openai- OpenAI models (e.g.,gpt-5-mini,gpt-4)anthropic- Anthropic Claude models (e.g.,claude-3-5-sonnet-20241022)gemini- Google Gemini models (e.g.,gemini-2.5-flash)azure_openai- Azure OpenAI serviceollama- Local Ollama models (requires local Ollama instance)lm_studio- LM Studio local models (requires LM Studio server running)
The provider must be configured in your ~/.config/whai/config.toml file before it can be used. If no provider is specified in the role, whai uses the default provider from your configuration.
The default role is defined in the config.
Context Awareness
whai automatically captures context from:
- tmux scrollback (recommended): Full commands + output context
- Recorded shell sessions: Full commands + output when using
whai shell - Shell history (fallback): Recent commands only when not in tmux
Recorded Shell Sessions
For output context without tmux, use whai shell to launch an interactive shell with session recording:
whai shell
This command:
- Opens your normal shell (bash, zsh, fish, or PowerShell) with identical behavior
- Records all commands and outputs to a session log
- Provides commands + outputs to whai without requiring tmux
The recorded session behaves exactly like your normal shell. The only difference is that whai can now access full command outputs for better assistance.
To exit: Type exit in the shell to return to your previous terminal.
Options:
# Launch with a specific shell
whai shell --shell zsh
# Specify a custom log path
whai shell --log ~/my-session.log
Session logs are stored temporarily during the session and are deleted when you exit the shell.
When you run whai from within a recorded shell session, it automatically uses the in-session log.
Safety First
- Every command requires explicit approval
- Modify commands before execution
- Commands run in isolated subprocess (won't affect your main shell)
- Press
Ctrl+Cto interrupt anytime
FAQ
How is this different from [insert app here] ?
whai is integrated into your terminal with context awareness. It sees your command history and can execute commands.
Most terminal assistants either require you to explicitely start a chat loop which takes you out of your usual workflow, don't allow for roles, or don't allow to mix natural language conversation and shell execution.
The goal was really to replace alt-tabbing to google with a CLI command.
Does it send my terminal history to the LLM?
Only when you run whai.
It captures recent history (50 last commands), tmux scrollback (commands + output), or recorded shell session content (commands + output while the session is active) and includes it in the request.
If you use a remote API model, it will see your recent terminal history.
You can disable this with the --no-context flag.
Can I use it with local models?
Yes! Configure Ollama or LMStudio for local models. See the configuration section above.
Contributing
Contributions are welcome! If you'd like to contribute to whai, please:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Run the test suite (
uv run pytest) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
For detailed development setup and guidelines, see DEV.md.
Acknowledgments
Built with LiteLLM for multi-provider support, Typer for the CLI, and Rich for pretty terminal output.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file whai-0.8.3.tar.gz.
File metadata
- Download URL: whai-0.8.3.tar.gz
- Upload date:
- Size: 85.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.10 {"installer":{"name":"uv","version":"0.9.10"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3b1706a22124c6664bcd58b53f5360039e792207112e7e0e32b3c650140dea3f
|
|
| MD5 |
d582b8f73e6c98a6c893d0acccf78406
|
|
| BLAKE2b-256 |
626e4ed2da2ed4593a5ed92ca2b2432e1ae20d579bd3202337116381f0570084
|
File details
Details for the file whai-0.8.3-py3-none-any.whl.
File metadata
- Download URL: whai-0.8.3-py3-none-any.whl
- Upload date:
- Size: 103.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.10 {"installer":{"name":"uv","version":"0.9.10"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f438c36604b349a751e0eb8f95d6b9c79c022a6a85f9d8c92f3b3d6ab2db4ec3
|
|
| MD5 |
c284c448a8d6fea002f86a857ed844cb
|
|
| BLAKE2b-256 |
9a71630141a2ff9c3443674d6e047112f4306595c880560ccd69c4dc4eedbaa1
|