Local Terminal AI Coding Assistant Deployment: Installation and Troubleshooting Guide
This guide explains how to deploy a terminal-based AI coding assistant locally, using Claude Code as an example. It covers prerequisites, Node.js and Git installation, global npm installation, common installation errors and fixes, scripted installation as a fallback, first login and project validation, permission and ignore rules, and a final deployment checklist.
1. Intended Audience and Prerequisites
This article is intended for developers who want to use an AI coding assistant in a local terminal. It uses Claude Code as an example; its npm package name is @anthropic-ai/claude-code. The installation process for other similar terminal tools is generally the same, with only the package name and configuration paths changed.
Before deployment, confirm the following requirements:
- Operating system: macOS, a mainstream Linux distribution (Ubuntu, Debian, Fedora, etc.), or Windows 10 or later.
- Node.js: 20.x LTS or later.
- Git: 2.x or later. Windows users also need Git Bash, which comes with Git for Windows.
- Network: access to the model service domain, and the ability to complete login authorization in a browser.
- A real project directory for verifying whether the tool can read project context. A repository already managed by Git is preferred.
2. Step 1: Check and Install Node.js and Git
First, check the current versions:
node -vnpm -vgit --version
If the major version reported by node -v is lower than 20, upgrade Node.js. The installation commands below are organized by operating system.
On macOS and Linux, using nvm to manage multiple Node.js versions is recommended so that other system tools are not affected:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bashsource ~/.bashrc # zsh users should run source ~/.zshrc insteadnvm install 20nvm use 20
On Windows, you can install with winget:
winget install OpenJS.NodeJS.LTSwinget install Git.Git
When installing Git for Windows, the default options are sufficient. After installation, close and reopen the terminal so that the PATH changes take effect. Claude Code relies on Git Bash on Windows, and the installer detects it automatically.
3. Step 2: Install the AI Coding Assistant Globally
Run the global installation command:
npm install -g @anthropic-ai/claude-codeclaude --version
After a global installation, the command can be invoked from any directory. If claude --version outputs a version number, the executable is already on the PATH.
3.1 Common Errors and Fixes
Most installation errors fall into the categories in the table below:
| Error message | Common cause | Fix |
|---|---|---|
EACCES: permission denied |
The npm global directory is owned by root, and the current user does not have write permission | Change the npm global directory to a user directory: mkdir -p ~/.npm-global && npm config set prefix '~/.npm-global', then add export PATH=$HOME/.npm-global/bin:$PATH to ~/.bashrc or ~/.zshrc |
ETIMEDOUT, ECONNRESET |
Unstable network or incorrect proxy configuration | Run npm config get registry to check the registry; if a proxy is required, run npm config set proxy http://127.0.0.1:7890, using the port required by your proxy software |
claude: command not found |
The global bin directory is not on the PATH | Run npm config get prefix, add the bin directory under the output path to the PATH, then reopen the terminal |
| Installation succeeds but an old version runs | An old package remains on the system | First run npm uninstall -g @anthropic-ai/claude-code, then reinstall |
engine "node" is incompatible |
The Node.js version is too old | Upgrade to Node.js 20 LTS as described in Section 2 |
Using sudo npm install -g directly is not recommended. Files installed as root can cause permission conflicts during later upgrades and uninstalls. Consider sudo only when there is no other option, and prefer changing the npm prefix first.
4. Step 3: Scripted Installation (Fallback)
If npm installation fails repeatedly, you can use the official installation script instead. The process below includes a few more checks than simply executing a remote script, making it suitable for environments with security requirements. Use the script URL provided in the official documentation.
Download the script locally instead of piping it directly into a shell:
curl -fsSL -o install.sh "<script URL from the official documentation>"
Read the script and check specifically for
rm -rfoperations against system directories, writes to/etc, or modifications to system files other than shell configuration:less install.sh
Calculate the hash and compare it with the value published on the official page. On macOS, use
shasum -a 256 install.sh; on Linux, usesha256sum install.sh. If the hashes do not match, stop immediately and do not execute the script.After confirming that everything is correct, run:
bash install.sh
This process also applies to WSL environments. After the script installation finishes, you still need to run claude --version to confirm the installation result.
5. Step 4: First Login and Project Validation
After installation, validate the setup in the following order:
- Run
claudein any directory and follow the prompts to complete login authorization in a browser. When the terminal shows a ready prompt, authorization has succeeded. - Go to the root directory of the project you want to test, for example
cd ~/projects/demo-app. Do not start the tool in your home directory; otherwise, it will read the contents of the home directory. - Ask a question that tests context, such as “Where is the entry file for this project?” If the answer accurately references the
mainorscriptsfield inpackage.json, the tool has read the project files. - Check the configuration file locations. User-level configuration is located at
~/.claude/settings.json, and project-level configuration is located at.claude/settings.jsonin the project root. Project-level configuration applies only to the current repository.
If validation fails, check the following items in order:
- Still unauthorized after login: confirm that the authorization page in the browser has been completed. If a proxy blocks the authentication domain, allow the relevant domain in the proxy rules and run
claudeagain. - Answers are unrelated to the project: use
pwdto confirm that the current directory is the project root. - The tool does not respond: first run
claude --versionto confirm that the program itself works, then check the network and proxy settings.
6. Configuring Ignore Rules and Permissions
An AI coding assistant can read local files. For sensitive content such as keys, certificates, and environment variables, you need two layers of restriction.
The first layer is the tool’s permission rules. Create .claude/settings.json in the project root and add the following:
{"permissions": {"deny": ["Read(./.env)","Read(./.env.*)","Read(./secrets/**)"]}}
The second layer is Git ignore rules. Add the following to .gitignore:
.env.env.*secrets/*.pem*.key
These two layers serve different purposes. .gitignore only prevents sensitive files from being committed to the repository; it does not prevent local tools from reading them. Therefore, it must be used together with deny rules.
In addition, before letting the tool modify code in bulk, switch to a separate branch and commit the current state:
git statusgit switch -c ai-experimentgit add -A && git commit -m "baseline before AI edits"
This way, every change can be reviewed with git diff and reverted with git restore or by switching back to the original branch, without losing existing work.
7. Deployment Checklist
After deployment, confirm each item:
-
node -vshows v20 or later -
npm -voutputs normally -
git --versionoutputs normally -
claude --versionoutputs a version number - Browser login authorization has been completed
- Asking a question in the project root returns an answer consistent with the project files
-
denyrules have been configured in.claude/settings.json - Sensitive files have been added to
.gitignore - Work is on a separate branch, and a baseline commit exists before any modifications
8. Conclusion
The deployment process can be summarized in four steps: install Node.js and Git, install the tool globally, complete login and validate it in a real project, and finally configure permissions and version control protection. Errors are common during installation. When a problem occurs, save the complete error message first, then check it against the troubleshooting table above. After completing these steps, the tool can reliably read code and execute commands in the project, and every change can be traced.
