Sub topic 4
Installing and signing in
This chapter covers getting Claude Code, Codex CLI, and Copilot CLI onto your machine and authenticated. It assumes you are comfortable in a shell, have Node.js and npm installed, and can read environment variables. Version numbers and menu wording change often, so treat the commands below as the stable shape and check each tool's README for current details.
What installation gives you
Each tool is a command-line program distributed as an npm package. Installing it puts one executable on your PATH. Running that executable inside a project directory starts a session whose working directory is the project root. The agent can only see and edit what is under that directory, plus anything your permissions allow.
| Tool | npm package | Command |
|---|---|---|
| Claude Code | `@anthropic-ai/claude-code` | `claude` |
| Codex CLI | `@openai/codex` | `codex` |
| Copilot CLI | `@github/copilot` | `copilot` |
Installing with npm
Install each package globally with -g, then verify that the command resolves.
npm install -g @anthropic-ai/claude-code
npm install -g @openai/codex
npm install -g @github/copilot
claude --version
codex --version
copilot --versionIf a --version command prints "command not found", the install succeeded but your shell cannot find the binary. Run npm prefix -g and make sure its bin directory is on PATH.
Node.js version
These tools require a minimum Node.js version, and the minimum differs between them and between releases. Run node --version first. An old Node produces syntax errors or an install failure that looks unrelated to the tool. If your system Node is old, use a version manager such as nvm rather than upgrading the system package.
Permission errors on global installs
The most common install failure is EACCES when npm tries to write to a system directory. Do not fix this with sudo npm install -g. A root-owned global install makes later updates fail and runs package install scripts with full privileges. Instead, point npm at a directory you own:
mkdir -p "$HOME/.npm-global"
npm config set prefix "$HOME/.npm-global"
echo 'export PATH="$HOME/.npm-global/bin:$PATH"' >> ~/.bashrc
source ~/.bashrcUse ~/.zshrc instead if your shell is zsh. A Node version manager avoids this problem entirely, because it installs Node under your home directory.
Updating
Re-run the same npm install -g <package> command to move to the latest release. Some tools also check for updates on startup and tell you when one is available. Because these tools change quickly, updating is often the first thing to try when a documented feature is missing from your copy.
Starting a session
Change into the project first. Then start the tool.
cd my-project
claude # start Claude Code
codex # start Codex CLI
copilot # start Copilot CLIOn first launch, each tool detects that you are not authenticated and walks you through signing in. Copilot CLI may also ask whether you trust the current folder before it reads or changes files there. Answer that prompt carefully. Trusting a folder is a permission decision, covered in the permissions chapter.
Two kinds of credentials
Every tool supports a subset of two authentication styles.
- Account sign-in uses a browser-based login tied to a subscription. The tool stores a token on your machine, and usage counts against your plan's limits.
- API key or token is a secret read from an environment variable or config. Usage is billed per request, or against the account that owns the token.
| Tool | Account sign-in | Key or token |
|---|---|---|
| Claude Code | Claude subscription, or an Anthropic Console account | `ANTHROPIC_API_KEY` |
| Codex CLI | ChatGPT account | `OPENAI_API_KEY` |
| Copilot CLI | GitHub account with a Copilot plan | A GitHub token such as `GH_TOKEN` or `GITHUB_TOKEN` |
For Copilot CLI, a token must be one that is allowed to make Copilot requests. A fine-grained personal access token needs the Copilot permission, and a classic repo-scoped token is not a substitute. Check the current Copilot CLI documentation for the exact permission name.
The exact precedence between an environment variable and a stored login differs by tool and version. If you have both, and billing or limits look wrong, check which one the tool reports as active. The tools usually show this in their status output or on the startup banner.
Signing in explicitly
You do not have to wait for the first-launch prompt.
- Codex CLI has a login subcommand:
codex login. - Claude Code and Copilot CLI start sign-in from inside a session with a slash command, such as
/login. Slash commands are covered in a later chapter.
For a key-based setup, export the variable in the shell where you start the tool:
export ANTHROPIC_API_KEY="your-key-here"
claudeNever paste a real key into a file that is committed to git, a shared shell history, or a screenshot. Load it from a secrets manager or an untracked file instead.
Where credentials live
Account sign-in stores a token in a per-user location, either the operating system keychain or a file under a dot-directory in your home folder, such as ~/.codex/ for Codex CLI. Three consequences follow:
- Credentials are per user, not per project. Signing in once covers every repository.
- On a shared machine, anyone who can read your home directory may be able to use your login. Check file permissions.
- In a container or CI job, a browser login is usually impossible. Use a key or token supplied through the environment instead.
Common problems
- Browser does not open on a remote server. Look for a URL or device code printed in the terminal, open it on your own machine, and complete the login there. If neither is offered, use a key or token.
- Login succeeds but requests fail with a plan or quota error. The account may lack access, for example no Copilot seat from your organization, or an API account without billing set up.
- Wrong account. Signing in with a personal account when your work uses an organization account is common. Log out through the tool, then sign in again with the right identity.
- Corporate proxy or TLS inspection. Standard variables such as
HTTPS_PROXYare generally honored. Certificate errors need your company's CA configured for Node. - Stale environment variable overriding a login. An old
ANTHROPIC_API_KEYorOPENAI_API_KEYleft in your shell profile can silently take priority. Runenv | grep -i -E 'API_KEY|TOKEN'to find leftovers.
Exercise
You installed Codex CLI with npm install -g @openai/codex and got EACCES: permission denied on a system directory. What is the recommended fix, and why not use sudo?
Show answer
Set npm's global prefix to a directory you own, for example npm config set prefix "$HOME/.npm-global", and add its bin folder to PATH. Or use a Node version manager. Using sudo creates root-owned files that break later updates, and it runs package install scripts with full privileges.
Exercise
A teammate runs Copilot CLI inside a CI container, where no browser is available. Which authentication style should they use, and how is it supplied?
Show answer
Use a token rather than an interactive account login. They create a GitHub token that is allowed to make Copilot requests, store it as a CI secret, and expose it to the job as an environment variable such as GH_TOKEN.