Claude Code
authorKRIATIZ
01 · Getting started / lesson 3 of 3

How the agent works

20 minBeginner6 steps

To give the agent good tasks, you need to understand how it thinks. Claude Code runs a loop: think, call a tool, look at the result, repeat. All of it lives in a limited context window.

data and requestsproblem
Lesson stepsstep 1 of 6
  1. Task
  2. Read
  3. Edit
  4. Bash
  5. Loop
  6. Overflow
step 1 / 6how it works

You write the task

The request reaches the model together with CLAUDE.md and system instructions.

Key point

Everything the agent knows lives in context.

← → steps · space pause · R restart · ⌘K search
You will learn 5
Lesson notes

The agent loop

  1. Task. You write a request.
  2. Reasoning. The model decides what is missing: read a file, find a function, run a test.
  3. Tool. The agent calls a tool, for example reads a file.
  4. Result. The file contents or command output come back into context.
  5. Repeat until the task is done or your decision is needed.

One task can take dozens of such steps. That is why the agent handles multi-file tasks, and why what it sees in context matters.

Tools

GroupWhat it doesExample
Read and searchfinds and reads filessearch by name, grep the code, read a file
Editchanges or creates filestargeted replacement, a new file
Bashruns terminal commandstests, linter, build, git
Websearches and reads pageslibrary documentation
ExtensionsMCP servers, subagents, skillsGitHub, database, Notion

Reading and searching usually need no permission. Editing and commands require your confirmation by default.

The context window

Everything the agent knows in a session is in context: system instructions, CLAUDE.md, your messages, files read, command output. The context is large but not unlimited. When it fills up:

  • the agent replies slower and makes more detail mistakes;
  • Claude Code automatically compresses old history and some details are lost;
  • more limits or tokens are spent.

The /context command shows what fills the context right now.

Why the agent "forgets"

If the agent stops following an agreement in a long session, it most likely sits in the compressed part of the history. The fix is simple: write important rules in CLAUDE.md, and use /clear between different tasks.

Rule: one task, one session. A new unrelated task = /clear.

How to help the agent

  • Reference files with @ so the agent doesn’t spend steps searching.
  • Say how to verify: "run npm test".
  • For big tasks ask for a plan first. Plan mode is covered in the tasks lesson.
  • Use subagents to explore large codebases: they read files in their own context and return only the conclusion.

Today's task

Give the agent an exploration task: "Explain how a request flows from the router to the database in this project." See which tools it called, then run /context.

Want an agent that works with your systems?

I build AI agents with tools for your processes: from internal assistants to development automation.

Learn more
Vladyslav Koshelyev
Vladyslav Koshelyev

Developer at KRIATIZ. I build chatbots, websites and automation for businesses. Author of the course.

About the author · Telegram