DS DevShelfHub Projects · AI tools
Tutorials / Claude Code / Agentic Loop
Claude Code Beginner · 9 min read Page 4 of 25

The Agentic Loop in Practice

By DevShelfHub

Now you'll watch the loop run for real: how Claude gathers context, takes action, and verifies its own work — and just as importantly, how you stay in the loop by interrupting, steering, and choosing the right permission mode.

Series progress4 / 25
Claude Code agentic loop tutorial — gather context, take action, verify, and permission modes

The three phases, observed

Every task you hand Claude flows through the same loop. The difference now is that you'll watch each phase happen and learn to read what Claude is doing.

1

Gather context

Claude reads files in your source directory, searches for patterns with grep and glob, checks git status and recent history, and reviews CLAUDE.md before forming a plan.

2

Take action

Claude edits files and runs commands — but only within your permission mode. In default mode it asks first, and you can Approve, Deny, or modify the proposed action.

3

Verify results

Claude runs tests, reads the output, and iterates. When a test fails it traces the cause, adjusts the code, and runs again — without you having to ask.

Try each phase yourself

Give these prompts in a real project and watch which phase each one exercises:

text
# Gather context
> Find all the places we handle user authentication and explain the flow.

# Take action
> Add input validation to the user registration form — validate email
  format and require password length >= 8.

# Verify results
> Run the test suite and fix any failures.

With the first prompt you'll see Claude read multiple files and trace function calls before answering. With the third, watch it run the suite, read failures, and fix them in a tight verify-and-retry cycle.

Interrupting and steering

You are part of the loop, not a spectator. At any point you can give Claude new direction — it stops immediately and adjusts. This is essential: don't wait for Claude to finish if it's heading the wrong way. Interrupt early, especially when you notice it reading the wrong files.

Effective mid-session steering sounds like this:

text
> Stop — that approach will break the caching layer. Use the existing
  SessionManager instead.

> That test is passing but it's not testing the right thing. Rewrite the
  assertion.

> Before you continue, explain your plan for the remaining files.

Keys to know: Esc interrupts mid-action, and Esc Esc rewinds to a previous checkpoint when you don't like a change.

The four permission modes

Cycle modes with Shift+Tab. The mode you're in decides how much Claude can do without stopping to ask — match it to how much you trust the task.

Mode Behaviour Use when
Default Asks before file edits and shell commands Learning, or any task you want to watch closely
acceptEdits Edits files freely, still asks for shell commands You trust the edits but want a gate on commands
Plan Read-only exploration; produces a plan for your approval Complex or architectural tasks, before any edits
Auto Evaluates all actions with a background safety classifier (research preview) Trusted, well-scoped work you want to run hands-off

For anything you don't fully understand yet, reach for plan mode first — press Shift+Tab twice, then prompt:

text
> Review src/auth/ and plan an OAuth integration.

Practice and pitfalls

Three exercises to build the right instincts:

  • Give Claude a bug-fix task, then interrupt mid-way to change the approach.
  • Use plan mode to analyse a module before letting Claude edit anything.
  • Make a change, then rewind it with Esc Esc.

And the common mistakes to steer clear of:

  • Letting long tasks run unchecked while in default mode without watching the checkpoints.
  • Ignoring Claude's visible tool use — its reasoning is on screen, and it's valuable.
  • Treating every prompt as a one-shot command instead of a steerable conversation.

Claude Code Agentic Loop FAQ

What is the agentic loop in Claude Code?

The agentic loop is the repeating cycle every task runs through: gather context, take action, and verify results. Claude reads files and git history, edits code and runs commands, then runs tests and iterates until the task is done.

How do I interrupt Claude Code mid-task?

Press Esc to interrupt Claude mid-action, then give new direction — it stops immediately and adjusts. Press Esc Esc to rewind to a previous checkpoint when you don't like a change. You are part of the loop, not a spectator.

What are the four permission modes in Claude Code?

The four modes are default (asks before edits and commands), acceptEdits (edits freely, still asks for shell commands), plan (read-only, produces a plan for approval), and auto (evaluates actions with a background safety classifier). Cycle them with Shift+Tab.

When should I use plan mode?

Reach for plan mode for anything complex, architectural, or unfamiliar, before any edits are made. Press Shift+Tab twice to enter it, then prompt Claude to review the relevant code and produce a plan you approve first.

Does Claude Code fix its own test failures?

Yes. In the verify phase Claude runs tests, reads the output, and iterates. When a test fails it traces the cause, adjusts the code, and runs again without you having to ask — a failing test is just another signal to gather context and retry.

Quick summary

  • Every task runs the loop: gather context → take action → verify results
  • You're part of the loop — interrupt with Esc and steer Claude any time
  • Four permission modes (default, acceptEdits, plan, auto) gate what Claude does — cycle with Shift+Tab
  • Use plan mode first for anything complex or unfamiliar