Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Claude Code Installation and Usage

Claude Code Installation and Usage

Before installing, first learn about the ways Claude Code can be used and choose the one that suits you best.

Method Suitable for Advantages Disadvantages
Web version Complete beginners No installation needed; just open a browser Relatively limited features; cannot deeply integrate with local code
CLI (command line) Developers with some foundation Complete features, high integration, closest to the original design intent Requires familiarity with command-line operations
Editor integration (VS Code / Cursor, etc.) Everyday developers Seamlessly fits into existing workflows; no window switching needed Depends on plugins and environment configuration

Selection advice:

Claude Code now also offers a desktop version, downloadable at the following address:https://claude.com/download

This tutorial focuses on the CLI approachas the main method, because it is the most stable and versatile, and closest to Claude Code's original design intent.


Installing Claude Code CLI

1. Prerequisites

Before installing, you need to prepare the following two items:

① Claude account

② Command-line tool

2. Install using the official script (recommended)

An official one-click install script is provided; choose the appropriate command for your system:

macOS、Linux、WSL:

curl -fsSL https://claude.ai/install.sh | bash

Windows PowerShell:

irm https://claude.ai/install.ps1 | iex

Windows CMD:

curl -fsSL https://claude.ai/install.cmd -o install.cmd && install.cmd && del install.cmd

Homebrew:

brew install --cask claude-code

WinGet:

winget install Anthropic.ClaudeCode

After installation, verify it succeeded:

claude --version

If the terminal outputs a version number (such as 1.x.x), the installation succeeded:

2.1.81 (Claude Code)

3. Install using npm (not recommended)

The official recommendation is no longer to install via npm; prefer the official script above. If you really need to install via npm, first confirm Node.js is installed:

node --version

If a version number is output (such as v18.17.0), it is installed. If the command is not found, go to nodejs.org Download and install.

after confirming Node.js is available, run the following command to install Claude Code:

npm install -g @anthropic-ai/claude-code

Wait for installation to complete (may take a few minutes), then verify:

claude --version

4. Update Claude Code

You can update directly with the following command:

claude install

or:

claude update

Claude Code willautomatically check for updates; after the background download completes, it takes effect on next launch. Auto-update settings are written in settings.json :

Example

{

  "autoUpdatesChannel": "stable" // update channel: stable (stable version, recommended) or beta (test version)

}

You can also configure it within Claude Code via the /config command.

If you don't need auto-updates, you can disable them in settings.json 's env :

Example

{

  "env": {

    "DISABLE_AUTOUPDATER": "1" // set to "1" to disable auto-update; "0" or deleting this line restores auto-update

  }

}

Pass Homebrew or WinGet The installed Claude Code does not support auto-update; run the following command manually to update:

macOS Homebrew

brew upgrade claude-code

#Windows WinGet winget upgrade Anthropic.ClaudeCode

5. Troubleshooting common installation issues

Issue 1: prompt says npm command not found

Issue 2: prompt says permission denied

Issue 3: installation is very slow or gets stuck

Recommended terminals:If the system's default terminal is mediocre, the following terminals offer a better experience with Claude Code:

  • WezTerm (cross-platform):https://wezterm.org/
  • Alacritty (cross-platform):https://alacritty.org/
  • Ghostty(Linux / macOS):https://ghostty.org/
  • Kitty(Linux / macOS):https://github.com/kovidgoyal/kitty
  • For more terminal tools, see:https://www.runoob.com/w3cnote/terminal-tools.html


    Uninstalling Claude Code

    Choose the corresponding uninstall command based on how you originally installed it.

    1. Official script installation (native installation)

    Delete Claude Code's executable and version files:

    macOS、Linux、WSL:

    rm -f ~/.local/bin/claude
    
    rm -rf ~/.local/share/claude
    
    

    Windows PowerShell:

    Remove-Item -Path "$env:USERPROFILE\.local\bin\claude.exe" -Force
    
    Remove-Item -Path "$env:USERPROFILE\.local\share\claude" -Recurse -Force
    
    

    2. Homebrew installation

    brew uninstall --cask claude-code
    
    

    3. WinGet installation

    winget uninstall Anthropic.ClaudeCode
    
    

    4. npm installation

    npm uninstall -g @anthropic-ai/claude-code
    
    

    5. Delete configuration files (optional)

    The above commands only uninstall the executable; configuration files and history are not automatically deleted. If you want to completely clear all data (including settings, authorized tools, MCP server configuration, and conversation history), run the following additional commands:

    ⚠️ Deleting configuration files isirreversibleoperation; all local settings and history will be permanently lost. Confirm before proceeding.

    macOS、Linux、WSL:

    # 删除全局用户设置和状态
    
    rm -rf ~/.claude
    
    rm ~/.claude.json
    
    
    
    # Delete local settings for the current project (run in project directory)
    
    rm -rf .claude
    
    rm -f .mcp.json
    
    

    Windows PowerShell:

    # 删除全局用户设置和状态
    
    Remove-Item -Path "$env:USERPROFILE\.claude" -Recurse -Force
    
    Remove-Item -Path "$env:USERPROFILE\.claude.json" -Force
    
    
    
    # Delete local settings for the current project (run in project directory)
    
    Remove-Item -Path ".claude" -Recurse -Force
    
    Remove-Item -Path ".mcp.json" -Force
    
    

    Logging in to Claude Code

    1. First-time login flow

    Start Claude Code in the project directory:

    claude
    
    

    On first launch, Claude Code guides you through login. You can also manually enter the login command after entering the interface:

    /login
    
    

    Follow the prompts in the terminal to complete login authorization. After login, credentials are saved locally,so no re-login is needed next time. If you need to switch accounts, re-run /login .

    2. Supported account types

    You can log in with any of the following account types:

    ① Claude subscription account (recommended)

    ② Claude Console account (API access)

    3. Automatic workspace creation (Console account)

    When first authenticating Claude Code with a Claude Console account, the system automatically creates a workspace named "Claude Code" in your Console, used for:


    Starting your first session

    1. Start in the project directory

    Open a terminal, first switch to your project directory, then start Claude Code. This lets Claude read your project files and provide targeted help:

    cd /path/to/your/project
    
    claude
    
    

    2. Welcome screen

    After launching, you'll see Claude Code's welcome screen, including current session info, recent conversations, and the latest update notes:

    3. View available commands

    Type ... in the input box /help to see all available features:

    /help
    
    

    Input /resume You can resume a previously interrupted conversation:

    /resume
    
    

    Directly type ... in the input box /, and a completion list of all available commands pops up:

    For detailed credential management information, see the official documentation's Credential Management part.


    Asking your first question

    1. Understand the project

    After starting Claude Code in the project directory, you can first have it analyze your codebase:

    what does this project do?
    
    

    Claude automatically reads project files and gives a project overview.

    Claude Code automatically reads files as needed—you don't need to manually copy and paste file contents into the conversation; it finds the needed context on its own.

    2. More project-related questions

    You can also ask more specific questions:

    what technologies does this project use?
    
    
    where is the main entry point?
    
    
    explain the folder structure
    
    

    3. Ask about Claude Code's capabilities

    You can also directly ask Claude what it can do:

    what can Claude Code do?
    
    
    how do I use slash commands in Claude Code?
    
    
    can Claude Code work with Docker?
    
    

    Claude can access its own documentation and accurately answer questions about its features and capabilities.


    Making your first code change

    1. Try a simple task

    Now let Claude Code actually write code. We create a test directory and have it test.py add a Hello World function in the file:

    cd runoob-test    # 进入测试目录(没有则新建一个)
    
    claude            # 启动 Claude Code
    
    

    After entering the interface, type:

    在 test.py 文件中添加 hello world 函数
    
    

    Claude Code shows the proposed code changes and asks for your confirmation before executing; select yes then press Enter to apply:

    2. Claude Code's modification workflow

    For each code change, Claude Code follows this process:

    1. Locate relevant files: automatically locate the files to modify in the project
    2. Show proposed changes: display the changes as a diff
    3. Request your approval: must be confirmed by you before execution
    4. Execute the edit: write to the file after confirmation

    You can approve each change individually, or enable "Accept All" mode in the current session to confirm in bulk.


    Using Git features

    Claude Code makes Git operations as simple as everyday conversation; just describe what you want in natural language.

    1. Basic Git operations

    View modified files:

    what files have I changed?
    
    

    Commit changes (Claude automatically generates the commit message):

    commit my changes with a descriptive message
    
    

    2. More complex Git operations

    Create a new branch:

    create a new branch called feature/quickstart
    
    

    View recent commit history:

    show me the last 5 commits
    
    

    Help resolve merge conflicts:

    help me resolve merge conflicts
    
    

    Fix a bug or add a feature

    1. Add a new feature

    Describe the feature you want to add in natural language, and Claude Code finds the right place and implements it:

    add input validation to the user registration form
    
    

    2. Fix existing issues

    Describe the bug symptoms and let Claude locate and fix it:

    there's a bug where users can submit empty forms - fix it
    
    

    3. Claude Code's issue-handling process

    1. Locate relevant code: find files and functions related to the issue in the codebase
    2. Understand the Context: analyze the code logic to understand the root cause of the issue
    3. Implement the solution: propose changes and show the diff
    4. Running tests: if tests exist in the project, Claude tries to run them to verify the fix

    Other common workflows

    Code Refactoring

    refactor the authentication module to use async/await instead of callbacks
    
    

    Writing tests

    write unit tests for the calculator functions
    
    

    Update documents

    update the README with installation instructions
    
    

    Code review

    review my changes and suggest improvements
    
    

    Claude Code is your AI pair-programming partner.Talk to it as you would to an experienced colleague—describe what you want to achieve; no need to stick to specific command formats, just express yourself in natural language, and it will help you find the best implementation.


    Common Command Quick Reference

    Command-line commands (used in the terminal)

    Command Function Example
    claude Start interactive mode (most common) claude
    claude "任务描述" Run a one-off task then exit interactive mode claude "fix the build error"
    claude -p "查询内容" Exit immediately after a single query (suitable for script integration) claude -p "explain this function"
    claude -c Resume the most recent conversation in the current directory claude -c
    claude -r Select and resume a conversation from history claude -r
    claude commit Have Claude automatically generate a Git commit message and commit claude commit
    claude update Manually update Claude Code to the latest version claude update
    claude --version View the currently installed version number claude --version

    In-interactive-mode commands (used in the Claude Code interface)

    Command Function Example
    /help Show all available commands and feature descriptions /help
    /login Log in or switch to another account /login
    /resume Resume a previously interrupted conversation from history /resume
    /clear Clear the current conversation history and start a fresh session /clear
    /config View and modify Claude Code configuration /config
    exit or Ctrl+C Exit Claude Code and return to the terminal exit