✻Founding-member pricing: every lesson for $19/mo. The first 3 lessons are free. Start lesson 1 →
Unit 1 · Claude Code Foundations · Lesson 2 of 40

How Claude Code Works: The Agentic Loop

Look under the hood of Claude Code: the agentic loop, built-in tools, the context window and permissions, and how they fit together on every turn.

FREE11 min+72 XP5-question quiz

🎯 By the end of this lesson you'll be able to

  • Walk through one turn of the agentic loop
  • Name Claude Code's core built-in tools
  • Explain what the context window is and why it fills up
  • Understand where permissions fit in the loop

The loop, one turn at a time

Every time you send a prompt, Claude Code runs a loop that looks like this:

  1. Gather context. Claude reads your prompt plus everything already in the session: system instructions, CLAUDE.md, earlier messages and tool results.
  2. Decide. The model picks the next step: answer you, or call a tool.
  3. Act. If it calls a tool (read a file, run a command, edit code), Claude Code checks permissions and then runs it.
  4. Observe. The tool's output is added to the conversation.
  5. Repeat until the task is done or Claude needs you.
⇅Rebuild the agentic loopdrag or use arrows
  1. ⋮⋮You send a prompt
  2. ⋮⋮Claude reads the context it has
  3. ⋮⋮The model decides on a tool call
  4. ⋮⋮Permissions are checked
  5. ⋮⋮The tool runs and its output is added to context
  6. ⋮⋮Claude decides: another step, or a final answer

The built-in toolbox

Claude doesn't have magic access to your machine. It has tools, and each one does one specific thing. The core set:

ToolWhat it does
ReadReads a file (text, images, PDFs, notebooks)
Glob / GrepFinds files by pattern and searches their contents
Edit / WriteChanges part of a file, or writes a whole file
BashRuns shell commands: tests, builds, git, package managers, any CLI
WebFetch / WebSearchReads a web page or searches the web
AgentHands a self-contained task to a subagent with its own context
SkillLoads a packaged skill's instructions when they're relevant

On top of these you can add tools from MCP servers (Unit 6), and code intelligence plugins that give Claude real type errors and "go to definition" after each edit.

✓
Why Bash matters so much

Bash is the universal adapter. If there's a CLI for it (gh, aws, psql, docker, your own scripts), Claude can use it. Before reaching for anything fancier, ask: "Is there already a command for this?"

The context window: Claude's working memory

Everything in the session (your messages, Claude's replies, every file it read, every command output) lives in the context window. It's large, but it isn't infinite, and the more it holds, the more expensive and less focused each turn becomes.

What loads automatically at the start of a session:

  • Claude Code's own system instructions and tool definitions
  • Your CLAUDE.md files (project, user and organization)
  • The names and descriptions of skills and MCP tools. Their full content loads only when needed.

What grows as you work: file reads, command output and the conversation itself. When the window gets close to full, Claude Code compacts automatically, summarizing older history to make room. You'll learn to steer that in Lesson 5 and Unit 2.

▶Watch it runPeeking at context
Peeking at context

Permissions: the checkpoint inside the loop

Between "decide" and "act" sits the permission check. Reading files is safe, so it's usually allowed. Editing files or running commands may prompt you, depending on your permission mode and rules:

▶Watch it runA permission prompt
A permission prompt

You can approve once, approve similar actions for the session, or say no and redirect. Press Esc at any time to interrupt Claude mid-turn. The work done so far is kept, and you can steer from there.

⌨Type the command+15 XP

What do you type inside Claude Code to see how full the context window is?

❯

Check your understanding

?Lesson quiz10 XP per correct answer · +25 for a perfect score
QUESTION 1 OF 5

In the agentic loop, what happens right before a tool runs?

Why: Every tool call passes through the permission system, based on your mode and your allow/ask/deny rules.
QUESTION 2 OF 5

Which tool lets Claude use almost any command-line program?

Why: Bash runs shell commands, so any CLI becomes something Claude can use.
QUESTION 3 OF 5

What loads into context automatically at session start?

Why: Claude Code loads instructions, CLAUDE.md, and the short descriptions of skills and MCP tools. Full skill content loads on demand.
QUESTION 4 OF 5

What happens when the context window gets close to full?

Why: Auto-compaction summarizes older turns to free space. You can also trigger and steer it with /compact.
QUESTION 5 OF 5

How do you interrupt Claude mid-turn without losing its progress?

Why: Esc stops the current turn but keeps work done so far, so you can redirect.
0 / 5 correct
Academy lesson

Unlock lesson 2 and the next 38

You've finished the free lessons. Join the Academy for $19/month to unlock every lesson, quiz, terminal simulation and puzzle, plus the final exam and your certificate of completion.

  • All 40 lessons across 9 units
  • 165+ quiz questions
  • Final exam + certificate
  • New lessons as Claude Code evolves
  • XP, streaks and badges
  • Cancel anytime

Already a member? Log in to continue.

Key takeaways

  • Each turn is a loop: gather context, decide, check permissions, act, observe, repeat.
  • Claude works through a small set of built-in tools. Bash makes any CLI available.
  • The context window is working memory. Keep it focused and watch it with /context.
  • Permissions sit inside the loop, so you decide how much autonomy Claude gets.

Nice work. Lesson 2 done?

Mark it complete to earn +72 XP, keep your streak alive and unlock badges.

Written by Curtis Cornell from Anthropic's public Claude Code documentation. Last reviewed November 14, 2026. Claude Code changes fast; if something here differs from your version, the official docs win.

Start lesson 1 free →