Course navigation
Claude CodeLesson 3 of 25

How Claude Code Works

Claude Code is not a chatbot. It is an agent — a loop that reads your project, makes decisions, runs tools, and repeats until the job is done. This lesson covers what happens between pressing Enter and seeing the result on disk.

The agent loop

Every time you type a message, Claude Code runs the same loop. It does not stop after one step — it keeps going until the task is complete or it needs to ask you something.

1

Receive your message

You type a plain-English instruction. Claude reads it along with open files, conversation history, and CLAUDE.md if one exists.

2

Plan the steps

Claude decides what needs to happen. For 'add a login page', it might plan: read existing auth setup, write a component, update the router, write a test.

3

Call a tool

Claude picks one tool — read a file, write a file, run a shell command, or search the web — and executes it. One tool at a time.

4

Read the result

Tool output returns to the context window. Claude reads file contents, command output, or error text and decides what to do next.

5

Repeat or finish

If there is more to do, go back to step 3. If the task is complete, Claude writes a summary. If something is unclear, it pauses and asks you.

Claude Code is not one big request. It is a series of small, targeted tool calls — each moving the task forward by one concrete step.

The context window

Everything Claude "knows" during a session lives in the context window — a sliding buffer of text. Think of it as short-term memory.

LayerWhat it containsSize
System promptBuilt-in instructions about how Claude Code should behave~2k tokens
CLAUDE.mdYour project guide — conventions, architecture notes, commandsvaries
ConversationYour messages, Claude replies, and tool call resultsgrows
File readsContents of files Claude has read this sessiongrows
Shell outputStdout/stderr from commands — test results, lint output, errorsgrows
The window has a token limit. For very large tasks, Claude Code may summarise older conversation parts to make room. Start fresh with /clear or /compact.

Built-in tools

Claude Code has a fixed set of built-in tools. Each maps to something real on your machine.

Read

Reads file contents before editing so Claude never overwrites blindly.

Read(src/app/page.tsx)Read(package.json)

Write

Creates or overwrites a file. This is how Claude changes your code.

Write(src/utils/auth.ts, ...)Write(.env.example, ...)

Search / Grep

Finds patterns across the codebase — function usage, bug locations.

Grep('useAuth', src/)Glob('**/*.test.ts')

Bash / Shell

Runs shell commands — npm install, git status, test suites, builds.

npm testgit diff HEAD~1npx tsc --noEmit

Web Search

Looks up docs, error messages, or package APIs when the answer is not in your repo.

Search('Next.js App Router metadata')

TodoRead / TodoWrite

Tracks multi-step progress with a persistent task list.

TodoWrite([{title: 'Add auth', ...}])
Permission modes (next lesson) let you decide whether Claude needs approval before calling Bash, writing files, or making network requests.

A simple example, step by step

You type one sentence. Here is what Claude Code does behind the scenes.

Terminal
> Add a helper function that formats a price in Indian Rupees
ToolActionResult
GrepSearch for existing price or currency utilitiesNo formatPrice function in src/
ReadRead src/utils/index.ts for existing util patternsNamed exports, TypeScript strict mode
WriteWrite formatPrice helper to src/utils/currency.tsCreated src/utils/currency.ts
BashRun npx tsc --noEmit to check for type errorsNo errors. Build clean.

The file Claude wrote

src/utils/currency.tsnew file
/** Formats a number as an Indian Rupees string.
* e.g. formatPrice(1234567) → '₹12,34,567'
*/
export function formatPrice(amount: number): string {
return new Intl.NumberFormat(
"en-IN",
{
style: "currency",
currency: "INR",
maximumFractionDigits: 0,
}
).format(amount);
}
Claude read the codebase first, matched your conventions, then verified with the compiler — without you asking for any of that.

What Claude does not do

Knowing the limits helps you avoid surprises.

AssumptionReality
Keeps memory between sessionsContext is blank when you reopen. Use CLAUDE.md to persist project knowledge — it is re-read at session start.
Runs in the backgroundClaude only acts when you send a message. It does not watch files unless you set up a Hook.
Guesses when stuckIf Claude hits ambiguity or an unsafe decision, it pauses and asks rather than silently breaking something.
Has internet access by defaultWeb search is a tool Claude can call when needed. Your code is not sent externally unless a tool does so.

Before you continue

  • Claude Code runs an agent loop: plan, tool call, read result, repeat.
  • Session knowledge lives in the context window — system prompt, CLAUDE.md, files, and output.
  • Built-in tools: Read, Write, Search, Bash, Web, and Todo.
  • Claude reads your project and matches conventions before writing.
  • Next: the .claude/ directory and project config files.

What's Next

The agent loop is how Claude Code thinks. The next lesson maps out the .claude/ directory memory files, skills, and project config.