Mastering Claude Code CLI
Setup and Authentication
Getting Started with Claude Code
Claude Code moves your AI assistant from a separate IDE window directly into your terminal. It's a command-line interface (CLI) that gives Claude the ability to interact with your local file system, run commands, and understand the full context of your project. Let's get it set up.
Installation
Before installing, ensure you have Node.js (version 16 or higher) on your system. Claude Code works with most modern shells, including Zsh, Bash, and PowerShell.
For macOS and Linux, the recommended installation method uses a curl command to download and execute the installation script.
curl -sL https://install.claude.run | bash
This command securely fetches the latest installer script from install.claude.run and pipes it directly into your bash shell to run. The -sL flags ensure the process is silent (no progress meter) and follows any redirects.
For Windows users, it's best to use PowerShell with administrator privileges. The following command achieves the same result.
powershell -c "irm https://install.claude.run | iex"
Here, irm (Invoke-RestMethod) fetches the script, and iex (Invoke-Expression) executes it. If you use Windows Subsystem for Linux (WSL), you can follow the standard Linux installation instructions within your WSL terminal.
Once the script finishes, verify the installation by checking the version. Close and reopen your terminal first to ensure your shell registers the new command.
claude --version
Seeing a version number confirms that Claude Code is installed and accessible from your system's PATH.
Authentication and Setup
Claude Code requires an active subscription, such as Claude Pro, Max, or a Team plan. There are two primary ways to authenticate: through a browser-based login for most users or with an API key for enterprise and direct API accounts.
If you have a standard subscription, simply running the claude command in your terminal for the first time will automatically open your web browser. You'll be prompted to log in to your Anthropic account. This process uses to securely connect the CLI to your account without exposing your credentials.
If you're using an enterprise account or have an API key from the Anthropic Console, you can authenticate by setting an environment variable. Set ANTHROPIC_API_KEY to your secret key.
# For macOS and Linux (add to .zshrc or .bashrc for persistence)
export ANTHROPIC_API_KEY='your-api-key'
# For PowerShell (add to your $PROFILE for persistence)
$Env:ANTHROPIC_API_KEY='your-api-key'
Claude Code is a terminal-based assistant that can plan features, write code, debug errors, search your codebase, and run shell commands.
With authentication complete, navigate to your project's root directory in the terminal. To formally introduce Claude to your codebase, run the /init command. This is a crucial first step.
claude /init
This command creates a claude.md file in your project. This file acts as a special instruction manual for the AI. It's the first thing Claude Code reads to understand your project's architecture, coding style, important files, and common commands. You can, and should, edit this file to give the agent better context.
Now that you have the claude command and an active session linked to your project, you're ready to start collaborating with the AI.
