# 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 --help or the official documentation.
    • <version>: the stable version required by the tool; you can use latest or 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:

    1. node -v
    2. npm -v

    If the output looks like:

    1. v18.19.0
    2. 9.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:

    1. curl -fsSL -o nvm-install.sh https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh
    2. # Open nvm-install.sh and confirm the source and contents before running it
    3. bash nvm-install.sh
    4. source ~/.bashrc
    5. # or source ~/.zshrc

    Install and switch Node.js:

    1. nvm install 22
    2. nvm use 22
    3. node -v
    4. npm -v
    5. npm 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:

    1. nvm install 22
    2. nvm use 22
    3. node -v
    4. npm -v

    If your team uses an internal mirror, check the current registry:

    1. 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 .npmrc in 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:

    1. mkdir -p ~/.local/global
    2. npm config set prefix ~/.local/global
    3. export PATH="$HOME/.local/global/bin:$PATH"

    To make this effective in new terminals, add it to your shell configuration:

    1. echo 'export PATH="$HOME/.local/global/bin:$PATH"' >> ~/.bashrc
    2. source ~/.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

    1. npm install -g <package-name>@<version>

    If you always want the latest stable version:

    1. 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:

    1. <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:

    1. Run npm list -g <package-name> to confirm the package installed.
    2. Run npm prefix -g to find the global executable directory.
    3. Check whether that directory is in PATH.
    4. Close and reopen the terminal, or manually run source ~/.bashrc or source ~/.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:

    1. npm install -g <package-name>@<version>
    2. <command> --version

    If you get “command not found,” check in this order:

    1. Get-Command <command>
    2. npm prefix -g
    3. $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:

    1. <command> --version

    4.3 npx or Docker Alternatives

    Some tools support a no-install trial run:

    1. npx <package-name>@<version> --version

    If the tool publishes an official Docker image, you can also run it in a container:

    1. 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:

    1. whoami
    2. ls -ld ~/.local/global

    If the directory was mistakenly handed to a system user, return it to the current user:

    1. 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

    1. <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:

    1. <command> doctor
    2. <command> config list
    3. <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_url points 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:

    1. mkdir ~/ai-cli-sandbox
    2. cd ~/ai-cli-sandbox
    3. <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:

    1. Confirm that the base_url shown by <command> doctor points at the proxy address.
    2. Send one request with a specific model, for example --model fast-coder.
    3. Check the proxy logs to confirm the request actually went through the proxy and that the model alias was recorded.
    4. 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:

    1. A single model may be rate-limited, may raise prices, or may be unstable.
    2. Different tasks need different capabilities: completion needs low latency, complex refactoring needs strong reasoning.
    3. API keys written directly into the tool’s configuration leak easily.
    4. 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:

    1. Terminal / CI script
    2. ↓
    3. Command-line AI coding tool CLI
    4. ↓
    5. Model proxy http://127.0.0.1:4000
    6. ├→ Model service A
    7. ├→ Model service B
    8. └→ 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:

    1. python3 -m venv .venv
    2. source .venv/bin/activate
    3. pip install --upgrade pip
    4. pip install "litellm[proxy]"

    Before starting, confirm the command is available:

    1. 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:

    1. model_list:
    2. - model_name: fast-coder
    3. litellm_params:
    4. model: openai/<upstream-model-A>
    5. api_base: os.environ/UPSTREAM_A_BASE
    6. api_key: os.environ/UPSTREAM_A_KEY
    7. - model_name: deep-reasoner
    8. litellm_params:
    9. model: anthropic/<upstream-model-B>
    10. api_base: os.environ/UPSTREAM_B_BASE
    11. api_key: os.environ/UPSTREAM_B_KEY
    12. general_settings:
    13. master_key: os.environ/LITELLM_MASTER_KEY

    Notes:

    • fast-coder is an alias at the proxy layer, suited to low-latency work such as lightweight completion, script generation, and comment generation.
    • deep-reasoner is 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:

    1. export UPSTREAM_A_BASE="https://api.example-a.com/v1"
    2. export UPSTREAM_A_KEY="replace-with-real-key-a"
    3. export UPSTREAM_B_BASE="https://api.example-b.com"
    4. export UPSTREAM_B_KEY="replace-with-real-key-b"
    5. export LITELLM_MASTER_KEY="local-proxy-token"

    Start the proxy:

    1. litellm --config litellm_config.yaml --port 4000

    Liveness check:

    1. 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:

    1. 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:

    1. export AI_BASE_URL="http://127.0.0.1:4000/v1"
    2. export AI_API_KEY="local-proxy-token"

    Common variants may include:

    1. export OPENAI_BASE_URL="http://127.0.0.1:4000/v1"
    2. export OPENAI_API_KEY="local-proxy-token"

    or, for some Anthropic-compatible tools:

    1. export ANTHROPIC_BASE_URL="http://127.0.0.1:4000"
    2. 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:

    1. <command> doctor
    2. <command> config list
    3. <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:

    1. <command> --model fast-coder
    2. <command> --model deep-reasoner

    If the CLI selects the model through an environment variable, set it as the official documentation describes. Illustratively:

    1. 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:

    1. Explicit command-line arguments, such as --model
    2. The tool’s configuration file
    3. Environment variables
    4. 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:

    1. curl -fsS http://127.0.0.1:4000/v1/chat/completions \
    2. -H "Authorization: Bearer local-proxy-token" \
    3. -H "Content-Type: application/json" \
    4. -d '{
    5. "model": "fast-coder",
    6. "messages": [
    7. {
    8. "role": "user",
    9. "content": "ping"
    10. }
    11. ]
    12. }'

    A normal model response means the proxy, authentication, and routing basically work. If it returns an error, check first:

    • Whether the model alias 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.1 while 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:

    1. Daily budget per person: <daily budget>
    2. Monthly budget per team: <monthly budget>
    3. Per-request timeout: 30 seconds
    4. Retries after consecutive failures: 2
    5. After 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:

    1. Never commit keys to a repository. Configuration files hold placeholders only, such as ${KEY_A} and ${KEY_B}.
    2. Add sensitive files to .gitignore, such as .env, litellm_config.local.yaml, and key cache directories.
    3. The proxy should listen on the local machine by default, for example 127.0.0.1:4000, and should not bind to 0.0.0.0.
    4. 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.
    5. Local placeholder credentials exist only for communication between the CLI and the local proxy; they are not real upstream keys.
    6. Use separate keys per upstream service, and restrict call scope and model permissions.
    7. Redact logs. Avoid printing full request bodies, full keys, full source excerpts, or user private data.
    8. Enable auditing. Record call time, model alias, duration, status code, error message, and caller.
    9. 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:

    1. 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:

    1. npm install -g <package-name>@latest

    Update to a pinned version:

    1. npm install -g <package-name>@<new-version>

    Verify after upgrading:

    1. <command> --version
    2. <command> doctor

    9.2 Uninstall

    Uninstall the global install:

    1. npm uninstall -g <package-name>

    If you configured a user-level prefix, you can check:

    1. npm config get prefix
    2. ls -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:

    1. npm install -g <package-name>@<previous-version>

    Roll the Node.js version back:

    1. nvm install <previous-node-version>
    2. nvm use <previous-node-version>
    3. node -v
    4. npm 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:

    1. lsof -i :4000

    Windows:

    1. 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.