Command-Line AI Coding Assistant on Desktop: Configuration and Security Practices

    This article explains how to configure and safely operate a command-line AI coding assistant on a developer desktop. Using Claude Code with Node.js 20 LTS, npm, and Git as an example, it covers environment preparation, installation verification, API key management, first repository onboarding, common workflows for feature development, bug fixing, and test troubleshooting, plus security and compliance controls and a troubleshooting table.

    1. Audience and Scope

    This article is for developers who already write code in a local terminal and want an AI assistant to read repositories, modify files, and run tests. The command examples use Node.js 20 LTS, npm, and Git as the baseline, and use Claude Code as a specific command-line example. Other tools have different package names and environment variable names; before installation, follow that tool’s official documentation.

    Tasks suitable for the assistant include: small feature additions, repeated-code cleanup, unit test completion, error log analysis, and draft API documentation. Tasks not suitable for unattended execution include: database migrations, deleting files or directories, production environment configuration, key rotation, and changes to permission or billing logic. These tasks should be reviewed line by line by an engineer before execution.

    2. Environment Preparation

    1. Runtime

    Install Node.js 20 LTS or a newer LTS version. After installation, run the following commands in the terminal:

    1. node -v
    2. npm -v
    3. git --version

    Under normal conditions, the commands output version numbers such as v20.x.x, 10.x.x, and 2.x.x. If a command is not found, close and reopen the terminal first, then check whether the installer has written the path to the environment variables. If the version information is unclear, do not continue installing higher-level tools.

    2. Version Control

    Before entering the project, run git status to confirm that the working tree is clean. If there are uncommitted changes, commit or stash them first so that your changes do not mix with the assistant’s changes. Before each session in which the assistant will make changes, create a separate branch:

    1. git switch -c ai/feature-xxx

    3. Terminal

    The system terminal is sufficient. It needs to support copy and paste, scrollback history, and color output. Teams should standardize the default encoding to UTF-8 to reduce compatibility issues caused by non-ASCII paths and line endings.

    4. Network

    If the corporate network uses a proxy or certificate validation, first confirm that the npm registry is reachable. Run npm config get registry to view the current registry. If the organization provides an internal mirror, set it with npm config set registry <address provided by your organization>. Do not bypass network issues by disabling TLS certificate validation.

    3. Installation and Verification

    A global installation example is shown below. The command is the same in Windows PowerShell and in macOS or Linux terminals:

    1. npm install -g @anthropic-ai/claude-code
    2. claude --version

    After installation, perform three checks:

    1. The version number matches the official release page.
    2. Run npm view @anthropic-ai/claude-code version to confirm the latest version on the registry, and compare it with your installed version.
    3. Record the installation source, version number, and installation date in team documentation for auditing and reproducibility.

    If global installation reports insufficient permissions (EACCES), prefer a user-level prefix instead of administrator privileges:

    1. npm config set prefix "$HOME/.npm-global"

    Then add $HOME/.npm-global/bin to PATH. On Windows, the default global directory is %APPDATA%\npm, which is usually already in the user PATH. If the command is reported as not found, first check whether that directory is in the user PATH.

    To upgrade or roll back, pin the version:

    1. npm install -g @anthropic-ai/claude-code@<version>

    4. Key Management

    The API key used by the assistant must not be written into the repository. In Claude Code, for example, it reads ANTHROPIC_API_KEY as the key. If the organization uses a unified gateway, it also reads ANTHROPIC_BASE_URL.

    On macOS or Linux, write the two configuration lines into a separate file ~/.config/ai-assistant/env, restrict the file permissions, and then load it from your shell configuration:

    1. export ANTHROPIC_API_KEY="<token from your secret management system>"
    2. export ANTHROPIC_BASE_URL="<gateway address provided by your organization>"
    1. chmod 600 ~/.config/ai-assistant/env

    Add source ~/.config/ai-assistant/env to ~/.zshrc or ~/.bashrc.

    On Windows, you can use setx to write user-level environment variables. The settings take effect only after you reopen the terminal:

    1. setx ANTHROPIC_API_KEY "<token from your secret management system>"

    setx stores values in plaintext in the registry. If the organization has a credential manager or secret service, prefer using it to inject the variables.

    Basic rules:

    • Do not commit keys to version control. Add .env, *.key, and similar files to .gitignore.
    • Do not expose full tokens in screenshots, logs, or meeting recordings.
    • Assign keys per person, rotate them regularly, and revoke them immediately when someone leaves or changes roles.
    • If a token is accidentally entered as a command argument, immediately rotate it in the secret system and delete the corresponding line from the shell history file.

    5. Initial Project Onboarding

    When entering the repository for the first time, only observe; do not change code. Start the assistant at the project root and use a prompt similar to:

    Read this repository’s directory structure, build scripts, test entry points, and coding conventions. Do not modify any files in this session. Output: 1. the build command; 2. the test command; 3. the main modules and their responsibilities; 4. questions you believe I need to confirm.

    Onboarding checklist:

    • The build and test commands provided by the assistant match the README. If they are inconsistent, the CI configuration prevails.
    • The assistant’s modification plan includes a list of affected files, and execution starts only after you confirm it.
    • After each change, run git diff --stat to confirm that changes appear only in the agreed directories.
    • After changes, run the relevant tests, rather than stopping after a single test case.

    6. Common Workflow Templates

    1. Feature Development

    Organize the prompt using the following structure:

    • Background: relevant module paths, plus similar implementations and test files for reference.
    • Goal: the behavior to add, described in one sentence.
    • Constraints: do not modify public interfaces, do not add dependencies, and follow existing naming and directory conventions.
    • Acceptance: the specified test command passes, and new test cases cover at least one normal path and one exception path.
    • Prohibited changes: migration scripts, CI configuration, and secret-related files.

    Acceptance criteria: the diff appears only in the agreed directories; tests pass; you have read the new code line by line.

    2. Bug Fixing

    First provide the error stack and reproduction steps, and ask the assistant to locate the problem first rather than modify directly. The prompt can be written as:

    Below are the error stack and reproduction command. Please output in four parts: problem localization, affected files, modification plan, and verification method. After I confirm, modify the code.

    Acceptance criteria: the reproduction command no longer fails; there is a comparison of test results before and after the fix; use git log -5 -- <file> to check whether recent changes are related to the bug.

    3. Troubleshooting Test Failures

    Ask the assistant to first distinguish environment issues from code issues and list three categories of possible causes: dependency versions, environment variables, and code logic. Each category must include a verification command. For example, reinstall dependencies first:

    1. npm ci

    Then run the tests again. If they still fail, proceed to code investigation.

    Acceptance criteria: the failure cause is supported by logs or reproduction steps; after the fix, all related tests pass.

    7. Security and Compliance

    • Do not write customer information, internal addresses, keys, or undisclosed algorithm parameters into prompts.
    • Run high-risk repositories in an isolated working directory or container, and restrict network egress.
    • Before adding dependencies, check licenses and maintenance status, commit the lockfile, and pin versions.
    • Before merging, the change must pass diff review, tests, and static checks.
    • Store and retain session records according to organizational rules, and do not post full session screenshots to public channels.

    8. Troubleshooting Common Issues

    Symptom Possible cause Verification command Action
    Command not found The global directory is not in PATH, or the terminal was not reopened npm prefix -g, echo $PATH Add the global directory to PATH and reopen the terminal
    Permission denied (EACCES) The global directory requires administrator privileges npm config get prefix Switch to a user-level prefix
    Authentication failure (401) Expired token, or gateway address issue N/A N/A