Claude Code: Claude Code Introduction and How It Works
Last updated: 2026-08-31
Claude Code is Anthropic's AI coding Agent — it's not a chatbot, but an intelligent entity that can read files, run tests, modify code, and iterate based on feedback.

📋 Prerequisites: No prior knowledge required, basic command line familiarity helpful
1. What You'll Learn
- Claude Code's positioning: Agent, not Chat
- How it works in local code repositories
- Core architecture and permission model
- Comparison with traditional AI coding tools
- Use cases and limitations
About Code Example Outputs
This course uses a deterministic/non-deterministic separation pattern for code examples, which is the industry best practice for AI Agent tool tutorials:
| Marker | Meaning | Your Output |
|---|---|---|
| Output: | Deterministic results (installation, configuration, counts, etc.) | Should closely match the example |
| Interaction Flow: | Agent behavior flow (LLM calls, tool selection, etc.) | Actual text will differ, but the flow will be similar |
| Verification: | How to check exercise results | Follow the described steps to verify |
1 + 1 = 2 (always the same). AI Agent tools: agent.chat("analyze code") = ??? (different every time). This is an essential characteristic of AI Agent tools, not a bug.
2. A Real Team's Story
(1) The Problem: AI Coding Tool Efficiency Bottleneck
Alice is the tech lead at a mid-sized internet company. Her team tried various AI coding tools:
- ChatGPT: Good answers, but code needs manual copy-paste into the project
- GitHub Copilot: Convenient auto-completion, but only local completion, can't understand the whole project
- Cursor: Good IDE integration, but limited Agent capabilities for complex refactoring
Product manager Bob's requirements keep growing:
"We need to migrate the entire authentication module from Session to JWT, involving 20+ files, and ensure all tests pass."
(2) Claude Code's Solution
Alice installed Claude Code and launched the migration with one command:
claude "Migrate the authentication module from Session to JWT, ensure all tests pass"
Claude Code autonomously completed:
- Read project structure, located all authentication-related files
- Modified authentication logic one by one
- Ran the test suite
- Fixed code based on failed results
- Iterated until all tests passed
Files modified: 23
Tests run: 47
Tests passed: 47
Iterations: 3
Time: ~8 minutes
3. What is Claude Code
(1) Core Definition
Claude Code is a command-line AI Agent that works directly in your local code repository:
| Feature | Description |
|---|---|
| Positioning | AI coding Agent, not a chat tool |
| Environment | Local terminal / IDE terminal |
| Work style | Read files → Analyze → Modify → Verify → Iterate |
| Permission model | High permissions, can read/write files and execute commands |
| Model | Claude Sonnet / Opus |
(2) Agent vs Chat: The Essential Difference
graph LR
A[User Instruction] --> B[Chat Mode]
A --> C[Agent Mode]
B --> B1[Generate Answer]
B1 --> B2[User Manually Executes]
C --> C1[Understand Intent]
C1 --> C2[Read Context]
C2 --> C3[Execute Operation]
C3 --> C4[Verify Result]
C4 --> C5{Success?}
C5 -->|No| C2
C5 -->|Yes| C6[Report Result]
| Dimension | Chat Tool | Agent (Claude Code) |
|---|---|---|
| Interaction | Q&A | Autonomous iteration |
| Code operation | Output code snippets | Directly modify project files |
| Context | User manually provides | Auto-read project files |
| Verification | User manually verifies | Auto-run tests/commands |
| Error handling | User self-corrects | Self-correct and retry |
▶ Example 1: Chat vs Agent Comparison
# Chat approach: User needs multiple steps
# 1. Ask AI how to fix bug
# 2. Copy code
# 3. Paste into file
# 4. Run test
# 5. Test fails, go back to step 1
# Agent approach: One command does it all
claude "Fix the null pointer exception in user.service.ts, ensure tests pass"
4. How Claude Code Works
(1) Workflow
Claude Code's work loop:
graph TB
U[User Input] --> P[Intent Parsing]
P --> R[Read Project Context]
R --> A[Plan Operations]
A --> E[Execute Operations]
E --> V[Verify Results]
V --> S{Success?}
S -->|Yes| RPT[Report Results]
S -->|No| A
(2) Permissions and Security
Claude Code has high permissions but provides multi-layer security controls:
| Permission Level | Scope | Confirmation Method |
|---|---|---|
| Read | Read any project file | Auto-allowed |
| Write | Modify project files | First confirm / Auto |
| Execute | Run shell commands | Requires confirmation (configurable auto) |
| Network | Install packages, access APIs | Requires confirmation |
▶ Example 2: Claude Code Work Process
$ claude "Create date.ts under src/utils/ with common date formatting functions and tests"
# Claude Code's autonomous work process:
# 1. Reading src/utils/ directory structure...
# 2. Reading existing utils for style consistency...
# 3. Creating src/utils/date.ts with formatDate(), relativeTime(), etc.
# 4. Creating src/utils/__tests__/date.test.ts
# 5. Running: npm test -- src/utils/__tests__/date.test.ts
# 6. 2 tests failing... fixing edge cases
# 7. Running: npm test -- src/utils/__tests__/date.test.ts
# 8. All 6 tests passed ✓
5. Comparison with Other AI Coding Tools
| Tool | Type | Work Scope | Agent Ability | Model |
|---|---|---|---|---|
| Claude Code | CLI Agent | Full project | Strong | Claude |
| GitHub Copilot | IDE Plugin | Single file completion | Weak | GPT series |
| Cursor | IDE + Agent | Within IDE | Medium | Multi-model |
| Aider | CLI Agent | Full project | Medium | Multi-model |
| Codex CLI | CLI Agent | Full project | Strong | GPT series |
| OpenCode | CLI Agent | Full project | Medium | Multi-model |
▶ Example 3: Alice's Tool Evaluation
def evaluate_tool(tool_name, agent_score, scope_score, multi_file):
score = agent_score * 0.4 + scope_score * 0.3 + (1 if multi_file else 0) * 0.3
return round(score, 2)
tools = {
"Claude Code": {"agent": 9, "scope": 9, "multi_file": True},
"Copilot": {"agent": 3, "scope": 4, "multi_file": False},
"Cursor": {"agent": 6, "scope": 7, "multi_file": True},
"Aider": {"agent": 7, "scope": 8, "multi_file": True},
}
for name, scores in tools.items():
result = evaluate_tool(name, scores["agent"], scores["scope"], scores["multi_file"])
print(f"{name}: {result}")
6. Comprehensive Example: Project-Level Refactoring
# Scenario: Alice needs to migrate an Express project to Fastify
$ claude "Migrate the entire project from Express to Fastify:
1. Replace all route definitions
2. Update middleware syntax
3. Modify startup script
4. Ensure all tests pass
5. Update package.json dependencies"
# Claude Code autonomously executes:
# → Scanning 45 files for Express patterns...
# → Converting route definitions (32 routes)...
# → Updating middleware (8 files)...
# → Running test suite: 89/89 passed ✓
# → Updating package.json...
# → Removing Express dependencies...
# → Final test run: 89/89 passed ✓
❓ FAQ
📖 Summary
- Claude Code is an Agent tool, not a chat tool — core ability is autonomous code operations
- Work loop: Read → Analyze → Execute → Verify → Iterate
- High permissions with multi-layer security controls, configurable auto/manual confirmation
- CLI-based, not IDE-dependent, works directly in terminal
- Best for multi-file refactoring, bug fixing, test writing and other complex tasks
📝 Exercises
- Basic (⭐): List three core differences between Claude Code and ChatGPT in coding assistance.
- Intermediate (⭐⭐): Choose an AI coding tool for your project and write your reasoning (refer to the comparison table).
- Advanced (⭐⭐⭐): Design a workflow specifying which tasks suit Claude Code and which suit Copilot, with decision criteria.