Lesson 2 of 3 · Claude Code Field Guide
How Claude Code Works
Story: The Architecture Behind the Magic
Daniel was a senior backend engineer who'd been using Claude Code for a week with mixed results. Some prompts gave him astonishing outputs -- perfectly structured code that matched his project's patterns. Other prompts produced generic, almost useless suggestions. The difference was maddening.
One afternoon, his teammate Priya watched him struggle. "You're asking it to fix the auth middleware, but you're not giving it any context about which auth middleware," she said.
"It should figure that out," Daniel replied. "It can see the whole codebase."
Priya shook her head. "It can see the whole codebase, but it doesn't automatically read every file. It has to decide what to read, and your prompt is too vague for it to know where to start. Watch."
She sat down and typed: "The JWT validation in our Express auth middleware at src/middleware/auth.ts is not checking token expiration. Fix it and add a test."
Claude Code immediately read the specific file, understood the JWT library being used, found the missing expiration check, wrote the fix, then read the existing test file to match the testing pattern before generating a new test case. Clean, precise, effective.
"The difference," Priya explained, "is that I understood how Claude Code thinks -- what it can see, how it decides what to do, and what information helps it make better decisions. Once you understand the architecture, you stop fighting the tool and start working with it."
That conversation changed Daniel's entire approach. And it's exactly what this lesson will do for you.
Concept: The Architecture of Claude Code
System Overview
Claude Code is not a single monolithic program. It's a carefully orchestrated system with several distinct components working together. Understanding these components will transform you from a casual user to a power user.
Let's break down each component.
Component 1: The CLI Interface
When you type claude in your terminal, you're launching the CLI (Command Line Interface). This is your primary interaction point. It handles:
- Input parsing: Taking your natural language prompts and formatting them for the model
- Output rendering: Displaying Claude's responses, including formatted code blocks, diffs, and progress indicators
- Permission prompts: Asking you to approve file writes and command executions
- Session management: Maintaining conversation history within a session
The CLI is intentionally minimal. There's no GUI, no web interface, no complex configuration wizard. You type, Claude responds, you approve actions. This simplicity is a feature -- it means Claude Code works everywhere your terminal works: local machines, SSH sessions, CI/CD pipelines, Docker containers.
Do not let How Claude Code Works become a hidden assumption. If teammates cannot see the rule, config, or verification path, Claude will behave inconsistently across sessions.
Component 2: The Tool System
This is the heart of what makes Claude Code agentic rather than just a chatbot. The tool system gives Claude a set of capabilities it can invoke autonomously:
Read Tool
The Read tool is Claude's eyes. When it needs to understand something about your project, it reads files. A single task might involve reading 10-20 files as Claude traces code paths, reads configurations, and examines test patterns.
Write Tool
The Write tool creates new files or replaces existing ones. Every write operation shows you the proposed content and waits for your approval before executing.
Edit Tool
The Edit tool is for surgical changes -- modifying a function, adding an import, changing a configuration value. Rather than rewriting an entire file, it finds the relevant section and makes the targeted change.
If How Claude Code Works becomes part of a recurring workflow, document the exact trigger, boundary, and verification step now. Future speed comes from clarity, not from memory.
Bash Tool
The Bash tool lets Claude run any terminal command: npm test, git status, curl, ls, cat -- anything you could type into your terminal. This is what lets Claude verify its own work by running tests, check the current state of things, and interact with external tools.
Search Tools (Grep/Glob)
These tools let Claude efficiently search your codebase without reading every file. Need to find all files that import a specific module? All places where a deprecated function is called? Search tools make this fast.
The tool system is what separates Claude Code from ChatGPT or a simple coding chatbot. Instead of you being the intermediary -- copying code in, pasting suggestions out -- Claude Code can directly interact with your project files and development environment.
Component 3: The Context Manager
Context management is arguably the most important concept to understand as a Claude Code user. It directly determines the quality of outputs you get.
What is context? Context is everything Claude knows when it's generating a response. This includes:
- Your conversation history -- all prompts and responses in the current session
- File contents -- every file Claude has read during the session
- Command outputs -- results from every bash command that was run
- System prompt -- instructions that tell Claude how to behave
- CLAUDE.md files -- project-specific instructions (we'll cover this in depth later)
Audit the How Claude Code Works Boundary
- List the commands, files, or actions this lesson says should be trusted.
- Compare that list against your current Claude permissions or team defaults.
- Tighten one rule today so the boundary is explicit instead of assumed.
The context window is finite. Claude has a maximum amount of information it can hold "in mind" at once. Think of it like working memory -- there's a limit to how much you can actively think about simultaneously.
200K
Token Context Window
Claude can hold approximately 150,000 words in context -- but strategic use matters more than filling it all
This has practical implications:
- Early in a session, Claude has lots of available context space. It can read many files, consider lots of code, and reason about complex relationships.
- Late in a long session, context gets crowded. Claude may not be able to hold all the information from earlier in the conversation plus new information. It might "forget" details from files it read earlier.
Pressure-Test a Safety Rule
- Choose one risky action mentioned in the lesson.
- Add or verify a rule that blocks it without breaking the safe workflow around it.
- Test the safe path and the blocked path so you know the guardrail is real.
Context management strategies:
Component 4: The Permission Model
Claude Code uses a tiered permission system that balances productivity with safety:
Always Allowed (no prompt):
- Reading files in your project
- Searching/grepping the codebase
- Reading environment variables
- Viewing git status and logs
Requires Approval:
- Writing or editing files
- Running bash commands (most of them)
- Making network requests
Can Be Pre-Approved:
- You can configure certain tools or commands to run without asking every time
- Example:
npm testcan be set to auto-approve since it's read-only
This permission model means Claude Code is safe to use in production codebases. It can't accidentally delete files, run destructive commands, or push to production without your explicit approval.
Permission Approval Habits
Review each proposed action before approving -- treat approvals as code review for AI actions
Blindly approve every action without reading what Claude plans to do, especially in production codebases
Quick Check
What is the main benefit of using How Claude Code Works well in Claude Code?
Never blindly approve actions without reading them. Claude Code shows you exactly what it plans to do. Take a few seconds to review -- that's your safety net. Think of approvals as code review for AI actions.
How a Request Gets Processed
Let's trace a real request through the entire system to see how all components work together.
Your prompt: "Add input validation to the signup form"
Step 1 -- Context Assembly The CLI packages your prompt with the current conversation history, any CLAUDE.md instructions, and sends it to the Claude model via the Anthropic API.
Step 2 -- Planning Claude analyzes the request and decides it needs to:
- Find the signup form component
- Understand the current form structure
- Determine what validation library the project uses (if any)
- Write the validation logic
- Test it
Step 3 -- Information Gathering (Agentic Loop)
Step 4 -- Implementation Based on what it learned, Claude writes validation code that:
- Uses Zod (matching the project's existing pattern)
- Follows the same schema structure as other schemas in the project
- Integrates with the existing form component
Quick Check
After reading this lesson, what should you validate when applying How Claude Code Works?
Step 5 -- Presentation Claude shows you the proposed changes and explains its reasoning. You review and approve.
Step 6 -- Verification (Optional) If you ask, Claude can run the test suite to verify nothing broke.
This entire sequence -- from your prompt to the finished implementation -- typically takes 30-90 seconds, depending on the complexity.
Apply: Trace the Architecture
Try This Now
Exercise 1: Predict the Tool Usage
For each prompt below, predict which tools Claude Code would use and in what order:
-
"What testing framework does this project use?"
- Think: What files would reveal the testing framework?
- Predicted tools: ___
-
"Rename the
UserServiceclass toUserManageracross the entire codebase."- Think: What does a codebase-wide rename require?
- Predicted tools: ___
-
"Why is the build failing?"
- Think: How would you diagnose a build failure?
- Predicted tools: ___
Answers:
- Read
package.json-> Grep for test config files -> Read test config (likejest.config.ts) - Grep for all occurrences -> Read each file -> Edit each file -> Run tests to verify
- Bash (
npm run build) -> Read error output -> Read the failing file(s) -> Fix -> Bash (rebuild)
Exercise 2: Context Window Awareness
Imagine you're working on a large project (500+ files). You start a Claude Code session and ask these questions in sequence:
- "Explain the authentication flow" (Claude reads 8 files)
- "Now explain the payment system" (Claude reads 12 files)
- "Now refactor the notification system" (Claude reads 6 files)
- "Can you recall what the auth middleware looked like?"
At step 4, Claude might struggle because the auth files from step 1 may have been pushed out of the context window by all the subsequent file reads. The solution? Start a new session for unrelated tasks, or re-read the specific file.
Exercise 3: Permission Model Scenarios
For each scenario, decide: would Claude Code ask for permission or act automatically?
- Reading your
.envfile -> ___ - Running
rm -rf node_modules-> ___ - Searching for all TODO comments -> ___
- Creating a new file
src/utils/helpers.ts-> ___ - Running
npm test-> ___
Answers: 1. Auto (read), 2. Requires approval (bash), 3. Auto (grep), 4. Requires approval (write), 5. Requires approval (bash, unless pre-approved)
Reflect: Thinking Architecturally
What You've Learned
Understanding how Claude Code works under the hood is the single biggest factor in getting great results from it. Let's summarize the key architectural concepts:
Key Takeaways
- Claude Code consists of four main components: CLI Interface, Tool System, Context Manager, and Permission Model
- The Tool System (Read, Write, Edit, Bash, Grep/Glob) is what makes Claude Code agentic -- it can interact directly with your project
- Context management is finite -- Claude has a limited amount of information it can hold at once, so session strategy matters
- The Permission Model ensures safety -- file writes and command execution always require your approval
- Every request triggers an agentic loop where Claude gathers information, plans, acts, and verifies
- Better prompts lead to more efficient tool usage, which leads to better results within the context window
Why Architecture Matters for Users
You might wonder why you need to understand the internals. Can't you just use it? You can -- but understanding the architecture lets you:
- Write better prompts -- When you know Claude needs to find files before it can read them, you'll provide file paths to skip the search step
- Manage context effectively -- When you know the context window is finite, you'll structure your sessions to avoid information overload
- Debug poor outputs -- When Claude gives a subpar response, understanding the architecture helps you figure out why and adjust
- Trust the tool appropriately -- When you know every action requires approval, you can confidently use Claude Code in production codebases
Looking Ahead
In the next lesson, we'll get hands-on: installing Claude Code, running it for the first time, and completing your first real task. Now that you understand the architecture, the installation and first-run experience will make much more sense -- you'll know exactly what's happening behind the terminal when you type that first prompt.
Use ← → to navigate, Space to mark complete