Keeping an 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 I write code myself, my hands follow my brain. When I use an agent, my value shifts to defining the goal and reviewing the result. Not typing faster.
So how do I 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 planDuring a session, I hit Shift+Tab to toggle between Plan and Accept-Edits. Or I just type /plan.
Why explore first? Claude’s understanding of the project depends entirely on what context I give it. I let it read the relevant files and build a map before deciding what to change. Way more reliable than me 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.
I don’t need to be dogmatic about it though. For trivial tasks — fixing a typo, renaming a variable, adding a log line — I just ask Claude to do it directly. The official docs say the same: if I can describe the diff in one sentence, I skip the plan.
Step two: turn exploration into a plan
After Claude finishes exploring, I don’t let it start coding right away. I 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, I 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 me, routine ones proceed automatically. I start with claude --permission-mode auto. Good when I 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, I hit Shift+Tab to switch to Accept-Edits mode. Claude can work without asking me for permission on every step, which is much faster.
Key tip: I don’t ask it to implement the whole plan at once. One function at a time. Or I 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 I 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 I’d miss otherwise
Once this loop became habit, I noticed most of my energy goes into “explore” and “plan.” The “code” part is the easiest step. That’s the right rhythm for me — think before I act.