Building with agents, lesson 4.3
Working well from the command line
Most of what makes an agent in your terminal work well is a handful of habits. This lesson follows one session from the first prompt to a scripted run, and shows which habit fixes which mistake.
Every example below changes to fit what you pick. The businesses are made up for teaching.
The picture, one step at a time
Each box is one stage. The picture lights up as you scroll.
A command-line session, from the first prompt to a scripted run
1Start specific
The file, the symptom and what done looks like. Hand over logs and files, do not describe them.
2Watch the first minute
Stop it the moment it drifts. Roll back if you need to.
3Give it a check
A command that comes back pass or fail, and its output as proof.
4One job per session
Clear between unrelated jobs, and after two failed corrections.
5Script the repeats
A job you do often runs once from a script, with limits, and exits.
Name the file, the symptom and what done means.
Step 1 of 6
Say what only you know
The agent can read your code, but not your head. For fixing the checkout, say which file, what goes wrong and what fixed looks like. If you already have the thing it needs, hand it over: point it at the file, paste the screenshot, or pipe the error output straight in.
Claude Code's guide (November 2026) gives the pattern: instead of "fix the login bug", write what fails, where to look, and "write a failing test that reproduces it, then fix it". You can pipe output in with cat error.log | claude -p "what's going on here".
Step 2 of 6
Watch the first minute
Most wrong turns show early. Watch the first minute, and stop it the moment it heads somewhere you did not mean. Stopping keeps the work so far, so you redirect rather than start again. If it already went too far, roll back to an earlier point.
In Claude Code, Esc stops it mid-action. Esc twice, or /rewind, rolls the code, the conversation or both back. Changes made by shell commands are not rolled back, so keep using git.
Step 3 of 6
Give it something that passes or fails
An agent stops when the work looks done. Give it a check it can run, such as a test, a build or a linter, and it can find and fix its own mistakes before it reports back. Then ask for proof: the command and its output, not "all good".
Which is the best last line of a prompt?
Step 4 of 6
One job per session
Every request sends the whole conversation. A session that has done three unrelated jobs rereads all three on every turn of the fourth, and its answers drift towards old work. Clear between unrelated jobs. And if you have corrected the same thing twice, clear and write one better prompt rather than trying a third time.
In Claude Code that is /clear, or /compact to keep a short summary. The guide's rule: after two failed corrections, /clear and a better prompt "works better almost every time".
You have corrected the same mistake twice and it is still wrong. What next?
Step 5 of 6
Choose how much it asks first
You decide how much it does before asking you. It can ask before every edit and command, only plan and read until you approve, or run a set of approved actions on its own. Start careful on a new job, and loosen it only where it has earned it.
Claude Code has permission modes for this (as of November 2026), from one that asks before most edits and commands, to plan mode, which reads and proposes but cannot edit. Shift+Tab moves between them.
Step 6 of 6
Script the jobs you repeat
When you have run the same job by hand a few times, turn it into one command that runs, does the job and exits, ready for a script, a scheduled job or a check before every commit. Give it a limit on turns, only the tools it needs, and a place to put the result where a person will see it.
In Claude Code that is claude -p "your prompt" (print mode), with flags such as --max-turns, --allowedTools and --output-format json. Before a run goes unattended, the guide asks: does it know what done looks like, can it check itself, what may it touch, what stops it, and who signs off?
Which habit fixes it?
Here are four things that went wrong in a session in your business. Sort each one into the habit that would have fixed it.
1You type "fix the checkout" and it changes the basket page, which was fine.
2In the first minute you see it start editing the payments settings, which this job should not touch.
3It says the discount fix works. It never ran anything to find out.
4After two hours on stock reports, you ask about the order emails and it keeps bringing up stock.
0 of 4 right so far, 4 to go.
The command-line habits card
This is what you keep: six habits for every session, on one card.
The command-line habits card
- Start each job with the file, the symptom and what done looks like. Hand over logs and files rather than describing them.
- Watch the first minute, and stop it the moment it drifts. Keep using git, so any change can be undone.
- Give it a command that passes or fails, and ask for the command and its output as proof.
- One job per session: clear between unrelated jobs.
- After two failed corrections, clear and write one better prompt instead of a third.
- For a job you repeat, script it: one run, a turn limit, only the tools it needs, and a person who reads the result.
Before you walk away from a run, it must know what done looks like, be able to check itself, touch only what it should, and have something that stops it.
Next: Lesson 5.1: CLAUDE.md and AGENTS.md: what goes where. The house rules file every session reads, and what belongs in it.