cmd-ai is an npm package that installs a global ai command for terminal use.
Primary flow:
- user writes a natural-language task, e.g.
ai list files - provider generates shell command(s)
- CLI shows the proposed command
- user confirms execution
- command runs (or is skipped by
--dry, cancellation, or safety block)
Configured with ai config.
Supported providers:
ollama(default): uses local Ollama models selected fromollama listopenai: uses OpenAI Codex models through the Responses APIgemini: uses Google Gemini models throughgenerateContentclaude: uses Anthropic Claude models through the Messages API
gpt-5.3-codexgpt-5.3-codex-sparkgpt-5.2-codexgpt-5.1-codexgpt-5.1-codex-max
Configurable in CLI:
- API key
- model
- reasoning effort (
low/medium/high, plusxhighforgpt-5.3-codexandgpt-5.2-codex)
gemini-3.1-pro-previewgemini-3-flash-previewgemini-3.1-flash-lite-previewgemini-2.5-progemini-2.5-flashgemini-2.5-flash-lite
Configurable in CLI:
- API key
- model
- reasoning effort (
low/medium/high)
Implementation detail:
- Gemini 3.x models use
thinkingConfig.thinkingLevel - Gemini 2.5 models use
thinkingConfig.thinkingBudgetmapped from effort
claude-opus-4-6claude-sonnet-4-6claude-haiku-4-5
Configurable in CLI:
- API key
- model
- reasoning effort (
low/medium/high;maxalso available forclaude-opus-4-6)
Implementation detail:
- reasoning effort is sent via
output_config.effortfor supported models (opusandsonnet) claude-haiku-4-5is supported as a model choice, but effort control is not applied in this CLI path
- checks that
ollamacommand exists - fetches local models from
ollama list - user picks one model in
ai config - selected model is stored in config and used for prompt generation
Commands:
ai <task>ai configai historyai manai install-autocomplete
Flags:
--explain--dry--help/-h--version
Config:
$XDG_CONFIG_HOME/cmd-ai/config.json- fallback when
XDG_CONFIG_HOMEis unset:~/.config/cmd-ai/config.json - legacy read compatibility:
~/.ai-config.json
History:
$XDG_STATE_HOME/cmd-ai/history.json- fallback when
XDG_STATE_HOMEis unset:~/.local/state/cmd-ai/history.json - legacy read compatibility:
~/.ai-command-history.json
History entry fields:
timestamppromptcommandexecutedprovider- optional
notes
History is trimmed to the latest 1000 entries before append.
- proposed commands pass through a danger-pattern filter before execution
- obviously risky commands are not auto-executed and are logged
- execution still requires user confirmation (unless cancelled/dry run path)
- execution prefers
process.execvehandoff when available (non-Windows runtimes that support it), with fallback tochild_process.exec
Generated provider output is parsed by:
- extracting fenced code blocks when present
- otherwise finding first command-like line
- stripping shell prompt noise and wrappers
- separating explanation from command when
--explainis on
ai install-autocomplete:
- copies
cmd-ai-completion.shto$XDG_DATA_HOME/cmd-ai/cmd-ai-completion.sh - fallback when
XDG_DATA_HOMEis unset:~/.local/share/cmd-ai/cmd-ai-completion.sh - updates shell rc source line to that XDG path when possible
- CLI logic:
bin/ai.js - shell completion script:
cmd-ai-completion.sh - package metadata + bin mapping:
package.json - docs:
README.md - release helper:
scripts/release.mjs
Use this for future releases:
- Decide release kind:
fix(patch)feature(minor)breaking(major)
- Run:
npm run releasenpm run release does all of the following:
- verifies required scripts exist in
package.json(dev:check,lint) - runs
npm run dev:check - runs
npm run lint(required) andnpm run dev:pack(optional) checks if present - prompts for release kind if not passed as an argument (or accepts:
npm run release -- fixnpm run release -- featurenpm run release -- breaking)
- runs
npm versionwithout creating a git tag directly, then creates an annotated release commit and tag - creates an annotated version tag (default
npm versionformat) - pushes commit and tags
- runs
npm publish(supports interactive OTP prompt orNPM_OTPenv var when 2FA is required) - prints the published package version
If you prefer manual steps, run these in order:
npm run dev:check
npm run lint
npm run dev:pack
npm version patch # or minor/major
git push --follow-tags
npm publish- model lists are intentionally hardcoded; updating requires code changes in
bin/ai.js install-autocompletecopies the bundledcmd-ai-completion.shfrom the installed package path and sources it from the XDG data path- safety filter is pattern-based, not a full shell parser/sandbox