PTENES
MODULE 1.2

🧠 How the agent thinks

Discover Claude Code's internal loop: how it plans, uses tools, handles uncertainty, and decides when to ask permission.

6
Topics
45
Minutes
Basic
Level
Theory
Type
1

🔄 The agent loop

Claude Code doesn't read your message and respond immediately. It runs a reasoning and action loop — the ReAct pattern — repeated until the task is complete or you can no longer make progress.

Task 🧠 Thinking internal reasoning 🛠️ Tool Read/Edit/Bash/Search 👁️ Observe read the result ✅ Ready repeats if needed

🔄 ReAct in detail

ReAct (Reasoning + Acting) is the most common agent pattern. The model reasons through the problem, chooses a tool, runs it, observes the result, and reasons again — iterating until it finishes.

  • •Think: "I need to know what's in src/auth.ts before editing"
  • •Act: Calls Read("src/auth.ts")
  • •Observe: Receives the file contents
  • •Think: "I need to add the function on line 42..."
ReAct
Reasoning + Acting in a loop
Scratchpad
Invisible internal reasoning
Tool call
Tool call
Iteration
Repeat until complete
2

🛠️ The Agent’s Tools

Claude Code has a set of native tools that you use in every cycle. Each tool has a token cost and requires specific permissions. Knowing them means knowing the agent’s hands.

✓ Reading tools (safe)

  • Read— reads the contents of a file
  • Glob— lists files matching a glob pattern
  • Grep— searches text/regex in files
  • LS— lists directories and structure

⚠️ Writing tools (require care)

  • Edit— modifies sections of a file
  • Write— creates or overwrites a file
  • Bash— runs any shell command
  • TodoWrite— manages an internal task list

💡 Tip: Observe the tools in the logs

Each tool appears in the logs with a prefix ●. Learn to read these logs—they show exactly what the agent is doing and which file it’s working in. It’s the closest thing to “seeing the agent’s thoughts.”

Reading
Read, Glob, Grep, LS
Writing
Edit, Write
Execution
Bash — more powerful and dangerous
Cost
Each tool call uses tokens
3

📋 How it plans

Before acting, Claude Code makes a implicit planning: breaks the problem into steps, identifies which files it needs to read first, and chooses the most efficient sequence of tools.

How the agent approaches "Add tests to the auth module"

1

Exploration — "what's there?"

Uses Glob("**/*.test.ts") e Glob("src/auth/**") to map the project.

You need to understand the structure before creating any files.

2

Reading — "what does it do?"

Reads src/auth/index.ts, src/auth/utils.ts and existing tests as a reference.

Without reading the code, you don't know what to test.

3

Writing — "create the tests"

Uses Write("src/auth/auth.test.ts", ...) with the generated content.

Follow the pattern of the existing tests, respecting the detected framework.

4

Validation — "does it work?"

Runs Bash("npm test src/auth") and fixes issues.

Never deliver untested code—the feedback loop is automatic.

📋 Explicit vs. implicit plan

By default, planning is internal (invisible). For complex tasks, you can ask the agent to create a plan before acting: "Before implementing, list the steps you'll follow". This reduces errors on long tasks.

Explore
Initial project mapping
Read
Reads relevant files first
Act
Modifies/creates with context
Validate
Runs and verifies the result
4

🛡️ When It Asks for Permission

Claude Code has a system of granular permissions. It operates autonomously for permitted actions, but pauses and asks for confirmation before actions that could cause irreversible damage.

✓ Does it without asking

  • ✓Read any file
  • ✓Edit code files (if on the allowlist)
  • ✓Run npm test, git status, git diff
  • ✓Create new files

⚠️ Requests confirmation

  • ⚠️Delete files or folders
  • ⚠️Destructive commands (rm -rf, drop table)
  • ⚠️Push to remote repositories
  • ⚠️Install global dependencies

⚙️ Configuring permissions in settings.json

// .claude/settings.json
{
"permissions": {
"allow": ["Bash(npm test:*)","Bash(git commit:*)"],
"deny": ["Bash(rm -rf:*)"]
}
}

💡 Tip: Configure the allowlist at the start

Spending the first few hours with the agent asking permission for every npm test is annoying. Configure the project's settings.json during your first few sessions for the commands you use often.

allowlist
Commands allowed without confirmation
denylist
Commands that are always blocked
settings.json
Project configuration file
--skip
Flag to skip confirmations (use caution)
5

🚧 Agent Limitations

Know the the agent’s real limits is just as important as knowing its capabilities. Wrong expectations lead to frustration and mediocre results.

📊 What Claude Code doesn't do natively

  • 1.Without memory between sessions: each new session starts from scratch (without CLAUDE.md)
  • 2.Without internet access: doesn’t consult online documentation without an extra tool
  • 3.Without a GUI: doesn’t click buttons or navigate graphical apps
  • 4.No vision: doesn’t read images, visual PDFs, or screenshots
  • 5.Without parallel execution: one task at a time in the same session

✓ Work around it with CLAUDE.md

  • ✓Create a file CLAUDE.md in the project with persistent instructions
  • ✓Include project context, code rules, and preferences
  • ✓The agent reads the file automatically at startup

✗ Real limitations (no hacks)

  • ✗Doesn't remember conversations from past sessions
  • ✗Doesn't monitor files in real time
  • ✗Doesn't schedule automatic tasks
CLAUDE.md
Manual persistent memory
MCP
Protocol for adding tools
Scope
Local project, not the internet
Session
Context cleared when you close
6

🔍 Watching the Agent Work

Claude Code is transparent: every action appears in the terminal in real time. Learning to read these logs is a skill that accelerates your learning exponentially.

💻 A typical session log

> Add a password hashing function to auth.ts
● Bash: find . -name "*.ts" -path "*/auth/*"
● Read: src/auth/auth.ts (342 lines)
● Read: src/auth/types.ts (89 lines)
● Bash: grep -r "bcrypt\|argon2\|crypto" package.json
● Edit: src/auth/auth.ts
● Bash: npx tsc --noEmit src/auth/auth.ts
✓ hashPassword function added. Using crypto.pbkdf2...

💡 What each log line means

  • Bash: find... — explore the project structure
  • Read: file (N lines) — reading N lines of context
  • Bash: grep... — checking for available dependencies
  • Edit: file — modifying the file
  • Bash: npx tsc... — checking for compilation errors
Tool log
Line by line in real time
Verbose
Flag for more detail
Ctrl+C
Interrupt at any time
Trace
Every action is auditable

✅ Module 1.2 Summary

✓
ReAct loop — Think → Use Tool → Observe → repeat
✓
Native tools — Read, Edit, Write, Bash, Glob, Grep
✓
Sequential planning — explore → read → act → validate
✓
Configurable permissions — allowlist/denylist in settings.json
✓
Full transparency — real-time logs show each action

Next Module:

1.3 — Context, tokens, and the window: how the agent’s working memory works and why it has a limit.