Mastering Claude Code: A Complete Beginner‑to‑Expert Guide

This article provides a comprehensive walkthrough of Claude Code, covering its core capabilities, cross‑platform installation, login methods, basic commands, advanced features like hooks and MCP, a detailed comparison with GitHub Copilot, best‑practice prompts, and FAQs, enabling developers to boost productivity with an AI‑driven terminal assistant.

Old Meng AI Explorer
Old Meng AI Explorer
Old Meng AI Explorer
Mastering Claude Code: A Complete Beginner‑to‑Expert Guide

What is Claude Code

Claude Code is a command‑line AI programming assistant that can plan execution paths, manipulate the file system, run terminal commands, integrate with Git, and call external tools. It operates from requirement analysis through code submission.

Default model: Claude Sonnet 4.5 (Opus 4.1 optional). Context window up to 1 000 000 tokens.

Installation

macOS / Linux / WSL

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

Windows PowerShell

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

Homebrew (macOS)

brew install --cask claude-code

NPM (not recommended for beginners)

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

If a previous npm installation exists, uninstall it first:

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

Verify installation

# Check version
claude --version

# Run health check
claude doctor

Login and authentication

First run of claude starts an OAuth flow. Subscription options:

Pro: $20 / month (includes Claude Code quota)

Max: $100 / month (higher priority, larger quota)

Enterprise users can use an Anthropic Console API key (pay‑per‑token). For connectivity issues in China, set a proxy:

# macOS / Linux
export ANTHROPIC_BASE_URL="https://your-proxy-url.com"
export ANTHROPIC_API_KEY="your-api-key"

# Windows PowerShell
$env:ANTHROPIC_BASE_URL="https://your-proxy-url.com"
$env:ANTHROPIC_API_KEY="your-api-key"

Or create ~/.claude/settings.json:

{
  "env": {
    "ANTHROPIC_AUTH_TOKEN": "your-api-key",
    "ANTHROPIC_BASE_URL": "https://your-proxy-url.com"
  }
}

Basic usage

Start Claude Code

Navigate to a project directory and run: claude Single‑command example (Chinese prompt for quicksort): claude "帮我写一个快速排序算法" Specify a model: claude --model opus-4-5 Enable debug mode:

claude --debug

Core slash commands

/help          # show help
/exit          # quit
/clear         # clear conversation history
/read <file>    # read a specific file
/review        # code review
/debug         # enable debug mode
/init          # initialize CLAUDE.md
/compact       # compress context to save tokens
/cost          # show token consumption
/status        # show system status
/doctor        # diagnose installation issues

File reference @ syntax

# Single file
@src/auth/login.ts

# Whole directory (read‑only structure)
@src/components/

# Compare two files
@src/old.js and @src/new.js

Permission management

Claude Code asks for confirmation before modifying files. Toggle automatic acceptance with Shift+Tab or launch with: claude --dangerously-skip-permissions Press ESC twice to roll back to the previous checkpoint.

Session management

# Continue previous session
claude -c

# Reset conversation (keep connection)
/clear

# Compress history
/compact

# Show current context usage
/context

Compress when context reaches about 70 %.

Advanced features

CLAUDE.md project configuration

Create a CLAUDE.md file at the project root to provide long‑term context (overview, tech stack, conventions, common commands).

# Project overview
This is a Next.js 14 full‑stack e‑commerce project.

# Tech stack
- Frontend: Next.js 14 + TypeScript
- Backend: Express + Prisma
- Database: PostgreSQL

# Development conventions
- Use TypeScript strict mode
- Follow existing ESLint rules
- Place test files alongside source files

# Common commands
pnpm dev   # start dev server
pnpm build # production build
pnpm test  # run tests

Hooks automation

Define custom logic at key AI actions in .claude/hooks.json. Example runs npm run lint after any Bash tool use:

{
  "hooks": [
    {
      "name": "PostToolUse",
      "match": "bash",
      "command": "npm run lint"
    }
  ]
}

Common hook names: SessionStart , PreToolUse , PostToolUse , UserPromptSubmit .

MCP (Model Context Protocol) extensions

Connect Claude Code to external tools.

# List MCP configurations
claude mcp list

# Add a new MCP server
claude mcp add <server-name> <command>

Supports over 300 integrations (databases, CI/CD systems, GitHub, Slack, etc.).

Planning mode

For complex tasks, use a “plan‑then‑execute” workflow:

"先阅读相关文件,给我一个重构计划,不要写代码"
"计划没问题,开始执行"

Thinking depth control

# Simple thinking
think 某个功能怎么实现

# Deep thinking
think hard 关于架构选型

# Ultra deep thinking
think harder / ultrathink

Higher depth takes longer but yields more accurate results.

Scheduled tasks (/loop and /schedule)

Introduced March 2025. Automate recurring actions while the session is active ( /loop) or persist across restarts ( /schedule).

# Every 5 minutes run code review
/loop 5m /babysit

# Every hour clean up code
/loop 1h /tidy

# Every 6 hours upgrade dependencies and open a PR
/loop 6h /dep-upgrade

Remote control across devices

# Generate QR code for remote control
claude --remote-control

# Or type within session
/rc

Scan with the Claude mobile app to control the session.

Subagents

Enable parallel handling of multiple tasks (e.g., separate agents for code review or refactoring) and isolate sensitive operations.

/agents

Claude Code vs GitHub Copilot (core dimensions)

Run mode : Claude Code – terminal CLI; Copilot – IDE plugin.

Context window : Claude Code – up to 1 000 000 tokens; Copilot – 32k‑128k tokens.

Core capability : Claude Code – multi‑file refactoring, complex reasoning; Copilot – real‑time completion, code snippets.

IDE integration : Claude Code – primarily terminal; Copilot – VS Code, JetBrains full support.

Pricing : Claude Code – Pro $20 / month; Copilot – $10‑19 / month.

SWE‑bench score : Claude Code – 72.5 %; Copilot – not disclosed.

Prompt templates (examples)

Code review:

请审查 src/auth/ 目录,重点关注:
1. 潜在的安全漏洞
2. 性能问题
3. 代码风格一致性
4. 可维护性问题

Bug location:

我在 src/api/user.ts 的第 45 行遇到以下错误:
[错误信息]

请帮我:
1. 分析可能的原因
2. 给出修复方案
3. 直接修改代码

New feature development:

我需要在 src/payment/ 添加支付功能。
上下文:
- 技术栈:Node.js + Stripe
- 类似功能参考 src/order/
- API 风格遵循 RESTful 规范

请先给出实现方案,经我确认后再开始编码。

Tips for higher output quality

Provide clear context : specify tech stack and coding standards.

Execute step‑by‑step : break complex tasks into planning and execution phases.

Specify output format : request TypeScript, JSON, etc.

Use checkpoints : confirm large changes before committing; ESC‑ESC rolls back.

Team collaboration suggestions

Standardize CLAUDE.md across the team.

Leverage Hooks for automated linting and formatting.

Integrate MCP with internal CI/CD pipelines.

Share plugins that encapsulate best practices.

Frequently asked questions

Is there a free tier? A limited free quota exists; Pro subscription provides ample usage.

Can it run on Windows? Yes, but WSL2 is recommended for the best experience.

What if the context window is too small? Use /compact regularly or split work across sessions.

How to handle connectivity issues in China? Configure a third‑party proxy or use a domestic Claude API provider.

Conclusion

Claude Code is an autonomous AI programming assistant that can boost developer productivity by 3‑5× when used effectively.

Easy installation : one‑line command.

Natural‑language driven : describe requirements in plain language.

Project‑wide context via CLAUDE.md.

Advanced capabilities : Hooks, MCP, scheduled tasks, subagents.

Complementary use : combine Copilot for quick fixes with Claude Code for deep refactoring.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

CLIAutomationMCPhooksGitHub CopilotAI coding assistantSWE-benchClaude Code
Old Meng AI Explorer
Written by

Old Meng AI Explorer

Tracking global AI developments 24/7, focusing on large model iterations, commercial applications, and tech ethics. We break down hardcore technology into plain language, providing fresh news, in-depth analysis, and practical insights for professionals and enthusiasts.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.