# CLI AI Coding Tools: Installation and Multi-Model Switching Guide
This guide explains how to install a command-line AI coding tool, verify the installation, and switch between multiple upstream models through a local proxy. It covers a pre-installation checklist, cross-platform setup on Linux, macOS, and Windows, common installation errors and fixes, a LiteLLM proxy configuration with model aliases, key management and security boundaries, and upgrade, uninstall, and rollback procedures, including CI usage and offline or internal-network scenarios.
CLI AI Coding Tools: Installation and Multi-Model Switching Guide
1. Who This Is For, and How to Read the Placeholders
Command-line AI coding tools are aimed at developers who need to call AI capabilities from a terminal, a remote development machine, a container, CI/CD, script pipelines, or automated workflows. Compared with IDE plugins, they integrate more easily with shells, Makefiles, Python scripts, GitHub Actions, GitLab CI, and similar engineering pipelines. They also fit situations where desktop software cannot be installed, or where tasks must run unattended.
If your team works mainly in a browser-based IDE or cloud notebook, or if your security policy forbids installing a local CLI, the migration cost goes up. If all you need is code completion inside an IDE, an IDE plugin is usually the more direct option. If you need to process repositories in bulk, troubleshoot on remote servers, script code reviews, or call models on an offline internal network, a command-line tool has the advantage.
To avoid inventing vendor-specific commands, this article uses a “generic installation template plus an open-source proxy example” approach. <package-name>, <command>, <version>, and <previous-version> are all placeholders:
<package-name>: the npm package name published by the tool’s official maintainers.<command>: the executable name available after installation, usually confirmable via--helpor the official documentation.<version>: the stable version required by the tool; you can uselatestor an explicit version number.<previous-version>: the historical version number used for rollback.
The Node.js installation examples here apply when the target tool explicitly depends on Node.js and npm. If the target tool uses Python, Rust, Go, or a standalone binary, replace the installation method following the official documentation; the later reasoning about environment checks, model proxies, key safety, and uninstall/rollback still applies.
On versions: according to the Node.js release schedule, Node.js 20 reached end of maintenance in April 2026. As of the verification baseline of this article in August 2026, Active LTS is commonly Node.js 22 as a safe baseline, but the actual choice should follow the target tool’s official requirements and the latest release schedule. Do not chase the newest release blindly, and do not stay on a runtime that has passed end of maintenance for long.
2. Pre-Installation Checklist
Before installing, confirm the following items. This prevents common problems such as “command not found,” insufficient permissions, and incompatible native modules.
| Item | Recommended standard | How to verify |
|---|---|---|
| Operating system | Linux, macOS, Windows 10/11 | Check system information |
| CPU architecture | x64 or arm64; check the official support list first | uname -m or system information |
| Runtime | Node.js version officially supported by the tool | node -v |
| Package manager | npm version meets the official requirement | npm -v |
| Global install directory | Prefer a user-level directory to avoid polluting system directories | npm config get prefix |
| PATH | The executable’s directory is visible to the terminal | echo $PATH or $env:PATH in PowerShell |
| Write permission | The current user can write to the install directory | Check permissions on the prefix directory |
| Network | npm registry, internal mirror, or proxy is reachable | npm ping |
| Key policy | No hard-coded real keys; environment variables or a secret manager only | Inspect .env, config files, and CI variables |
One warning in particular: do not default to sudo npm install -g. If the system-wide global directory is not writable, create a user-level global directory instead of using administrator privileges to pollute system directories.
3. Environment Preparation
3.1 Check Node.js and npm
First check the current runtime and package manager versions:
node -vnpm -v
If the output looks like:
v18.19.09.2.0
and the target tool requires Node.js 22 or later, you need to upgrade. Prefer a version manager so that other projects are not affected.
On Linux or macOS you can use nvm. Before running a remote install script, verify the script’s source, version, and official release page; piping it straight into a shell without review is not recommended:
curl -fsSL -o nvm-install.sh https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh# Open nvm-install.sh and confirm the source and contents before running itbash nvm-install.shsource ~/.bashrc# or source ~/.zshrc
Install and switch Node.js:
nvm install 22nvm use 22node -vnpm -vnpm ls -g --depth=0
The last command, npm ls -g --depth=0, checks whether globally installed packages still work after the Node.js upgrade, so that global commands do not silently break.
On Windows you can use nvm-windows or the official installer. With nvm-windows, run the following in PowerShell:
nvm install 22nvm use 22node -vnpm -v
If your team uses an internal mirror, check the current registry:
npm config get registry
Note in particular: npm config set registry changes global configuration and can affect private package downloads, version locking, and build consistency in other projects. Better options:
- Create an
.npmrcin the project directory so the setting applies only to that project. - Specify the registry temporarily at install time:
npm install -g <package-name> --registry <registry-url> - Keep the enterprise official registry for private packages so third-party mirrors do not shadow them.
3.2 Avoid System Directory Permission Problems
npm’s default global directory may live inside a system directory. To avoid EACCES or Permission denied, configure a dedicated global prefix for the current user:
mkdir -p ~/.local/globalnpm config set prefix ~/.local/globalexport PATH="$HOME/.local/global/bin:$PATH"
To make this effective in new terminals, add it to your shell configuration:
echo 'export PATH="$HOME/.local/global/bin:$PATH"' >> ~/.bashrcsource ~/.bashrc
In Windows PowerShell, export does not work. $env:PATH usually applies only to the current PowerShell session. For a permanent change, add the directory to the system or user environment variables, then close and reopen PowerShell.
4. Installation Commands and Cross-Platform Steps
The examples below use the common Node.js ecosystem approach. Replace the placeholders with the package name, command, and version given in the official documentation.
4.1 Linux / macOS
npm install -g <package-name>@<version>
If you always want the latest stable version:
npm install -g <package-name>@latest
However, in production or team environments, pinning a version is better, for example <version> as 1.2.3, so upstream changes do not alter behavior.
Verify after installation:
<command> --version
On success, the output usually contains the tool name, version number, Node.js version, platform information, and similar details. On failure, for example command not found, troubleshoot in this order:
- Run
npm list -g <package-name>to confirm the package installed. - Run
npm prefix -gto find the global executable directory. - Check whether that directory is in
PATH. - Close and reopen the terminal, or manually run
source ~/.bashrcorsource ~/.zshrc.
4.2 Windows
Prefer a regular-user PowerShell session over an administrator PowerShell session. A user-level directory is usually sufficient and avoids permission pollution:
npm install -g <package-name>@<version><command> --version
If you get “command not found,” check in this order:
Get-Command <command>npm prefix -g$env:PATH
If the global bin directory is not in PATH, add it to the user environment variables. After that, close and reopen PowerShell, then run:
<command> --version
4.3 npx or Docker Alternatives
Some tools support a no-install trial run:
npx <package-name>@<version> --version
If the tool publishes an official Docker image, you can also run it in a container:
docker run --rm -it -v "$PWD":/workspace <official-image> <command> --version
The container approach suits CI, temporary environments, or keeping the local Node.js global directory clean. Watch out for mount directory permissions, network egress, how secrets are injected, and persistence of cache directories.
4.4 Common Errors and Fixes
| Symptom | Likely cause | Fix |
|---|---|---|
command not found |
Executable directory not in PATH | Check npm prefix -g, add the directory to PATH, reopen the terminal |
EACCES / Permission denied |
Global directory owned by a system user, or the current user cannot write to it | Switch to a user-level prefix, or use chown to return ownership of the prefix directory to the current user |
| Install succeeds but the command is still not found | Wrong package name, failed install, or the command name differs from the package name | Use npm list -g <package-name> and the official documentation to confirm the executable name |
NODE_MODULE_VERSION mismatch |
Node.js version incompatible with native modules | Switch to the officially required Node.js version, then check global packages after upgrading |
| Config error on startup | Missing config file, wrong variable name, or missing credentials | Run <command> --help, <command> doctor, or read the official documentation |
npm install times out |
Network, mirror, or proxy issues | Switch registry, configure a proxy and retry, or use an internal mirror |
If you need to repair directory permissions, first confirm the current user and the directory owner:
whoamils -ld ~/.local/global
If the directory was mistakenly handed to a system user, return it to the current user:
sudo chown -R "$(whoami)" ~/.local/global
This command affects every file under the directory, so confirm that no other tool shares it before running it.
5. Verification and Initialization
After installation, do not jump straight into a real project. Verify in an empty directory or a sandbox first.
5.1 Version Check
<command> --version
Success shows a clear version number. On failure, do not reinstall immediately; check PATH, the package name, and the global install result first.
5.2 Self-Check Commands
Most CLIs offer a self-check, help, or configuration-inspection command. Common forms:
<command> doctor<command> config list<command> --help
If the tool provides doctor, pay particular attention to:
- Whether the runtime meets the requirement.
- Whether the network can reach the model service or proxy.
- Whether auth is configured and the key source is safe.
- Whether the config path is clear.
- Whether
base_urlpoints to the expected address, especially when it should point at a local proxy.
5.3 Trial Run and Minimal End-to-End Acceptance
Try it out in an empty directory:
mkdir ~/ai-cli-sandboxcd ~/ai-cli-sandbox<command>
If the tool requires a login or API key, do it through the official login command or environment variables. Never write keys into source code. After the trial run, perform a minimal end-to-end acceptance check:
- Confirm that the
base_urlshown by<command> doctorpoints at the proxy address. - Send one request with a specific model, for example
--model fast-coder. - Check the proxy logs to confirm the request actually went through the proxy and that the model alias was recorded.
- If no request appears in the logs, the CLI is still talking directly to the official endpoint, or the variable name is wrong.
6. Why You Need a Model Proxy
By default, a command-line AI tool may connect to a single model service. In practice this causes several problems:
- A single model may be rate-limited, may raise prices, or may be unstable.
- Different tasks need different capabilities: completion needs low latency, complex refactoring needs strong reasoning.
- API keys written directly into the tool’s configuration leak easily.
- Teams need unified logging, rate limiting, cost accounting, auditing, and fallback policies.
The role of a model proxy is to insert a configurable forwarding layer between the CLI and the model services. A simplified chain:
Terminal / CI script↓Command-line AI coding tool CLI↓Model proxy http://127.0.0.1:4000├→ Model service A├→ Model service B└→ Logs / billing / audit
The CLI only needs to point at the local proxy address. When you switch models, you change the proxy configuration or startup arguments; there is no need to reinstall the CLI.
Dimensions to weigh when choosing a proxy:
| Dimension | What to check |
|---|---|
| Protocol compatibility | OpenAI-compatible endpoints, Anthropic endpoints, or a custom gateway |
| Model count | Multiple models, aliases, routing, and weights |
| Key management | Environment variables, key placeholders, master key |
| Logging and audit | Records of call time, model, duration, error codes, and caller |
| Deployment form | Python process, Docker, internal gateway, or managed cloud service |
| Cost accounting | Token usage, cost statistics, budget alerts |
7. Building a Multi-Model Proxy with LiteLLM
This article uses the open-source proxy LiteLLM as an example. It exposes an OpenAI-compatible interface and fits local development, internal gateways, and lightweight team proxy scenarios.
7.1 Install LiteLLM
LiteLLM requires a Python environment. A virtual environment is recommended:
python3 -m venv .venvsource .venv/bin/activatepip install --upgrade pippip install "litellm[proxy]"
Before starting, confirm the command is available:
litellm --version
If your team uses Docker, you can also start it from the official image, but confirm the image tag, port, config mount, and secret injection method in advance.
7.2 Define the Model List
Create a configuration file litellm_config.yaml:
model_list:- model_name: fast-coderlitellm_params:model: openai/<upstream-model-A>api_base: os.environ/UPSTREAM_A_BASEapi_key: os.environ/UPSTREAM_A_KEY- model_name: deep-reasonerlitellm_params:model: anthropic/<upstream-model-B>api_base: os.environ/UPSTREAM_B_BASEapi_key: os.environ/UPSTREAM_B_KEYgeneral_settings:master_key: os.environ/LITELLM_MASTER_KEY
Notes:
fast-coderis an alias at the proxy layer, suited to low-latency work such as lightweight completion, script generation, and comment generation.deep-reasoneris an alias at the proxy layer, suited to long-chain reasoning tasks such as complex refactoring, debugging, and architecture analysis.<upstream-model-A>and<upstream-model-B>should be replaced with the upstream model names you actually have access to.UPSTREAM_A_BASE,UPSTREAM_A_KEY, and the rest should be injected through environment variables, not written into the configuration file.
For local testing only, where the proxy listens on the local machine, you can temporarily use simplified authentication. Production environments should enable a master key, TLS, access control, and audit logging.
7.3 Inject Environment Variables and Start the Proxy
First set the upstream keys and the local proxy key:
export UPSTREAM_A_BASE="https://api.example-a.com/v1"export UPSTREAM_A_KEY="replace-with-real-key-a"export UPSTREAM_B_BASE="https://api.example-b.com"export UPSTREAM_B_KEY="replace-with-real-key-b"export LITELLM_MASTER_KEY="local-proxy-token"
Start the proxy:
litellm --config litellm_config.yaml --port 4000
Liveness check:
curl -fsS http://127.0.0.1:4000/health/liveliness
The response body may differ between versions; as long as the request succeeds and the process stays alive, the proxy is generally up. You can also query the model list:
curl -fsS http://127.0.0.1:4000/v1/models
7.4 Point the CLI at the Proxy
The environment variable names differ from one CLI to another. The variable names below are illustrative and not universal. Use the base_url and API key variables specified in the target tool’s official documentation:
export AI_BASE_URL="http://127.0.0.1:4000/v1"export AI_API_KEY="local-proxy-token"
Common variants may include:
export OPENAI_BASE_URL="http://127.0.0.1:4000/v1"export OPENAI_API_KEY="local-proxy-token"
or, for some Anthropic-compatible tools:
export ANTHROPIC_BASE_URL="http://127.0.0.1:4000"export ANTHROPIC_AUTH_TOKEN="local-proxy-token"
If the CLI supports a configuration file, prefer setting base_url and api_key there as documented officially, rather than relying on temporary environment variables.
After setting things up, you must verify that they take effect. If the tool offers doctor, config list, debug, or a logging mode, confirm that the actual request address points at the proxy. For example:
<command> doctor<command> config list<command> --debug
If the CLI does not seem to take effect, do not keep switching models. First check whether the proxy logs show incoming requests. If the proxy has no logs, the requests are not reaching the proxy.
7.5 Switch Models per Task
If the CLI supports a model parameter, specify the alias directly:
<command> --model fast-coder<command> --model deep-reasoner
If the CLI selects the model through an environment variable, set it as the official documentation describes. Illustratively:
export AI_MODEL="fast-coder"
Note: AI_MODEL is only an illustrative variable name and does not mean every tool uses it. Priority is generally understood as:
- Explicit command-line arguments, such as
--model - The tool’s configuration file
- Environment variables
- The proxy’s default model
If a switch still returns the default model, check the default setting or routing rules in the proxy configuration, and whether the CLI is reading an old environment variable.
7.6 Minimal Request Verification
Once the CLI points at the proxy, use curl to verify the proxy, authentication, and routing:
curl -fsS http://127.0.0.1:4000/v1/chat/completions \-H "Authorization: Bearer local-proxy-token" \-H "Content-Type: application/json" \-d '{"model": "fast-coder","messages": [{"role": "user","content": "ping"}]}'
A normal model response means the proxy, authentication, and routing basically work. If it returns an error, check first:
- Whether the
modelalias matches the configuration. - Whether the upstream model name is correct.
- Whether the upstream key has expired or lacks permission.
- Whether the proxy only listens on
127.0.0.1while you are accessing it from another container. - Whether network egress is blocked by a firewall.
7.7 Troubleshooting Model Aliases That Do Not Take Effect
| Symptom | Possible cause | How to investigate |
|---|---|---|
| Switching models changes nothing | The CLI is still using an old environment variable or config file | Check the precedence of AI_MODEL, --model, and the config file |
| The default model is returned | The proxy’s default alias was not switched | Inspect the proxy configuration and routing rules |
| 401/403 | Wrong local proxy key or upstream key | Check proxy logs and how keys are injected |
| 404 model not found | Misspelled alias or unavailable upstream model | Query /v1/models or the configuration file |
| Timeout | Upstream model unreachable or the timeout is too short | Adjust timeout, retry, and fallback policies |
| Request never reaches the proxy | The CLI base_url did not take effect |
Confirm with doctor, debug logs, or packet capture |
7.8 Model Selection and Cost Notes
| Alias | Suitable tasks | Context preference | Cost sensitivity | How to switch |
|---|---|---|---|---|
| fast-coder | Everyday completion, script generation, comments | Small-to-medium context is enough | High | --model fast-coder |
| deep-reasoner | Complex refactoring, debugging, architecture analysis | Larger context is more reliable | Medium to low | --model deep-reasoner |
| fallback-model | Safety net when the primary model fails | Close to the primary model | Medium | Configure a fallback policy |
Cost sensitivity here is only a qualitative estimate and cannot replace real billing. Actual cost depends on:
- Upstream model unit price.
- Input tokens, output tokens, and cached tokens.
- Request frequency and context length.
- Number of retries and the timeout policy.
- Whether caching, batch jobs, or local models are enabled.
This article does not promise any specific savings percentage. Whether you save money depends on task structure and usage. Measure with a small number of tasks first, then estimate the budget from proxy logs or the vendor’s bill. You can set a monthly budget ceiling, for example:
Daily budget per person: <daily budget>Monthly budget per team: <monthly budget>Per-request timeout: 30 secondsRetries after consecutive failures: 2After the primary model fails repeatedly: switch to fallback-model
If the proxy supports usage statistics, enable spend, usage, or audit logging; if it does not, estimate cost through gateway billing, the upstream console, or CI logs.
8. Key Management and Security Boundaries
Once a model is wired in, key safety becomes the priority. Follow these principles:
- Never commit keys to a repository. Configuration files hold placeholders only, such as
${KEY_A}and${KEY_B}. - Add sensitive files to
.gitignore, such as.env,litellm_config.local.yaml, and key cache directories. - The proxy should listen on the local machine by default, for example
127.0.0.1:4000, and should not bind to0.0.0.0. - Do not expose the proxy to the public internet. If the team shares it, use an internal gateway, VPN, mTLS, a reverse proxy, and access control.
- Local placeholder credentials exist only for communication between the CLI and the local proxy; they are not real upstream keys.
- Use separate keys per upstream service, and restrict call scope and model permissions.
- Redact logs. Avoid printing full request bodies, full keys, full source excerpts, or user private data.
- Enable auditing. Record call time, model alias, duration, status code, error message, and caller.
- Handle leaks. If a key leak is discovered, revoke the old key immediately, issue a new one, review the logs, and clean up local caches as well as anything mistakenly committed to Git history.
In CI, keys belong in the CI secret store or encrypted variables, not in the repository. For GitHub Actions use secrets; for GitLab CI use masked and protected variables. When running install scripts or fetching configuration, also avoid echoing keys into logs.
9. Updates, Uninstall, Rollback, and FAQ
9.1 Update and Upgrade
Back up your configuration before upgrading:
cp ~/.config/<tool>/config.yaml ~/.config/<tool>/config.yaml.bak
If the tool supports doctor, run the self-check after upgrading before starting project work.
Update to the latest version:
npm install -g <package-name>@latest
Update to a pinned version:
npm install -g <package-name>@<new-version>
Verify after upgrading:
<command> --version<command> doctor
9.2 Uninstall
Uninstall the global install:
npm uninstall -g <package-name>
If you configured a user-level prefix, you can check:
npm config get prefixls -la ~/.local/global
Clean up carefully. Do not delete directories shared by other tools. If you only want to remove the current tool, prefer npm uninstall -g over deleting the entire bin directory.
9.3 Rollback
Roll the tool version back:
npm install -g <package-name>@<previous-version>
Roll the Node.js version back:
nvm install <previous-node-version>nvm use <previous-node-version>node -vnpm ls -g --depth=0
Restore PATH: if you added a user-level path earlier, remove the corresponding export PATH line from your shell configuration and reload the shell.
9.4 FAQ
Q: It says command not found after installation.
Check npm prefix -g, npm list -g <package-name>, and PATH, and make sure the executable directory is in the environment variables. In Windows, $env:PATH applies only to the current session; a permanent change requires writing to the user environment variables.
Q: Switching models has no effect.
Check whether the CLI is reading an old environment variable, whether the proxy was restarted, whether the --model alias matches the proxy configuration, and confirm that the CLI’s actual request address points at the proxy.
Q: What if the proxy port is already in use?
Linux / macOS:
lsof -i :4000
Windows:
netstat -ano | findstr :4000
You can change the port and update the CLI’s base_url to match.
Q: How do I handle a key leak?
Revoke the leaked key immediately, update the proxy configuration, and check Git history, CI logs, and local caches to stop further plaintext key commits.
Q: Can this be used on an internal or offline network?
It can be attempted, but prepare in advance: an internal npm mirror or offline packages, an offline Node.js installer, the internal address of the model service, and proxy binaries or a Python package cache. Do not assume everything can be downloaded from the public internet.
Q: Can the team standardize the configuration?
Yes. Write the proxy configuration template, environment variable conventions, key injection method, Node.js version requirement, install commands, and acceptance procedure into internal team documentation, and prefer a controlled proxy with audit logging.
10. Summary
The value of command-line AI coding tools is not just “calling a model from the terminal,” but bringing AI capability into an engineering workflow that can be automated, audited, and switched. During installation, resolve Node.js version, user-level global directory, PATH, and permission issues first. During integration, use a local or internal proxy to manage model aliases, keys, logs, and fallback policies in one place. During use, validate the proxy chain with a minimal request, and close the loop with doctor, debug logs, and proxy logs.
Following the checklist and the LiteLLM example in this article, you can build a command-line AI coding workflow that is verifiable, switchable, and cost-aware. In practice, still treat the target tool’s official documentation as the authority, and re-verify runtime versions, model aliases, variable names, and proxy endpoints as they change.
