How Claude Code works under the hood

What happens after you press Enter: the agentic loop, the tools Claude uses, how context and memory work, and where permissions and checkpoints fit.

Lesson 2.1โฑ 8 min read๐Ÿšฒ Getting goingโ“ 3-question quiz
The short answer

Claude Code sends your request, your project memory (CLAUDE.md) and a list of tools to a Claude model. The model replies with tool calls (read this file, run that command), Claude Code runs them, subject to your permissions, and feeds the results back. That loop repeats until the task is done. Everything lives in a context window, which is summarised automatically when it fills up.

The model and the harness

There are two halves:

  • The model (Claude) does the thinking. It cannot touch your computer on its own; it can only reply with text and requests to use tools.
  • The harness (Claude Code, the program on your machine or in the cloud) does the doing. It runs the tools Claude asks for, enforces your permissions and passes results back.
Analogy: a surgeon (the model) and an operating theatre team (the harness). The surgeon decides; the team hands over instruments, checks the rules and reports what happened.

What happens when you press Enter

  1. Claude Code gathers your message, your CLAUDE.md files, the conversation so far and the list of tools it may use.
  2. The model decides on a next step, for example "search for the login form".
  3. Claude Code checks your permission settings, asks you if needed, then runs the tool.
  4. The result (search hits, file contents, test output) goes back to the model.
  5. Repeat until the model says it is finished, then you get a summary.

A single request can involve dozens of these steps. That is why Claude Code can fix a bug it has never seen: it explores, tries, checks and adjusts.

The toolbox

  • Read, search and list: open files, search text across the project, find files by name.
  • Edit and write: change part of a file or create a new one.
  • Bash: run terminal commands such as tests, builds, git and package managers.
  • Web fetch and search: read documentation and pages online.
  • Subagents: hand a side task to a helper with its own clean context.
  • To-do list: track the steps of a bigger job so nothing is forgotten.
  • MCP tools: anything you connect, such as GitHub, a database or your issue tracker.

Context: Claude's working memory

Everything in the conversation (your messages, files read, command output) sits in the context window. It is large but not endless. When it gets full, Claude Code compacts: it summarises older detail to make room. You can do this yourself with /compact, start fresh with /clear, or see what is using space with /context.

Long-term memory lives in CLAUDE.md files, which are loaded at the start of every session. Anything you want Claude to remember tomorrow belongs there, not in chat.

Safety rails built in

  • Permissions: by default Claude asks before editing files or running commands. You can allow or deny specific tools and commands in settings.
  • Plan mode: Claude researches and proposes a plan without changing anything.
  • Checkpoints: Claude Code tracks its file edits, so you can rewind with /rewind (or press Esc twice).
  • Hooks: your own scripts that run at set moments, every time, to format, check or block.
Tip: checkpoints cover Claude's file edits, not side effects such as database changes or deployments. Git is still your real safety net.

Check yourself

Three quick questions to check it stuck.

Ask the tutor

Stuck on something in this lesson? Ask the AI tutor. It answers from this lesson and points you to others that help. Answers are written by AI and can be wrong. Do not include personal details, passwords or company secrets.

Frequently asked

Does Claude Code send my whole codebase to Anthropic?

No. It reads files on demand, as the task needs them, and only what it reads (plus your messages and tool results) goes to the model as context. You can block sensitive files with deny rules in settings.

What is compaction in Claude Code?

When the context window fills up, Claude Code summarises the older parts of the conversation so the session can continue. You can trigger it yourself with /compact, or clear the conversation with /clear.

Which model does Claude Code use?

It uses Anthropic's Claude models. You can see and switch the model for a session with the /model command.