Terminal AI Coding Tools: Installation and Multi-Model Switching Guide
This guide is designed for engineers developing in the command line. It covers the installation of terminal AI coding assistants like Claude Code, setting up the base environment across macOS, Linux, and Windows, and using LiteLLM to build a unified local gateway for seamlessly switching between different LLMs based on specific task needs.
1. Scope and Prerequisites
This article is intended for engineers who already develop in the command line. The commands provided are applicable to mainstream environments including macOS, Linux, and Windows. Since AI coding tools update rapidly, please refer to the official documentation of each tool for specific version requirements.
A single model rarely performs best across all tasks. Some models excel at large-scale refactoring, while others are more stable at generating documentation comments or understanding specific languages. Therefore, a more practical approach is to maintain a unified entry point and switch the underlying model based on the task, rather than configuring a separate set of tools for each model.
This article assumes that readers already have API accounts with model providers and can access the corresponding API endpoints.
2. Preparing the Base Environment
Three types of base components need to be installed: Node.js (including npm) for installing Claude Code; Python for installing LiteLLM (and Aider, if used); and Git for version control.
Windows users can install these using winget by opening PowerShell as an administrator:
winget install OpenJS.NodeJSwinget install Git.Gitwinget install Python.Python.3.12
macOS users can use Homebrew:
brew install node git python
After installation, verify the versions one by one:
node --versionnpm --versiongit --versionpython3 --version
If you receive a “command not found” error, close and reopen your terminal first. If it still doesn’t work on Windows, check whether the corresponding installation directories are included in the system’s PATH environment variable.
Claude Code officially requires Node.js 18 or higher. It is recommended to choose the currently maintained LTS version.
When installing global npm packages, it is not recommended to use sudo on macOS or Linux. A safer approach is to use nvm or fnm to manage Node.js, allowing global packages to be installed in the current user’s directory. sudo is not required in Windows PowerShell.
3. Installing the Terminal Coding Assistant
This article uses Claude Code provided by Anthropic as an example. It is published as an npm package named @anthropic-ai/claude-code.
npm install -g @anthropic-ai/claude-codeclaude --version
If the version number outputs correctly, the installation was successful. Next, navigate to the root directory of your code repository to launch it:
cd your-projectclaude
Upon first launch, the tool will prompt you to log in or set up authentication information. Claude Code reads and modifies files in the current directory and usually requests confirmation before executing commands. Therefore, it is recommended to start it only in the project directories where it is needed, rather than running it in parent directories containing a large number of sensitive files.
If you prefer to use an OpenAI-compatible interface, you can also consider Aider. It is installed via pip install aider-chat and also supports custom models and API endpoints.
4. Unifying Multi-Model Access with LiteLLM
Directly modifying environment variables to switch providers is error-prone and difficult to audit. A more stable approach is to run a gateway locally. LiteLLM is an open-source project that unifies the APIs of multiple model providers into a single format.
Install the LiteLLM proxy component:
python3 -m pip install 'litellm[proxy]'
In Windows PowerShell, this should be written as python -m pip install "litellm[proxy]".
Create a config.yaml file in a dedicated directory and assign a local name to each model. Replace the model names in the example with the models currently supported by your providers:
model_list:- model_name: main-modellitellm_params:model: openai/your-main-model-nameapi_key: os.environ/OPENAI_API_KEY- model_name: backup-modellitellm_params:model: anthropic/your-backup-model-nameapi_key: os.environ/ANTHROPIC_API_KEY
The configuration file only references environment variable names and does not write keys in plaintext. When starting the gateway, restrict it to listen only on the local address:
litellm --config config.yaml --host 127.0.0.1 --port 4000
Once the gateway is running, point Claude Code to it. Here is the syntax for macOS or Linux:
export ANTHROPIC_BASE_URL="http://127.0.0.1:4000"export ANTHROPIC_AUTH_TOKEN="$LITELLM_MASTER_KEY"export ANTHROPIC_MODEL="main-model"claude
For Windows PowerShell, you can set the environment variables as follows:
$env:ANTHROPIC_BASE_URL="http://127.0.0.1:4000"$env:ANTHROPIC_AUTH_TOKEN="$env:LITELLM_MASTER_KEY"$env:ANTHROPIC_MODEL="main-model"claude
