Building a Local AI Coding Assistant with Node.js: A Practical Guide
A hands-on guide to setting up a local AI coding assistant with Node.js, covering tool selection, installation, API key configuration, MCP plugin setup, and a practical troubleshooting checklist.
1. Choosing a Tool and Prerequisites
Local AI coding assistants generally fall into two categories. The first is terminal- or editor-based coding agents such as Claude Code, Gemini CLI, and OpenAI Codex CLI. These tools are distributed as npm packages and run on Node.js, with no persistent web port. The second is web-style chat interfaces such as Open WebUI, which is Python-based, typically deployed with pip or Docker, and listens on port 8080 by default. Because these two types run on different runtimes, you cannot assume every tool is Node.js-based.
This guide uses Claude Code as the example. It requires Node.js 18 or later. For deployment, use a maintained LTS version such as Node.js 22 or 24; refer to the release page on nodejs.org for the exact support schedule.
Prerequisites:
- Operating system: macOS, Linux, or Windows 10/11. Windows users can use PowerShell directly or run inside WSL2—either works.
- Network: access to your chosen model provider’s API endpoint.
- Permissions: write access to the npm global directory when installing packages globally.
Before installing, verify your runtime by running:
node -vnpm -v
If you see version numbers like v22.x.x and 10.x.x, your runtime is ready. If you get “command not found,” manage versions with nvm. After installing nvm on macOS or Linux, run:
nvm install 22nvm use 22nvm alias default 22
The last command sets 22 as the default for new terminals, so you don’t have to switch versions every time you open one.
2. Installation and Startup
To install Claude Code globally:
npm install -g @anthropic-ai/claude-codeclaude --version
If the second command prints a version number, the command is on your PATH. Then run claude doctor, which checks the installation path, runtime version, and configuration files.
Navigate to your project directory and start:
cd ~/projects/your-repoclaude
On first launch, the tool will ask you to complete authentication. Once authenticated, the assistant works within the current directory and treats that directory as its context. Claude Code runs in the terminal and doesn’t occupy a network port, so there are no port conflicts to worry about.
If you prefer a web interface, install Open WebUI:
pip install open-webuiopen-webui serve --port 8080
After it starts, visit http://localhost:8080. If port 8080 is taken, switch to another port, such as --port 8090.
3. API Keys and Security Configuration
Claude Code reads its API key from the ANTHROPIC_API_KEY environment variable. Variable names differ across tools—Gemini CLI uses GEMINI_API_KEY, and OpenAI-related tools use OPENAI_API_KEY. Check the official documentation for the tool you’re using.
On macOS or Linux, add the variable to your shell configuration file, such as ~/.zshrc or ~/.bashrc:
export ANTHROPIC_API_KEY="your-key"
Then run source ~/.zshrc to apply it, and open a new terminal. On Windows PowerShell, use the following command to set a user-level environment variable, then reopen the terminal:
setx ANTHROPIC_API_KEY "your-key"
To verify the configuration without echoing the full key:
echo $ANTHROPIC_API_KEY | head -c 8
This prints the first 8 characters. Then run one non-interactive call:
claude -p "Reply with pong only"
If it returns “pong,” both your key and the network path are working.
A few security ground rules. First, never put API keys in project code or commit them to a repository. Second, keep project-level personal configuration in .claude/settings.local.json and add that file to .gitignore. Third, if your provider supports spending limits or scope restrictions for keys, configure them according to your usage. Fourth, when team members change or a key may have been leaked, revoke it in the console immediately and generate a new one.
4. Adding Plugins and Verifying
Claude Code integrates external capabilities through MCP (Model Context Protocol). An MCP server is essentially a plugin that provides features such as file access, database queries, or browser control. The following example adds the official filesystem server, restricted to a specific directory:
claude mcp add filesystem -- npx -y @modelcontextprotocol/server-filesystem /home/you/projects/your-repoclaude mcp list
claude mcp list shows the loading status of each server. If a server shows an abnormal status, remove it with claude mcp remove filesystem and add it again.
After setup, verify with three steps:
- File reference: type
@README.md Summarize this project in three sentencesin the session, and confirm the assistant actually read the file rather than answering from memory. - Terminal execution: ask the assistant to run
npm testand watch whether it prompts for permission first. Keep the confirmation prompt—do not enable skip-confirmation mode in a real repository. - Image input: screenshot an error screen and hand it to the assistant. Whether image recognition works depends on the tool version and whether the selected model supports vision, so test it with an actual screenshot rather than assuming it works.
If any step fails, go back to claude mcp list to check the status, then verify the command path and directory permissions. Don’t loosen permission boundaries just to pass a check.
5. Troubleshooting Checklist
Work through these items in order, and most issues can be pinpointed within a few minutes.
node: command not found: check whether nvm is loaded; runnvm use 22or reopen the terminal.claude: command not found: runnpm config get prefixand confirm that thebindirectory of the output path is on your PATH.EACCESpermission errors during install: don’t usesudo npm install -gdirectly. Instead, switch to a user-level global directory—for example, runnpm config set prefix ~/.npm-global, then add~/.npm-global/binto your PATH.- Authentication failure or 401 errors: use the
head -c 8command above to confirm the environment variable exists, then check whether the key has expired or its quota is exhausted. - Request timeouts: run
env | grep -i proxyto check whether proxy variables are interfering with API access. - Open WebUI port conflict: on macOS and Linux, run
lsof -i :8080; on Windows, runnetstat -ano | findstr :8080, thentasklist | findstr <PID>to identify the process. Confirm the process is safe to stop before acting—don’t terminate unknown processes at will. - MCP server not loaded: run
claude mcp listto check the status, then run the corresponding npx command manually to see the error output.
Before going live, check off the following: the runtime version meets requirements, claude --version works, the API key is read from an environment variable and not committed to the repository, MCP servers are healthy, and all three verifications—file reference, terminal execution, and image input—have passed.
