CLI AI Coding Assistant Setup: From Environment Preparation to Connection Verification
This guide explains how to get started with an agentic AI coding assistant in the terminal. It covers checking Node.js and Git, installing the tool from official documentation, configuring model access with environment variables, verifying the connection with a read-only task, troubleshooting common errors, and reviewing cost and security boundaries.
Agentic AI coding tools run in the terminal. They can read and write files in directories you authorize, execute commands, and decide what to do next based on command output. They can save a great deal of repetitive work, but they also have permission to modify local files, so you need to confirm the result of every step.
Follow the five sections below in order. After completing each section, run the corresponding check command and confirm the result before moving on.
1. Environment Setup
Open your system terminal first. On macOS, you can use the Terminal app. On Windows, you can use PowerShell. On Linux, you can use the built-in Bash or Zsh.
These tools depend on two basic pieces of software: Node.js and Git.
Check whether Node.js is installed:
node -vnpm -v
If both commands output version numbers, Node.js is installed. Use the current LTS release. If you see “command not found,” download the LTS installer from the official Node.js website. After installation, close and reopen the terminal, then run the commands again.
Check whether Git is installed:
git --version
An output similar to git version 2.x.x is sufficient. If Git is not installed, download the installer for your operating system from the official Git website.
You also need to confirm terminal permissions. On macOS, if the tool needs access to the Documents or Desktop directory, the system may show an authorization prompt. Allow access as needed. On Windows, do not run the tool as administrator unless the installation documentation explicitly requires it.
2. Tool Installation
Use the installation command provided in the tool’s official documentation. Package names and installation methods vary between tools, so copy the command directly from the official page. Do not copy unknown scripts from search results or unfamiliar forums.
Most tools are installed through a package manager, usually in a form like this:
npm install -g <package-name>
Replace <package-name> with the name given in the official documentation. After installation, run:
<tool-command> --version
If a version number is returned, the installation succeeded. If the command is not found, the global installation directory is usually not included in the system PATH. Reopening the terminal often solves the problem. If it still does not work, run npm config get prefix to find the global installation directory, then add its bin subdirectory to PATH.
Before the first run, create a practice directory instead of trying the tool directly in a folder containing important files:
mkdir ai-democd ai-demo
3. Model Connection
The tool itself does not include a model. It needs to connect to a model service. Model providers usually supply three key pieces of information:
- Base URL: the address to which the tool sends requests, provided by the provider’s documentation, usually in a format like
https://api.example.com/v1. This is only a placeholder example. - Model name: the model specified in the request. The name must exactly match the spelling in the console or documentation, including capitalization and any version suffix.
- API key: your credential, which functions like a key to your account.
An API key should not be written into code or configuration files and then committed to a repository. Pass it through environment variables instead. The variable names below are examples only; use the actual names specified in the tool documentation.
Set the variables in the current terminal on macOS or Linux:
export MODEL_API_KEY="your_API_KEY"export MODEL_BASE_URL="provider_base_URL"export MODEL_NAME="model_name_from_console"
Set the variable in the current PowerShell session on Windows:
$env:MODEL_API_KEY="your_API_KEY"
To make the settings persist, on macOS or Linux you can add the export lines to your shell configuration file, such as ~/.zshrc. On Windows, you can add them through System Environment Variables. Reopen the terminal after making changes. Keys entered directly on the command line may be written to shell history, so a safer approach is to write them into a configuration file and ensure that only you can read that file.
If your project uses a .env file for configuration, add .env to .gitignore so it is not committed to the Git repository.
4. Connection Verification
After configuration, start with a small read-only task to confirm that the tool can connect to the model and will not modify files. For example, in the practice directory, enter: “List the files in the current directory and describe each file’s type in one sentence.”
If the tool returns a normal result, the model connection is working. If an error occurs, troubleshoot in the following directions.
- 401 Unauthorized: the API key is incorrect, expired, or disabled. Check whether you copied extra spaces and confirm that the current terminal has loaded the environment variables. On macOS or Linux, you can run
[ -n "$MODEL_API_KEY" ] && echo set. In PowerShell, you can runif ($env:MODEL_API_KEY) { "set" }. These commands only check whether the variable exists and do not print the key itself. - 403 Forbidden: the account does not have permission to use the model, the current plan does not include the model, or regional or network policy restrictions apply. Check the activation status in the console.
- 404 Not Found: this is often caused by an incorrect base URL, such as a missing version path like
/v1. Compare the base URL with the provider documentation. - Incorrect model name: providers usually return 400 or 404 and indicate that the model does not exist. Compare the model name character by character with the name in the console.
- 429 Too Many Requests or quota exhausted: retry later or check usage in the console.
- Network timeout or connection failure: first open the provider’s official website in a browser to confirm that external network access works. If you use a proxy, check whether the tool’s proxy environment variables are set correctly. Corporate networks may require an administrator to allow the relevant domain.
If the problem remains unresolved, keep the key parts of the error message, remove any secrets, and then consult the provider documentation or community.
5. Cost and Security Boundaries
Review costs both before and after enabling the service to avoid unexpected charges. Use the checklist below.
- Billing method: confirm whether the service is billed per token, per request, or by a monthly subscription package. A token is the basic unit the model uses to process text. Agentic tools repeatedly read project context, so consumption is usually higher than with ordinary chat.
- Plan quota: confirm the quota period (daily, monthly, or rolling) and whether service stops or automatic charges apply after the quota is exceeded.
- Free quota: note the amount or number of uses and the expiration date. Expired quota usually does not carry over.
- Usage alerts: set usage alerts or a budget cap in the console.
- Bill review: within one or two days after the first real use, review the bill to confirm that charges match actual usage.
Pay attention to the following security points.
- Use official channels: only activate plans and APIs through the provider’s console or official documentation. Do not buy quota from unknown sources or use unknown relay services, as they may intercept your prompts or keys.
- Key storage: do not write API keys into code or commit them to Git. Do not take screenshots of real keys or paste them into chats. Use placeholders such as
sk-xxxin example documentation. - Leak handling: if you suspect a key has leaked, immediately revoke it in the console, generate a new key, and check recent usage records.
- Data boundaries: do not put passwords, private keys, customer personal information, or unpublished business data into prompts. If such data is necessary, anonymize it first.
- Team projects: before use, confirm whether your company or team allows code snippets to be sent to third-party model services and what scope is permitted.
