The agent loop
- Task. You write a request.
- Reasoning. The model decides what is missing: read a file, find a function, run a test.
- Tool. The agent calls a tool, for example reads a file.
- Result. The file contents or command output come back into context.
- 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
| Group | What it does | Example |
|---|---|---|
| Read and search | finds and reads files | search by name, grep the code, read a file |
| Edit | changes or creates files | targeted replacement, a new file |
| Bash | runs terminal commands | tests, linter, build, git |
| Web | searches and reads pages | library documentation |
| Extensions | MCP servers, subagents, skills | GitHub, 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.
/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.