Skip to content
AI Tooling·Intermediate

The Agentic Loop: Why Claude Code Feels Different (And How to Actually Use It)

·10 min read·2,037 words
share
𝕏in

Key Takeaways

  • Claude Code runs an agentic loop (Gather context → Take action → Verify results) — not a one-shot question-answer cycle
  • The Explore → Plan → Code → Commit workflow is the difference between productive sessions and frustrating ones
  • CLAUDE.md is project memory: keep it focused like an onboarding doc, not a reference manual — every line costs context on every session
  • Five extension layers (Configuration, Permissions, Slash Commands, MCP, Hooks) are the actual product — the chat interface is just the front door
  • Subagents isolate exploration from your main context — send one whenever a task requires reading more than 3 files
This post is Part 2 of the Claude's Badges series — real-world guides to getting more from Claude.

Introduction

Most developers' first experience with Claude Code goes something like this: they install it, type a prompt, watch it do something impressive, then try a bigger task and watch it do something baffling. They conclude AI coding agents are interesting but unreliable, and go back to using a chat-based AI for snippets.

I want to argue that the problem isn't the agent. The problem is treating it like the tool it most superficially resembles — a chat AI — when it's actually a different category entirely.

This blog is about what makes Claude Code structurally different, the workflow that turns it from "interesting" to "genuinely productive," and the small set of customizations that compound over time.

---

The Category Confusion

Chat-based AI assistants are good at one thing: answering a question with text. You ask, they respond, you copy what's useful. The interaction loop is single-turn.

Claude Code is an agent. It runs a loop:

  1. 1.Gather context — read files, search the codebase, list directories
  2. 2.Take action — edit a file, run a command, create something new
  3. 3.Verify results — read the output, compare to what was expected, decide what's next

Then it repeats. And repeats. Until the task is done or it needs your input.

This is the agentic loop, and once you internalize it, everything else makes sense. The agent isn't trying to give you the right answer in one shot — it's trying to converge on a working solution by acting and observing.

Practical implication: if you give Claude Code a vague task ("clean up this code"), it will start gathering context and acting on what it finds. The quality of its work depends on how well-grounded that context is. Garbage context → garbage actions.

---

The Three Resources That Govern Everything

Three things determine what a Claude Code session can accomplish:

1. Context window — the total amount of information Claude can hold in mind at once. File reads, your messages, tool outputs all consume it.

2. Tools — what Claude can DO. Read, Write, Edit, Bash, Grep, Glob, WebFetch. Each has a specific capability.

3. Permissions — what Claude is ALLOWED to do without asking you first. You set this per-tool: allow, ask, or deny.

These three resources interact in non-obvious ways. A huge context window with no Bash permission means Claude can read everything but can't run tests. Lots of permissions but a tiny context window means Claude can act but loses track of what it's doing.

The teams getting the most out of Claude Code think about all three deliberately. The teams struggling with it think about none.

---

The Workflow That Actually Works: Explore → Plan → Code → Commit

Here's the workflow the official course teaches, and after using it for months I'm convinced it's the difference between productive sessions and frustrating ones.

1. Explore (don't write code yet)

Before touching anything, have Claude read the relevant files, understand the patterns, trace dependencies. Use a subagent so the exploration doesn't fill your main context window.

"Investigate how our authentication system handles token refresh. Don't write any code yet."

2. Plan (think before doing)

Ask Claude to outline a step-by-step plan. For complex tasks, use phrases like "think hard" or "ultrathink" — these trigger deeper reasoning at the cost of more tokens. The tradeoff is almost always worth it.

"Now plan a refactor that adds dynamic log-level support via environment variables. Think hard. Save the plan to docs/logging-plan.md."

3. Code (one step at a time)

Implement the plan piece by piece. Verify each step is consistent with the surrounding code as you go. This is where Plan Mode (toggle with Shift+Tab) earns its keep — you can review what's about to happen before it touches disk.

4. Commit (close the loop)

Have Claude write the commit message and PR description. Update the README/CHANGELOG if relevant. Close the loop cleanly so the next session starts from a good state.

The biggest mistake new users make: jumping straight to step 3. Skipping Explore and Plan produces code that ignores existing patterns and breaks things in surprising ways. Following all four steps takes the same amount of total time and dramatically improves results.

---

CLAUDE.md: Project Memory That Actually Works

There's a file called CLAUDE.md that Claude Code automatically loads at the start of every session. Most developers either ignore it or stuff it with everything they can think of. Both are mistakes.

The right mental model: CLAUDE.md is the onboarding doc you'd give a new developer joining your team. Concise, focused, immediately useful.

What belongs in it:

  • 2–4 sentences on what the codebase does
  • Tech stack and runtime versions
  • The exact commands for run, build, test (e.g., pnpm dev, not "use the dev script")
  • Code conventions specific to your project
  • Where things live (the directory structure that matters)
  • Things to avoid — anti-patterns, deprecated APIs, files Claude shouldn't touch
  • A verification protocol: what "done" means (run tests, type-check, lint)

What does NOT belong in it:

  • Long reference material that's only sometimes relevant — that goes in Skills
  • Standards anyone could find online
  • Documentation for libraries Claude already knows about

Why this matters: every line in CLAUDE.md consumes context on every session. Bloat it and you're paying for it constantly. Keep it focused and you get a multiplier effect — every prompt benefits from the same well-curated foundation.

---

The Five Extension Layers Most Users Never Touch

Here's where developers split into two camps. The first camp uses Claude Code in its default form — chat plus tools — and finds it useful but limited. The second camp learns the five extension layers, and their productivity diverges sharply from the first group.

The five layers:

  • Configuration.claude/settings.json, CLAUDE.md, environment vars. The base layer.
  • Permissions — granular allow/ask/deny lists per tool. Lets you say "Bash for npm commands is fine, but always ask before git push."
  • Custom slash commands — markdown files in .claude/commands/ that turn repeatable prompts into one-tap workflows. If you've typed the same prompt twice this week, it should be a slash command.
  • MCP servers — connections to external services (databases, GitHub, Sentry, browsers). Without MCP, Claude only knows about files. With MCP, Claude can talk to your whole stack.
  • Hooks — deterministic shell scripts that run on lifecycle events. PreToolUse, PostToolUse, SessionStart, etc. These are the difference between hoping Claude follows your rules and guaranteeing it does.

If I had to pick just one of these to start with, it's slash commands. They're the lowest-effort highest-return customization. A .claude/commands/review.md file with a 10-line prompt becomes /review, and suddenly your code review workflow is one keystroke instead of a paragraph.

---

Subagents: The Context Window Trick

Here's a feature that's underappreciated and game-changing: subagents.

A subagent is an isolated Claude instance with its own context window, spun up to handle a specific task. It does its work in a separate session and returns just a summary to the main conversation.

Why this matters: long sessions get bloated. Reading a dozen files to understand a system fills your main context with raw file content. By the time you finish the investigation, your context is full and Claude is slow.

With a subagent, the investigation happens in a parallel context. Only the conclusion comes back. Your main context stays clean.

The decision rule: if a question requires reading more than 3 files, send a subagent.

Common subagents worth building:

  • code-reviewer — read-only, reviews diffs against your standards
  • test-engineer — writes/updates tests for a given module
  • codebase-architect — answers "how does X work?" by reading the system
  • debugger — reproduces bugs and identifies root causes
  • dependency-auditor — checks deps for vulnerabilities

Build a .claude/agents/ directory with subagents tuned to your codebase, commit it, and your whole team benefits.

---

Hooks: Where Determinism Meets AI

Prompts say "please do X." Hooks make X happen unconditionally. This is a more important distinction than it sounds.

If you tell Claude in CLAUDE.md "always run prettier after editing JS files," Claude will mostly do it. Mostly. Sometimes it'll forget, especially on long sessions or when the conversation drifts.

If you write a PostToolUse hook that runs prettier --write on every Edit, prettier runs every time. It cannot be talked out of it. It cannot forget. It just runs.

Hooks fire on lifecycle events:

  • PreToolUse — before a tool runs (can block or modify)
  • PostToolUse — after a tool runs (formatters, linters, tests)
  • SessionStart / SessionEnd — boundaries (logging, context injection)
  • Stop / SubagentStop — when a response or subagent finishes

The mental model: anything that MUST happen belongs in a hook. Anything that should usually happen can stay in CLAUDE.md or a slash command.

Useful hooks worth setting up early:

  • Auto-format on edit
  • Run affected tests after code changes
  • Block dangerous Bash commands (rm -rf, etc.)
  • Audit log every tool call
  • Desktop notification when long tasks complete

---

The Cost Optimization Most Devs Miss

Quick aside that's worth knowing: Claude Code lets you set different models for different roles. Subagents can run on Haiku (fast, cheap) while implementation runs on Sonnet or Opus.

For exploration-heavy work — large codebases, lots of file reads — using Haiku for exploration subagents and Sonnet for implementation typically reduces costs 40–50% with similar quality.

Other levers:

  • --max-turns 5 for headless runs (prevents runaway loops)
  • Plan Mode for exploration (no execution = no expensive operations)
  • /compact proactively in long sessions (smaller context = fewer tokens)
  • Prompt caching on by default — verify it's enabled

These add up. Teams that don't think about cost spend a lot. Teams that do think about it spend much less for similar output.

---

The Real Mental Shift

Claude Code is a programmable platform, not a chat interface with code knowledge.

If you treat it like a chat tool — paste code, ask question, copy answer — it's an okay version of that. But you're using maybe 20% of what it can do.

If you treat it like a programmable platform — set up CLAUDE.md, configure permissions, write slash commands for repeated tasks, wire up MCP for your stack, add hooks for guarantees, build subagents for delegation — the productivity curve is completely different.

The five extension layers aren't optional polish. They're the actual product. The chat interface is just the front door.

---

Where to Start

If you're new to Claude Code, I'd suggest this order:

  1. 1.Get it running, do a few small tasks to internalize the agentic loop
  2. 2.Write a basic CLAUDE.md for one project — keep it focused
  3. 3.Try the Explore → Plan → Code → Commit workflow on a real task
  4. 4.Create your first slash command (mine was /review)
  5. 5.Add the GitHub MCP server — it transforms PR workflows
  6. 6.Write your first hook (auto-formatter is the easiest win)
  7. 7.Build your first subagent (a code-reviewer is a great starter)

Each step compounds on the previous ones. By step 7, your setup is genuinely tailored to how you work, not a generic install.

---

*Inspired by the official Claude Code 101 course — free, takes about an hour, includes hands-on exercises and a certificate.*