Keeping Your Agent on Track with Plan → Code

When I first started using Claude Code, I had a bad habit: open the terminal, type one sentence telling it what to change, watch it go, and realize later it went in the wrong direction.

Here’s what I learned — agentic coding is a different skill from writing code. When you write code yourself, your hands follow your brain. When you use an agent, your value shifts to defining the goal and reviewing the result. Not typing faster.

So how do you keep an agent from drifting? I settled on four steps: explore → plan → code → commit.

Step one: explore first, touch nothing

Plan mode is Claude Code’s read-only mode. Start with:

claude --permission-mode plan

During a session, hit Shift+Tab to toggle between Plan and Accept-Edits. Or just type /plan.

Why explore first? Claude’s understanding of your project depends entirely on what context you give it. Let it read the relevant files and build a map before deciding what to change. Way more reliable than you guessing “go edit that file” from memory.

For tricky architectural questions, I add “think carefully before proposing anything” to the prompt. The more thorough the upfront reasoning, the less backtracking later.

Don’t be dogmatic about it though. For trivial tasks — fixing a typo, renaming a variable, adding a log line — just ask Claude to do it directly. The official docs say the same: if you can describe the diff in one sentence, skip the plan.

Step two: turn exploration into a plan

After Claude finishes exploring, don’t let it start coding right away. Have it write down what it found, what needs to change, and how.

I ask Claude to put open questions into a planning.md, answer them, and iterate. The plan should cover:

  • Which parts of the code need changes
  • What the approach is for each one
  • What’s uncertain — flag it for me to decide

Once the plan looks right, let it proceed. Tasks with good plans usually land in one pass. No need to go back and fix things.

There’s also Auto mode — Claude uses a classifier to decide what’s safe. Risky operations still ask you, routine ones proceed automatically. Start with claude --permission-mode auto. Good when you trust the general direction but don’t want to click through every step.

Step three: implement one piece at a time

After the plan is approved, hit Shift+Tab to switch to Accept-Edits mode. Claude can work without asking for permission on every step, which is much faster.

Key tip: don’t ask it to implement the whole plan at once. One function at a time. Or have it stub all functions first, then fill them in one by one.

If one function goes sideways, the cost of correcting is small. If it changed 10 files and the first assumption was wrong, rolling back hurts.

Step four: clean commits

Claude has auto-commit, but I don’t rely on it.

Manual git add and git commit at logical checkpoints beats auto-commit every time:

  • Some changes you’ll want to discard after review — clean commits make that a one-liner
  • Each commit does one thing, reviewers can follow it
  • Scanning the diff before committing catches security issues you’d miss otherwise

Once this loop becomes habit, you’ll notice most of your energy goes into “explore” and “plan.” The “code” part is the easiest step. That’s the right rhythm — think before you act.

Article Link:

/en/archive/claude-code-plan-code-loop/

# Related Articles