Learning to Communicate with Claude
A coding agent is only as good as the task you hand it. This page teaches how to give an agent what it cannot find for itself — intent, constraints and a way to check its work — using Spring examples from the bookshelf project. The guidance follows Anthropic's Claude Code best-practices page; the failing outputs are real failures captured while building the project.
You Are Delegating, Not Dictating
Anthropic's advice for Claude Code is to treat it like a capable colleague: give context and direction, then let it work out the details (Source 1). You do not need to say which files to read or which commands to run; Claude searches the repository itself.
What it cannot do is read your mind or your team's meetings. The best-practices page puts the dividing line precisely: Claude can find what is in the repository, so write down only what it cannot see (Source 2).
Five Parts of a Good Task Prompt
Not every prompt needs all five, but a request that fails usually lacks one. These are this guide's names for patterns that Anthropic's pages describe in other words: naming the file and symptom, saying what fixed looks like, pointing at a pattern to follow, stating constraints, and giving a check to run (Source 2).
| Part | Question it answers | bookshelf example |
|---|---|---|
| Objective | What should be true afterwards? | "Add GET /api/books/{id} that returns one book." |
| Context | Where, and what is happening now? | "Listing is in BookController; unknown ids currently give a 500." |
| Constraints | What must not change, what to follow? | "Follow the existing controller style. No new libraries. Don't change the DTO." |
| Outcome | How will we know it is right? | "Unknown id returns 404 with a ProblemDetail body." |
| Check | What can Claude run to find out? | "Run ./mvnw -B test and show me the output." |
Vague Prompts vs. Engineering Prompts
The docs' own example pair is "fix the login bug" versus a prompt that names the symptom, the code area, a failing test and the fix (Source 2). Here are four in the bookshelf project.
Which verb, which path, what for a missing id, what shape of response, any tests?
Invites edits to the tests rather than the code, and gives no hint of what "broken" means.
Where? Which rules? What should the client see?
"Faster" has no measure, so any change can be called done.
Hand Over What You Have
When you already hold the thing Claude needs, give it rather than describe it (Source 2):
- A file: type
@src/main/java/com/example/bookshelf/BookService.javato include its contents. The Read tool's default limit for this is 25,000 tokens, and a text file over 256KB is not included (Source 3). - An image: paste a screenshot of the error or design.
- Command output: pipe it from your shell, for example
cat error.log | claude -p "what's going on here".
These were captured while building version 2. Each is exactly the kind of thing worth pasting into a prompt.
Notice what each contains: the exact error, the place it came from, and what was expected. A prompt that includes input 1 plus "the app is Spring Boot with H2; find the cause" gives the agent a precise starting point instead of a guess. Chapter 9 resolves all three.
Explore, Plan, Implement, Verify
For anything bigger than a one-line change, split the work. The documentation's tips are consistent: let Claude explore before changing; give step-by-step instructions for complex tasks; and use plan mode when you want to review an approach before anything touches disk (Source 4, Source 5).
In plan mode Claude reads and proposes a plan but makes no edits until you approve. Enter it with Shift+Tab (the status bar shows ⏸ plan mode on), by prefixing a message with /plan, or at start-up with claude --permission-mode plan. Press Ctrl+G to edit the plan in your editor before approving (Source 5).
A good plan names the open question rather than hiding it. Answer it, edit anything you disagree with, and only then approve implementation. Anthropic's best-practices page adds an interview variant for when you do not yet know what you want: ask Claude to interview you until it could write the spec, write it to a file such as SPEC.md, and start a fresh session to build from it (Source 2).
Read What It Proposes
In Manual mode every edit and command prompts you; the prompt shows what Claude is about to do. Read it. In the VS Code extension, proposed edits appear as side-by-side diffs you can accept or reject per change (Source 6). After the work, review the full diff with Git: git diff shows what changed regardless of which tool changed it.
| Review question | Why |
|---|---|
| Did it change only the files the task needed? | Unrelated edits are scope creep and hide risk. |
| Does a test fail without the change? | A test that cannot fail proves nothing. |
| Did it edit or delete tests to make them pass? | The classic failure when "fix the tests" is the prompt. |
| Any new dependency, config or permission? | Supply-chain and security surface. |
| Does the evidence match the claim? | Ask for the command and its output, not a summary. |
For a second opinion, Anthropic suggests asking a subagent to review the diff against your spec — and to skip style, because a reviewer asked to find problems will always find something (Source 2):
Debugging Through Conversation
You rarely get it right in one prompt, and you do not have to: "when the first attempt isn't right, you don't start over. You iterate" is how the how-it-works page describes it (Source 1). The controls:
Escstops Claude immediately and keeps the conversation.- Type while it works. A message sent during a run is queued and read as soon as the current tool calls finish, so you can correct course without stopping.
- Rewind. Press
Esctwice (or use/rewind) to restore file changes and conversation to an earlier checkpoint. Checkpoints cover file edits only. - Start clean.
/clearbetween unrelated tasks; stale context costs tokens and attention.
Using the real output from Section 4, a good exchange has this shape. The replies are illustrative; the first message and the evidence it cites are real.
Two habits make this work. First, the human asked for the diagnosis before the fix, so a wrong theory could be corrected cheaply. Second, the verification is a test that already existed. The actual fix and the real before/after counts (4 then 1) are in Chapter 9.
Prompting an Agent
Key Takeaways, Exercises and Sources
- Delegate, but tell it what it cannot see: intent, decisions, constraints and what done means.
- Five parts: objective, context, constraints, outcome, check. The check matters most.
- Paste real evidence — the failing assertion, the stack trace — not a paraphrase.
- Explore, plan, implement, verify for anything non-trivial; plan mode makes the plan reviewable.
- Review the diff, not the summary, and ask for command output as evidence.
- Iterate. Interrupt early, rewind when needed, and clear context between tasks.
Exercise 1 Beginner
Rewrite these three vague prompts as engineering prompts for the bookshelf project: "add search", "it's slow", "write some tests". For each, label which of the five parts you added.
Learning outcome: recognise missing prompt parts.
Exercise 2 Intermediate
In plan mode, ask Claude to plan pagination for GET /api/books without editing. Read the plan, find one assumption you disagree with, edit the plan (Ctrl+G), and only then approve. Record what changed between the first plan and the one you approved.
Learning outcome: use plan mode as a review checkpoint, not a formality.
Exercise 3 Advanced
Introduce a bug in the project on purpose (for example, sort listing by year instead of title). Give Claude two prompts: one vague ("books are in the wrong order") and one precise with the failing assertion pasted in. Compare the number of corrections each needed and which one touched files it should not have.
Learning outcome: measure, rather than assume, how prompt quality changes the result.
- Anthropic, How Claude Code works — delegating, interrupting and steering, checkpoints.
- Anthropic, Best practices for Claude Code — tell Claude what it cannot see, specific prompts, checks, spec interviews, review prompts. The page was read in part; later sections were not.
- Anthropic, Common workflows —
@references and limits, piping, plan mode, worktrees. - Anthropic, Quickstart — prompt examples and "pro tips".
- Anthropic, Permission modes — entering plan mode, editing the plan.
- Anthropic, VS Code extension — inline diffs and per-change accept/reject.
The three "real input" blocks are verbatim excerpts from commands run on this machine on 2026-10-30 (Spring Boot 4.1.2, H2, OpenJDK 21.0.2). The plan and the debugging conversation are illustrative text written for this guide; no Claude Code session was run. Anthropic's general prompt-engineering guide for Claude models was fetched but only skimmed, so this page relies on the Claude Code pages above.