You have Claude Code running, and you have opened a Java project you did not write. Now the question is what to type.
In this part you will understand a module you have never seen, find the code behind one number, and add a small validation. You will see every prompt, every answer and the diff.
What you will do
You will take the orders-service project from Part 1 and treat it as someone else's code. First you ask for an overview. Then you find where an order total is calculated, and have the discount logic explained with numbers.
Last, you add one validation: a line item's quantity may not be more than 100. You ask for a plan first, let Claude Code make the change, and review it yourself.
We did not time the runs, so we give no measured range. Allow 30 to 45 minutes the first time. That is our guess, not a measurement.
You need Part 1 done, or the part-02/start folder from the example repository. You also need JDK 25, Git, and Claude Code signed in.
Every run in this article used Claude Code 2.1.316 on 31 October 2026, except the four "find" runs in Step 2, which used 2.1.330 on 22 November 2026. All runs were on Windows 11 with Git Bash, JDK 25.0.5 and Spring Boot 4.1.2. We ran them non-interactively, with claude -p, so the output below is the final answer, without the live screens. The interactive parts, such as the plan approval menu, come from the official docs and say so.
The idea: a ladder from broad to narrow
When you meet new code, you do not read every file. You ask a wide question, then a narrower one, and each answer tells you what to ask next. Figure 1 shows the ladder we use.
Steps 1 to 3 change nothing. That is on purpose. Questions are free, and they show whether Claude Code has understood the project before you let it touch a file.
The official docs give the same advice. The "Common workflows" page says: "Start with broad questions, then narrow down to specific areas". Its example first prompt is give me an overview of this codebase.
Set up a safe place to work
Before any prompt, we want a clean Git state. If something goes wrong, we can see exactly what changed, and we can throw it away.
Copy the start folder somewhere outside the repository, then start a repository of your own:
cp -r examples/claude-code-java/part-02/start orders-service
cd orders-service
git init -b main
git add -A && git commit -m "start of part 2"
git switch -c explore-discounts
./mvnw test
If you followed Part 1, you can use your own finished project and your own repository. Make a new branch either way. A branch costs nothing and lets you say "undo all of it" with one command.
The test run should end like this: 8 tests, no failures, BUILD SUCCESS. If it does not, stop here. A broken start makes every later result hard to read.
Step 1: ask for an overview
We start where the docs start. Here is our first try, run in plan mode, which is read only. Part 5 covers modes in full. For now, plan mode means "look, but do not edit".
First overview prompt
$ claude -p "Give me an overview of this codebase. Keep it under 150 words." --permission-mode plan
**orders-service** is a small Spring Boot 4.1 / Java 25 REST API for orders. It's the finished Part 1 project from the "Claude Code for Java Developers" series, and it uses an in-memory H2 database.
**Code** (`src/main/java/com/agentworks/orders`):
- `OrderController` exposes the endpoints, including create and `GET /orders/{id}`.
- `OrderService` holds the business logic. The README says the discount bug in `create` was fixed here, and it also has `findById`.
- `Order` and `OrderItem` are the entities, and `OrderRepository` handles persistence.
- `CreateOrderRequest` and `OrderResponse` are the request and response DTOs.
- `ApiExceptionHandler` and `OrderNotFoundException` return a 404 JSON problem body for unknown ids.
**Tests:** `OrderControllerTest` and `OrderServiceTest`. The README expects 8 tests with 0 failures.
**Build:** Maven wrapper. Run `./mvnw test` (or `.\mvnw.cmd test` on Windows).
**Git:** you're on branch `explore-discounts`, and the latest commit is "start of part 2".
I didn't open the Java files, so this comes from the file layout and the README.This is a fair answer, but look at its last line: "I didn't open the Java files, so this comes from the file layout and the README." It was honest, and thin. We cover why in "What went wrong". The fix is one more sentence in the prompt:
Give me an overview of this codebase. Read the source files in src/main, not only the README. Keep it under 150 words, and say which files you read.
$ claude -p "Give me an overview of this codebase. Read the source files in src/main, not only the README. Keep it under 150 words, and say which files you read." --permission-mode plan
**orders-service** is a small Spring Boot REST API for orders. It uses Spring Data JPA on an in-memory H2 database, and the schema is recreated on every start (`create-drop`).
- **API:** `OrderController` exposes `POST /orders` (validated, returns 201), `GET /orders` and `GET /orders/{id}`.
- **Pricing:** `OrderService.create` sums the line totals. Subtotals of 100 or more get 10% off, applied before the 20% tax. All amounts are rounded to two decimals, half up.
- **Persistence:** `Order` has many `OrderItem`s, cascaded. `OrderRepository` is a plain `JpaRepository`.
- **DTOs:** `CreateOrderRequest` carries the validation rules, and `OrderResponse` maps an `Order` to JSON.
- **Errors:** `ApiExceptionHandler` returns a 400 `ProblemDetail` for validation failures and a 404 for `OrderNotFoundException`.
I read all 11 files in `src/main`: the 10 Java files and `application.properties`. I also read `README.md`. I didn't read the tests.That is better in three ways. It names real behavior, such as create-drop and the 400 and 404 handling. It says which files it read. And it says what it did not read: the tests.
When Claude Code tells you what it skipped, you know where to ask next.
Step 2: find the code
Now a narrow question. Where does an order total come from? A good "find" prompt asks for a place and for proof. We asked for the file, the method and the tests that cover it.
Where is the order total calculated? Give the file and method, and name the tests that cover it.
Where the total is calculated
$ claude -p "Where is the order total calculated? ..." --permission-mode plan
The order total is calculated in `OrderService.create(CreateOrderRequest)`, in `src/main/java/com/agentworks/orders/OrderService.java:23-40`. I read the code only and didn't run the tests.
**How it works**
- **Subtotal:** it sums `OrderItem.lineTotal()` across the items (lines 28-30).
- **Discount:** an order with a subtotal of 100.00 or more gets 10% off, so exactly 100.00 qualifies. The threshold applies to the subtotal before tax (lines 32-34).
- **Tax:** 20% of the discounted subtotal (lines 35-36).
- **Total:** the discounted subtotal plus tax. `order.setAmounts(...)` stores it (line 38).
- **Rounding:** the private `money()` helper rounds each amount to 2 decimal places, half up.
The rates and threshold are the constants `TAX_RATE`, `DISCOUNT_RATE` and `DISCOUNT_THRESHOLD` (lines 13-15). `Order.setAmounts` in `Order.java:46` only stores the values.
**Tests that cover it**
`OrderServiceTest` covers the calculation directly:
- `addsTwentyPercentTaxToSmallOrders`: a 40.00 subtotal gives 8.00 tax and a 48.00 total.
- `appliesTenPercentDiscountBeforeTax`: 200.00 gives 20.00 off, 36.00 tax and a 216.00 total. It also checks that a 90.00 subtotal gets no discount and totals 108.00.
- `appliesDiscountAtExactlyOneHundred`: a 100.00 subtotal gives a 108.00 total, which exercises the `>=` boundary.
`OrderControllerTest` only touches the total through the API, asserting `$.total` is 48.00:
- `postCreatesAnOrder`
- `getByIdReturnsTheOrder`Check what you can. We opened OrderService.java and the test names matched our source. appliesDiscountAtExactlyOneHundred is a real test, and a 100.00 subtotal does give a 108.00 total: 10.00 off, 18.00 tax on 90.00.
Notice what it did not claim. It said "I read the code only and didn't run the tests." Good. If an answer claims a test passes and the transcript shows no test run, ask for the run.
Find things by meaning, not by name
You do not need the class name to find code. Describe what happens, and ask for the file and method. We ran four questions like that on the same project, all read only, with Claude Code 2.1.330 on 22 November 2026.
Where does the 404 for an unknown order come from? Give the files and methods involved, in under 100 words.
$ claude -p "Where does the 404 for an unknown order come from? ..." --permission-mode plan
The 404 for an unknown order comes from two places:
- **`OrderService.java:49`**: the lookup method calls `repository.findById(id).orElseThrow(() -> new OrderNotFoundException(id))`. It throws when no order has that ID.
- **`OrderNotFoundException.java`**: this is a `RuntimeException` that takes the order ID.
- **`ApiExceptionHandler.java:24-26`**: `handleNotFound(OrderNotFoundException)` has the `@ExceptionHandler` annotation. It returns a `ProblemDetail` built with `HttpStatus.NOT_FOUND`, which is the 404 response.
`OrderControllerTest.getByIdReturnsNotFoundForAnUnknownOrder` tests this behavior.What happens when someone posts an order with an item whose unit price is 0? Show where that is decided and what the client gets back. Under 100 words.
$ claude -p "What happens when someone posts an order with an item whose unit price is 0? ..." --permission-mode plan
A zero unit price is rejected before any order is created.
- **Where it's decided:** `CreateOrderRequest.java:21` has `@NotNull @DecimalMin("0.01") BigDecimal unitPrice`. `OrderController.java:27` triggers it with `@Valid @RequestBody`, and `@Valid` on the items list (line 16) applies it to each item.
- **What the client gets:** `ApiExceptionHandler.handleValidation` (lines 12-22) returns a 400 ProblemDetail. Its title is "Invalid order". The detail is built from the field errors, so it reads roughly `items[0].unitPrice must be greater than or equal to 0.01`.
- **Not stored:** `OrderService` is never reached, so nothing is saved.
I didn't run it. The exact message text comes from Hibernate Validator's default.Where is a customer's email checked, and what error does the client get when it is wrong? Under 100 words.
$ claude -p "Where is a customer's email checked, ..." --permission-mode plan
The email is checked by Bean Validation on the request record, at `CreateOrderRequest.java:15`. The field is `@NotBlank @Email String customerEmail`. `OrderController.java:27` triggers the check with `@Valid @RequestBody`.
If the email is wrong, Spring throws `MethodArgumentNotValidException`. `ApiExceptionHandler.handleValidation` (`ApiExceptionHandler.java:12`) turns that into an HTTP 400 `ProblemDetail`:
- **Title:** "Invalid order"
- **Detail:** `customerEmail <message>`, for example `customerEmail must be a well-formed email address`. Several field errors are sorted and joined with `; `.Verify two things yourself, with a search. First, the line numbers. We ran grep -n "orElseThrow\|DecimalMin\|@Email" src/main/java/com/agentworks/orders/*.java, and the lines matched: OrderService.java:49, CreateOrderRequest.java:21 and CreateOrderRequest.java:15. Second, the message text. "must be greater than or equal to 0.01" comes from the validation library, not from this code. Claude Code said "I didn't run it", so run the test before you quote the message.
One question did not work well. We asked with a word the project does not use:
Where is the checkout code?
$ claude -p "Where is the checkout code?" --permission-mode plan
There's no checkout code in this repo. A case-insensitive search for "checkout" matched no file contents, and the only file with it in the name is git's sample hook, `.git/hooks/push-to-checkout.sample`. That's boilerplate, not application code.
This is a small Spring Boot orders service in `src/main/java/com/agentworks/orders/`. The closest thing to checkout is order creation, which works like this:
- `OrderController.java` takes the HTTP requests.
- `CreateOrderRequest.java` defines the request body for placing an order.
- `OrderService.java` holds the business logic.
- `OrderRepository.java`, `Order.java` and `OrderItem.java` handle storage and the data model.
The repo has no cart or payment code either. If you meant something else, such as `git checkout`, a different branch, or a checkout flow that hasn't been written yet, tell me which. The commit message "start of part 2" suggests it may be the last one.It was honest: no match for "checkout", and a guess that order creation is the closest thing. But it also spent words on .git/hooks, and it ended with a question. This code calls it an order, and create is the method. The fix is the project's own words:
Where is an order created? Give the file and method.
$ claude -p "Where is an order created? Give the file and method." --permission-mode plan
An order is created in `OrderService.create(CreateOrderRequest request)`, in `src/main/java/com/agentworks/orders/OrderService.java:24`.
It is `@Transactional`. It builds the `Order` and its `OrderItem`s from the request. It then computes the subtotal, the discount (10% off when the subtotal is 100 or more) and the tax (20%), and saves the order with `repository.save(order)`.
The HTTP entry point is `OrderController.create(...)` in `OrderController.java:27`, which takes a `@Valid @RequestBody CreateOrderRequest` and calls the service.One clear answer, with a file, a method and the HTTP entry point. We checked line 24 of OrderService.java and it is the create method.
If you do not know the project's words, ask for them first. Run ls, read one controller, or ask "what are the main nouns in this codebase?". Then use those nouns.
Step 3: point at a file with @
So far we named things in words. You can also point. Type @ and a path, and Claude Code adds that file to the conversation. The path completes as you type, so you do not need the full name.
Our next prompt points at one file and asks for the rule plus a worked example:
Explain how the discount works in @src/main/java/com/agentworks/orders/OrderService.java. Show the rule, then one worked example with numbers.
The discount, explained with numbers
$ claude -p "Explain how the discount works in @src/main/java/com/agentworks/orders/OrderService.java. ..." --permission-mode plan
## The rule (`OrderService.create`, lines 28-38)
- **Subtotal:** the sum of every item's `lineTotal()`.
- **Threshold:** if the subtotal is **100.00 or more** (`>= DISCOUNT_THRESHOLD`), the order gets **10% off** (`DISCOUNT_RATE = 0.10`). A subtotal of exactly 100.00 qualifies. Anything below gets a discount of 0.00.
- **Order of operations:** the discount comes off *before* tax. Tax (`TAX_RATE = 0.20`) is then charged on the discounted amount, not the original subtotal.
- **Rounding:** every money value goes through `money()`, which rounds to 2 decimal places using `HALF_UP`.
```
discount = subtotal >= 100 ? round(subtotal × 0.10) : 0.00
taxable = subtotal − discount
tax = round(taxable × 0.20)
total = taxable + tax
```
The threshold test uses the raw, unrounded subtotal. `order.setAmounts` stores the rounded subtotal, the discount, the tax and the total.
## Worked example
An order with 2 × 40.00 and 1 × 70.00:
| Step | Calculation | Result |
|---|---|---|
| Subtotal | 80.00 + 70.00 | 150.00 |
| Qualifies? | 150.00 ≥ 100.00 | yes |
| Discount | 150.00 × 0.10 | 15.00 |
| Taxable | 150.00 − 15.00 | 135.00 |
| Tax | 135.00 × 0.20 | 27.00 |
| **Total** | 135.00 + 27.00 | **162.00** |
Tax applies after the discount, so the customer pays 162.00. Taxing the full subtotal would have given 150.00 − 15.00 + 30.00 = 165.00.The worked example checks out. Two items at 40.00 and one at 70.00 give 150.00. The discount is 15.00, the taxable amount is 135.00, the tax is 27.00, and the total is 162.00.
Do the sum by hand once. It takes a minute, and it tells you whether to trust the next answer.
What @file and @folder add
The docs describe the two kinds of reference like this. From the common workflows page, read on 31 October 2026: a file reference "includes the content of the file in the conversation when it fits the Read tool's token limit, 25,000 tokens by default. A text file larger than 256KB isn't included." And for folders: "Directory references show file listings, not contents".
Figure 2 puts the two side by side, with the case where you use no @ at all.
| You type | What is added |
|---|---|
@src/.../OrderService.java | The file's contents, if it fits the read limit. |
@src/main/java/com/agentworks/orders | A listing of file names. No contents. |
| "the order service" | Nothing yet. Claude Code searches and reads files itself. |
Two more facts from the same page. Per the docs, an @ file reference also adds CLAUDE.md files from that file's directory and its parent directories. Part 4 is about that file.
And you can switch off the contents and listings with the CLAUDE_CODE_DISABLE_FILE_MENTIONS setting. We did not use it.
One caveat about our own runs. We used claude -p, and we cannot tell from the output alone whether the @ path was expanded by Claude Code or read by the model with a tool. The answer cites line numbers, which means the file was read either way. We did not capture an interactive screen, so we do not describe one.
Step 4: give constraints
Now the change. A change prompt that says only "add validation" leaves too much open. Which field? How large a limit? Which file? Should it add classes? Whether to add tests?
We use four kinds of constraint, and the prompt below has all four:
- What to change. One field, one limit.
- Where. The file where the annotation goes, by
@reference. - What not to touch. No new classes, and
OrderServicestays as it is. - The check. One test, in the style of the existing tests.
And we ask for a plan, not an edit.
Add one validation: a line item's quantity may not be more than 100. Constraints: use a Bean Validation annotation on @src/main/java/com/agentworks/orders/CreateOrderRequest.java, add no new classes, do not touch OrderService, and add one test to @src/test/java/com/agentworks/orders/OrderControllerTest.java in the style of the existing tests. Do not edit anything yet. Give me a short plan: the files you will change, the exact change in each, and how you will check it.
The plan, before any edit
$ claude -p "Add one validation: ... Do not edit anything yet. Give me a short plan ..." --permission-mode plan
## Plan (nothing edited yet)
I read both files. I saved the plan to `C:\Users\Dell\.claude\plans\add-one-validation-a-elegant-ocean.md`. I couldn't call ExitPlanMode in this session, so tell me when to go ahead.
**1. `src/main/java/com/agentworks/orders/CreateOrderRequest.java`**
- Line 20 changes from `@Min(1) int quantity` to `@Min(1) @Max(100) int quantity`.
- Add `import jakarta.validation.constraints.Max;` above the `Min` import.
- `items` is already `List<@Valid Item>`, so the new constraint applies with no other wiring.
**2. `src/test/java/com/agentworks/orders/OrderControllerTest.java`**
- Add `postRejectsAQuantityOverOneHundred`, written like `postRejectsAnOrderWithoutItems`. It posts one item with `"quantity": 101` as an inline JSON string.
- It expects `status().isBadRequest()` and `jsonPath("$.title").value("Invalid order")`.
- It needs no new imports or helpers.
`OrderService` and the rest of the project stay as they are, and I add no new classes.
**How I'll check it**
- Run `OrderControllerTest` with the repo's build tool (`./mvnw test -Dtest=OrderControllerTest` or the Gradle equivalent). The new test and the five existing ones should all pass.
- Optionally, I'll change the new test's quantity to 100 and confirm it returns 201, so the limit is exactly "more than 100". Then I'll change it back.
I haven't confirmed that the handler returning "Invalid order" covers item-level violations. The empty-items test suggests it does, and the test run will show it.Read the plan as a reviewer. Is the change small? Yes: one annotation, one import, one test. Does it match your constraints? Yes. Does it say how it will check? Yes.
It also admits what it was unsure about: whether the error handler covers item-level violations. That honesty is useful, because it tells you what to watch in the test run.
Run git status now. In our run it printed nothing. Plan mode had edited no project files, which is the point of plan mode.
The interactive version of this step
In the terminal interface, plan mode ends differently. We did not capture that screen, so this comes from the permission modes page, read on 31 October 2026.
You enter plan mode with Shift+Tab, by starting with claude --permission-mode plan, or by prefixing one prompt with /plan. The status bar shows that plan mode is on. When the plan is ready, Claude Code asks how to proceed. The docs list these choices:
- Yes, and use auto mode. If auto mode is not available to your session, this reads Yes, auto-accept edits.
- Yes, manually approve edits. You approve each edit one by one.
- No, keep planning. You stay in plan mode and say what to change.
The page also says Ctrl+G opens the plan in your text editor, so you can change it before Claude Code starts. Our advice for a first pass: choose the manual option, so you see each edit.
Step 5: make the change
We approved the plan. In an interactive session you would pick one of the options above. In our non-interactive run we started a new claude -p call that allowed edits and allowed one command: ./mvnw test. Narrow permissions are a habit we will build on in Part 5.
Go ahead with the plan: add the quantity limit of 100 and the one test. Then run ./mvnw test and tell me the result in two sentences.
$ claude -p "Go ahead with the plan: ..." --permission-mode acceptEdits --allowedTools "Bash(./mvnw test*)"
`./mvnw test` passed: 9 tests ran with no failures or errors, and the build succeeded. I added `@Max(100)` to `quantity` in `CreateOrderRequest.java` and one test in `OrderControllerTest`, which checks that a quantity of 101 returns 400 "Invalid order".
I didn't have the plan from the earlier conversation, so I took "quantity limit of 100" to mean a maximum of 100 per line item. Tell me if you meant a different limit, such as a total across the whole order.Look at the second paragraph. It says: "I didn't have the plan from the earlier conversation, so I took 'quantity limit of 100' to mean a maximum of 100 per line item." We come back to that in "What went wrong". It guessed right, and it told us it was guessing.
Step 6: review with /diff
Do not trust the two-sentence summary. Read the change, and run the tests yourself. In an interactive session, start a line with ! to run a shell command and add its output to the session, for example !./mvnw test. The interactive mode page, read on 22 November 2026, lists ! as shell mode. We did not use it in our -p runs. In Claude Code, /diff shows the changes in your working tree, including the edits Claude has made so far. The commands page describes it as "Review the changes in your working tree, including the edits Claude has made so far."
We ran the non-interactive session, so there was no /diff screen to show. The plain Git command shows the same changes:
git diff
diff --git a/src/main/java/com/agentworks/orders/CreateOrderRequest.java b/src/main/java/com/agentworks/orders/CreateOrderRequest.java
index d646c9a..7a78b8f 100644
--- a/src/main/java/com/agentworks/orders/CreateOrderRequest.java
+++ b/src/main/java/com/agentworks/orders/CreateOrderRequest.java
@@ -3,6 +3,7 @@ package com.agentworks.orders;
import jakarta.validation.Valid;
import jakarta.validation.constraints.DecimalMin;
import jakarta.validation.constraints.Email;
+import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotEmpty;
@@ -17,7 +18,7 @@ public record CreateOrderRequest(
public record Item(
@NotBlank String productName,
- @Min(1) int quantity,
+ @Min(1) @Max(100) int quantity,
@NotNull @DecimalMin("0.01") BigDecimal unitPrice) {
}
}
diff --git a/src/test/java/com/agentworks/orders/OrderControllerTest.java b/src/test/java/com/agentworks/orders/OrderControllerTest.java
index 8b45302..711c2b9 100644
--- a/src/test/java/com/agentworks/orders/OrderControllerTest.java
+++ b/src/test/java/com/agentworks/orders/OrderControllerTest.java
@@ -41,6 +41,17 @@ class OrderControllerTest {
.andExpect(jsonPath("$.title").value("Invalid order"));
}
+ @Test
+ void postRejectsAQuantityOverOneHundred() throws Exception {
+ mvc.perform(post("/orders").contentType(MediaType.APPLICATION_JSON)
+ .content("""
+ {"customerEmail": "ana@example.com",
+ "items": [{"productName": "Keyboard", "quantity": 101, "unitPrice": 20.00}]}
+ """))
+ .andExpect(status().isBadRequest())
+ .andExpect(jsonPath("$.title").value("Invalid order"));
+ }
+
@Test
void getListsOrders() throws Exception {
mvc.perform(post("/orders").contentType(MediaType.APPLICATION_JSON).content(ONE_ITEM))
Thirteen lines added and one removed, in two files. Check the list:
- The annotation is
@Max(100), so 100 is allowed and 101 is not. That matches "not more than 100". - The import is the one the annotation needs.
OrderService.javais not in the diff, as we asked.- No new classes.
- The test posts 101 and expects 400 with the title
Invalid order, like the neighboring test.
Now run the tests yourself. Do not rely on the summary:
./mvnw test
[INFO] Tests run: 6, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 8.665 s -- in com.agentworks.orders.OrderControllerTest
[INFO] Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.381 s -- in com.agentworks.orders.OrderServiceTest
[INFO] Tests run: 9, Failures: 0, Errors: 0, Skipped: 0
[INFO] BUILD SUCCESS
[INFO] Total time: 17.380 s
Nine tests, up from eight. The new test passed, so the error handler does cover item-level violations, which is what the plan was unsure about.
One gap the test does not close
The new test checks that 101 is rejected. It does not check that 100 is accepted. If someone changes @Max(100) to @Max(99), this test still passes.
It is a small gap, and it is a real one. This is exactly what the general advice in Part 1 meant by a test that is too weak. We left the code as Claude Code wrote it, and Exercise 1 asks you to close the gap.
Commit when you are happy:
git add -A
git commit -m "Limit line item quantity to 100"
Figure 3 shows the loop we just followed. The orange boxes are your decisions.
What went wrong
Not everything went smoothly. Two things are worth your time.
The first overview read no code. Our short prompt, "Give me an overview of this codebase", got an answer built from the file names and the README. It said so, in its last sentence. But the answer also repeated README claims, such as "The README says the discount bug in create was fixed here", which is history, not design.
We do not know why it skipped the source. The prompt did not ask it to read any.
The fix is the sentence we added: read the source files, and say which ones. If an overview names no files it read, ask for them.
A new run forgot the plan. Each claude -p call starts a new conversation. So "Go ahead with the plan" reached a session that had never seen a plan. It guessed from the words and was right, and said it was guessing.
The docs say a later call continues an earlier conversation only if you pass --continue or --resume with a session ID (the headless page, read on 31 October 2026). In an interactive session the plan stays in the conversation and this does not happen. If you script -p calls, repeat the details or continue the session.
There was a second surprise in the planning run. Our output said it had saved the plan to a file in the .claude/plans folder in our home directory, outside the project. git status stayed clean, since the file is not in the repository. But it is a side effect that you may not expect from a "read only" mode, so now you know.
Stay in control
Here is the safety habit for this part: explore in plan mode, and check that nothing changed.
- Start unfamiliar work with
--permission-mode plan, or pressShift+Tabuntil the bar says plan mode. - After the read-only questions, run
git status. It should print nothing. - Before any edit, read the plan and compare it with your constraints.
- After the edit, read the diff and run the tests yourself.
Also keep secrets out of prompts and files you point at. An @ reference sends that file's content to the model. Do not point at a file that holds a password or a key.
Keep sessions healthy
Start a new conversation for each new task. Old answers about the discount code only add noise when you move on to something else.
Two commands help. Both are from the commands page, read on 22 November 2026:
/clear: "Start a new conversation with empty context."/compact: "Free up context by summarizing the conversation so far."
If answers start to drift or repeat, try /clear and restate the task in one prompt. The docs give no size at which to do it, so we do not either. Part 3 covers commands and shortcuts in full.
Cheat sheet
| Command, key or prompt | What it does |
|---|---|
claude --permission-mode plan | Starts a session in plan mode: read and propose, no edits. |
Shift+Tab | Cycles the permission mode. From manual it goes to accept edits, then plan. |
/plan followed by a description | Enters plan mode for one task. |
@path/to/File.java | Adds that file's contents to the conversation. |
@path/to/folder | Adds a listing of file names only. |
/diff | Shows the changes in your working tree, including Claude's edits. |
git status, git diff | Your own check that nothing unexpected changed. |
claude -p "prompt" | Runs one prompt non-interactively and prints the answer. |
!command | Runs a shell command from the prompt and adds its output to the session. |
/clear | Starts a new conversation with empty context. |
/compact | Summarizes the conversation to free up context. |
Describe what happens, then ask for the file and method. | A find-by-meaning prompt. Use the project's own nouns. |
Give me an overview of this codebase. Read the source files, and say which you read. | Broad first question. |
Where is X calculated? Give the file, the method and the tests. | A find prompt that asks for proof. |
Explain @File.java. Show the rule, then a worked example with numbers. | An explain prompt you can check by hand. |
Change X. Constraints: ... Do not edit anything yet. Give me a plan. | A change prompt with constraints that asks for a plan. |
Try it yourself
Three exercises on the same project. Start each from a clean branch.
- Close the test gap. Ask Claude Code to add a test that a quantity of exactly 100 is accepted. Hint: say "add one test, next to the existing 101 test, do not change the annotation". A good result is a test that posts 100 and expects 201. To prove the test works, change
@Max(100)to@Max(99)by hand, run the tests, see the new test fail, and change it back. - Explore a folder with a listing. Ask: "What's in @src/main/java/com/agentworks/orders and what does each file do? Do not edit anything." Hint: a folder reference gives names only, so a good result reads a few files before it answers. Check it by asking which files it opened.
git statusstays clean. - Plan a second validation. Ask for a plan, with no edits, to reject an order with more than 20 line items. Hint: give the same four constraints (what, where, what not to touch, the check). A good result names
CreateOrderRequest, picks a size constraint on theitemslist, and proposes one test. Then decide: edit it, or say "No, keep planning" and refine.
What comes next
Next is Part 3, Shortcuts and Commands You Will Use Every Day. It covers the keys and commands that make a session faster: interrupt, rewind, background tasks, clearing and resuming.
You can go back to Part 1 at any time. To follow along, subscribe to the RSS feed, or follow @agentworkshq on X or @agentworkshq on Instagram. The series page has the current list.