Dashboard/Phase 1: Foundations
📖 Concept7 min10 XP

Lesson 5: Reading Code with Claude

Day 5 of 50 · ~7 min read · Phase 1: Foundations


The Opening Question

Claude Code has tools. It can read files, search code, and edit things. But imagine Claude is dropped into a project with thousands of files.

How does Claude know which files to read? How does it avoid drowning in context? How does it navigate a codebase it's never seen?

Here's the question: How does Claude understand a codebase it's never seen?


Discovery

Let's reason through this step by step.

Question 1: Why can't Claude just read everything?

Let's say you ask Claude: "What does the login function do?"

Your project might have:

  • 50 JavaScript files
  • 20 configuration files
  • 100 test files
  • Dependencies in node_modules (thousands of files)
  • Docs, build artifacts, generated files...

If Claude read everything, the conversation would be overwhelmed. Claude would waste time and money (API calls cost money, and more files means higher cost). Plus, context would get blurry fast.

So the question becomes: How should Claude decide what to read?

Pause and think: If you walked into an unfamiliar codebase and someone asked "show me the login function," how would you find it without reading every file?

You'd probably:

  1. Look at the project structure (ls, file tree in VS Code)
  2. Guess where it might be (usually in an auth/ or src/ folder)
  3. Search for "login" (grep login **/*.js or Ctrl+F in VS Code)
  4. Read the file(s) you found

Claude does the same thing, but using tools to do it strategically.

Question 2: How does Claude explore a project structure?

When Claude first enters a project, it starts with reconnaissance. What would be the first files Claude should read to understand your project?

Pause and think: What files in your project tell you the most about what the project is?

Usually, these files:

  • package.json (or requirements.txt, go.mod, etc.) — tells Claude what tech stack you're using
  • README.md — tells Claude the project's purpose
  • Directory structure — tells Claude how the code is organized

Claude will often start by reading these, getting a mental model of the project, and then diving deeper.

This is where the Glob tool shines. Instead of asking you "where's your login code?", Claude can use Glob to find it:

Glob: Find all JavaScript files: **/*.js

This returns a list. Claude can then examine file names and paths to get oriented.

Question 3: How does Claude search for specific things?

Now let's say Claude understands the project structure. It knows you have a src/auth/ folder with authentication code.

But within that folder, how does Claude find the login function? Read every file?

No. Claude uses Grep — the search tool.

Grep lets Claude search for a pattern across files. For example:

Grep: Search for "function login" or "const login =" in src/auth/**/*.js

Grep returns every line that matches. Claude sees: "Oh, the login function is in auth.js at line 42." Now Claude can read just that file.

The key insight: Glob finds files. Grep finds content within files. Together, they're a navigation system.

Question 4: What's the difference between reading code and understanding code?

Here's a subtle but important distinction. Let me ask you:

Can Claude read code? Yes, absolutely. It can open a file and see the contents.

Does that mean Claude automatically understands what the code does? Not always.

Pause and think: If you opened a file and read every line, would you automatically understand what it does? Or would you need to think about it, trace through the logic, check what it calls?

Claude might read a file and still have questions. For instance:

  • The function calls another function. Claude needs to read that too.
  • The code handles an edge case. Claude needs to understand why.
  • There's a variable set somewhere else. Claude needs to trace it.

This is where the agentic loop comes back. Claude reads → reasons → might need to read more → reasons → acts.

So "reading code" is the act of viewing files. But "understanding code" requires Claude to ask follow-up questions, read related files, and reason about how things connect.

The good news: Claude is persistent. If it doesn't understand something, it'll read more files, ask you questions, or both.


The Insight

Here's the pattern:

When Claude enters a new codebase, it doesn't read everything. Instead, it strategically uses Glob to find relevant files, Grep to search for specific content, and Read to examine the code. This combination lets Claude navigate even large projects efficiently, building understanding one piece at a time.

The mental model: Claude's code reading is like navigating an unfamiliar city. The city is too big to explore every street. But with a map (Glob — see the structure), a search function (Grep — find what you're looking for), and the ability to stop and read signs (Read — examine files), you can find your destination without getting lost.


Try It

Let's watch Claude navigate and read your codebase.

  1. Pick a medium-sized project (something bigger than a single file, but not enormous).

  2. Ask Claude a question that requires reading:

    • "Find the database initialization code and tell me what database we're using"
    • "Where is the API route that handles POST requests? Show me the code"
    • "Find all places where we're making HTTP requests and tell me what libraries we're using"
  3. Watch Claude's strategy. You should see something like:

    • Claude uses Glob to find likely files (e.g., **/*.js, src/**/*)
    • Claude might use Grep to search for keywords (e.g., "database", "POST", "fetch")
    • Claude reads the files it found
    • Claude might read related files if needed (following imports, dependencies, etc.)
  4. Notice what Claude doesn't do: It doesn't read your entire project. It focuses on the question.


Key Concepts Introduced

ConceptDefinition
GlobA tool for finding files by pattern, like **/*.js or src/components/*.tsx
GrepA tool for searching text inside files across your project
Strategic readingClaude reads only the files relevant to your request, not the entire codebase
Code navigationUsing Glob + Grep + Read to explore and understand a project structure
Understanding vs. readingReading files means viewing the text; understanding means Claude has traced dependencies, reasoned about logic, and built context
Follow-up readsClaude often needs to read multiple related files to fully understand a feature or behavior

Bridge to Lesson 6

You now understand how Claude reads and navigates code. You've also learned the foundational concepts: what Claude Code is, how it installs, how the agentic loop works, what tools it has, and how it finds its way through a codebase.

Tomorrow, you'll apply all of this in a real hands-on lab. You'll work through a guided project that practices installation, conversation, tools, and reading code together.

Tomorrow's question: Can you build something useful with Claude Code right now?

We're starting with a hands-on lab where you'll create a real utility from scratch.


← Back to Curriculum · Lesson 6 →