Chapter 4
How to Ask Well (Prompt Engineering for the Terminal)
Imagine a brilliant new colleague just joined you. They can do almost anything, but it's their first day: they don't know the project, don't know what you like and don't know what you've already tried. Tell them "fix up the site" and they'll guess. Tell them exactly what, where, and how you'll know it worked, and they'll deliver great results the first time.
Claude is exactly that colleague. A prompt is simply the request you write to it, and prompt engineering is the craft of writing requests that work. Don't worry: there's no magic and no code words. Just a few simple habits that make a huge difference.
Why does wording matter so much?
Two reasons:
- Claude can't read minds. It's very good at understanding intent, but when information is missing it fills the gap with a guess. Sometimes the guess is great, and sometimes it builds something beautiful that's exactly not what you wanted.
- Every correction costs. Remember the "whiteboard" from the previous chapter, the context window? Every round of "no, I meant..." fills it up. The fuller the board, the more Claude may "forget" early instructions and make mistakes.
The golden rule: four principles
Every good prompt answers four questions. Small requests don't need all of them, but the bigger the task, the more they matter.
| Principle | The question to answer | In short |
|---|---|---|
| 1. Specificity | What exactly do I want, and where? | "Improve it" → "Make the headline bigger and color it blue" |
| 2. Context | What does Claude need to know to succeed? | Files, examples, errors, constraints |
| 3. Step by step | In what order should it work? | First investigate, then plan, and only then build |
| 4. Verification | How will we know it works? | "Run it and make sure there are no errors", "Check that it looks good on a phone" |
Principle 1: Specificity
A vague prompt gets a vague result. Instead of describing a feeling ("make it nicer"), describe a result you can see.
Weak prompt
Improve the site's design
Strong prompt
On the home page: make the main headline bigger, change the background to a light beige, and add more space between the recipes in the list. Don't change the other pages.
Three questions that help you be specific:
- Where? Which page, which file, which part of the screen.
- What exactly? How it should look or behave when it's done.
- What not? What must not change, which tools not to use, what to leave as is.
Principle 2: Context
Claude sees the files in the project, but it can't see what's in your head: the goal, who the site is for, what you've already tried. The more you tell it about why, the better it decides how.
Weak prompt
Add a sign-up form
Strong prompt
The site is for grandma and grandpa, so everything should be big and clear. Add a sign-up form for the family newsletter with just two fields: name and email. Look at the existing form on the contact page and style the new one the same way.
Later in this chapter there's a whole section on how to give context: files, folders, errors and images.
Principle 3: Step by step
Ask for everything at once and Claude tries to do everything at once. For big tasks it's better to tell it in what order to work, and especially to ask it to understand before changing.
Weak prompt
Add recipe search to the site
Strong prompt
I want to add recipe search. First read the files and briefly explain how recipes are stored today. Then propose a step-by-step plan. Don't write code until I approve the plan.
Principle 4: Verification
This is the principle most people miss, and maybe the most important. Claude stops when the work looks done. Give it a way to check that it really is done, and it'll check on its own, catch mistakes and fix them before you ever see them.
Weak prompt
Fix the bug in the form
Strong prompt
When you click send on the contact form without an email, the page freezes. Fix it so a clear message asks for an email. After the fix, run the site, make sure there are no errors, and explain how I can check it myself.
Ways to give Claude something to check:
- Run it: "Run the site and make sure there are no errors".
- Examples: "If you type 'cake' in the search, three recipes should appear".
- Automated tests: if the project has tests, "run the tests after the change".
- Compare to an image: paste a screenshot of the design you want and ask it to compare.
- Proof: "Show me the output of the command you ran". Checking proof is easier than trusting a promise.
A ready template
You don't need to memorize all this. Here's a template you can copy, fill in and send:
Goal: [what I want to achieve and why]. Where: [file / page / section]. Good to know: [audience, constraints, what not to change]. Order: first [investigate / plan], then [build]. How we'll know it worked: [what to check].
How to give Claude context
Attach files with @
Instead of describing where something is, point at it. Type @ followed by the start of the file name, and Claude Code offers autocomplete. Claude reads the file before answering.
Look at @index.html and @style.css and explain why the menu doesn't show on phones
A sources folder (sources/)
A trick that works great on bigger projects: create a folder called sources in the project and put all the background material in it: links to sites you like, texts, examples, client instructions or idea lists. Then point Claude to it:
Before we start, read all the files in the sources folder and summarize what you learned from each in one sentence
A folder outside the project
Claude works inside the folder where you started it. If the background material lives elsewhere on your computer, for example in your documents, you can give it access with the /add-dir command:
/add-dir ~/Documents/recipes-from-grandmaThe access lasts for the current conversation only.
Pasting error messages
"It doesn't work" is the hardest request for Claude. The full error message is the easiest. The error says exactly what broke, and sometimes on which line.
Weak prompt
The site won't load, fix it
Strong prompt
When I run npm run dev I get this error: [paste the whole error]. Find the cause and fix it, then run it again and make sure the site loads without errors. Fix the root cause, don't just hide the error.
There are two more ways to hand command output to Claude:
Command mode with !: inside Claude Code, a line starting with ! runs straight in the terminal, and its output, errors included, joins the conversation. Claude sees it and can respond:
! npm run devPiping a log file directly: if the errors are saved in a file, you can hand it to Claude straight from the regular terminal:
Get-Content error.log | claude -p "Explain in plain language what this error means"type error.log | claude -p "Explain in plain language what this error means"cat error.log | claude -p "Explain in plain language what this error means"The -p option tells Claude to answer once and exit, without opening a conversation.
Images and screenshots
A picture is worth a thousand words, to Claude too. You can paste a screenshot of a design you liked, a bug you saw, or a sketch you drew on paper:
- Copy the image (for example a screenshot), and paste it inside Claude Code with
Ctrl + V. On Windows, useAlt + V. - Or just drag an image file into the terminal window.
[paste a screenshot] This is how I want the home page to look. Build it, then compare with the image and tell me what's still different
Links
You can give Claude a link to a web page, for example a tool's documentation, and it'll read it (usually after asking for your approval):
Read the instructions at [paste a link] and tell me how to add this to our site
Breaking a big task into small pieces
The most common beginner mistake is asking for the whole project in one message. It's tempting, and it sometimes even works, but usually you get a huge structure that's hard to check, and when something's wrong it's hard to tell what.
Think of building a house: you don't build all the walls, plumbing and wiring at once and only check at the end. You lay the foundation, check, and move on to the next floor.
Weak prompt
Build me a family recipe site with a page per recipe, search, categories, a way to add recipes, photos, printing, a mobile version, and make it bilingual.
Strong prompt
We're building a family recipe site in stages. Stage 1 only: a home page that shows a list of three sample recipes (name and photo). No search and no categories yet. When you're done, tell me how to open it in the browser.
Here's the whole project, piece by piece:
- Home page with a recipe list. ✔ Check in the browser.
- A page per recipe with ingredients and instructions. ✔ Click each recipe and check.
- Categories (cakes, soups, stews). ✔ Check each recipe is in the right category.
- Search. ✔ Search "cake" and check the results.
- Mobile layout. ✔ Open it on a phone.
Plan mode for big tasks
When you're not sure how to break a task down, let Claude do it. In plan mode Claude only reads and plans, and changes no files until you approve the plan.
How to get in:
- Press
Shift + Tabuntil the status line showsplan mode on, or - Type
/planfollowed by the task.
/plan I want family members to be able to add recipes themselves. Check how the site is built today and propose a plan in small steps, where each step can be tested on its own
Claude shows a plan. Read it, ask for changes if needed, and when it looks good, approve it. Only then does it start building.
Let Claude interview you
Sometimes you know what you want but haven't thought through the details. Then you can flip roles: Claude asks, you answer.
I want to build a site for my mom's small business (custom cakes). Interview me in detail: what the site needs, who it's for, how ordering works, and what matters to me. Ask about things I might not have thought of. At the end, write everything we agreed on to SPEC.md
Once the SPEC file is ready, start a new conversation with /clear and ask Claude to build from the file, step by step. The new conversation starts with a clean board and a tidy document holding every decision.
Real-life examples: before and after
A few more pairs. Notice how every strong prompt uses at least two of the four principles.
Understanding a project you were handed
Weak prompt
What is this?
Strong prompt
A friend gave me this project and I'm not a programmer. Explain in plain language, with no technical terms: what the site does, what parts it's built from, and how to run it on my computer.
Changing text in many places
Weak prompt
Change the phone number
Strong prompt
The business phone number changed from 555-123-4567 to 555-765-4321. Replace it everywhere it appears on the site, including the footer and the contact page. At the end, show me a list of every file you changed.
Organizing files on your computer
Weak prompt
Organize the photos
Strong prompt
The photos folder has hundreds of vacation photos. Create a folder for each day by the date taken, and move each photo into the right folder. Don't delete any file. Before you start, show me what you plan to do with the first five photos.
Fixing a display problem
Weak prompt
It looks bad on my phone
Strong prompt
[paste a phone screenshot] On the phone, the photos on the recipe page overflow the screen and you have to scroll sideways. Fix it so the photos fit the screen width. Don't change the desktop layout.
Learning while you work
Weak prompt
Do it
Strong prompt
Add a button that switches between dark and light mode. When you're done, explain in three short paragraphs what you did and why, as if I'm a beginner. I want to learn from this.
CLAUDE.md: rules you don't need to repeat
Noticed you keep writing the same sentences? "Use plain language", "the site is for older people", "don't use external libraries"... That's exactly what CLAUDE.md is for.
CLAUDE.md is a plain text file in your project folder. Claude reads it at the start of every conversation, automatically. Everything in it is like an introduction you never have to write again.
How to create CLAUDE.md
The easiest way: inside Claude Code, in the project folder, run:
/initClaude scans the project and creates a starter file with what it understood: how to run the project, how it's built and what conventions it uses. Then you add your own rules. You can edit the file in any text editor, or inside Claude Code with /memory.
What goes in it? An example
Here's a sample CLAUDE.md for the family recipe site:
# The Cohen Family Recipe Site
## About the project
- A family recipe site. Most users are grandparents and aunts.
## Working rules
- Always answer in plain language, without technical jargon.
- Before a change touching more than three files, show a plan and wait for approval.
- Don't delete recipes, not even to "clean up". If needed, ask.
## Design
- Large text: at least 18 pixels.
- Big, clear buttons, with text and not just an icon.
## Checks
- After every change, run npm run dev and make sure there are no errors.
## Background material
@sources/references.mdGood rules and weak rules
A good rule is one you can check whether it was followed:
| Weak rule | Strong rule |
|---|---|
| Write clean code | Use 2-space indentation |
| Check your changes | After every change, run npm run dev and make sure there are no errors |
| Make it look nice | Text at least 18 pixels, and buttons with text |
| Be careful | Don't delete files in the recipes folder without asking |
When to add a rule?
- When Claude makes the same mistake a second time.
- When you find yourself typing the same note you typed last conversation.
- When someone new joining the project would need to know it.
Where does the file go?
| Location | Applies to | When to use |
|---|---|---|
CLAUDE.md in the project folder | This project, and everyone working on it | Project rules: goal, design, checks |
~/.claude/CLAUDE.md in your home folder | You, in every project | Personal preferences, e.g. "always explain in plain language" |
CLAUDE.local.md in the project folder | Only you, only this project | Personal notes you don't want to share |
And in case you wondered, this site has a CLAUDE.md too. It says the site supports Hebrew right-to-left and English, which technologies to use and where to get information. Thanks to it, every time we asked for a new chapter, the request itself could stay short.
When it's not working: correct fast, restart smart
Even with great prompts, Claude sometimes heads the wrong way. A few habits:
- Stop early. See it going the wrong way? Press
Escright away and explain what to do instead. No need to wait for it to finish. - "Undo what you did" is a perfectly fine request, and
Esctwice also goes back to an earlier point. - The rule of two: if you've corrected Claude twice on the same thing and it still doesn't get it, the conversation is already full of failed attempts. Run
/clearand send a new, better prompt that includes what you learned. A clean conversation with a good prompt almost always beats a long conversation full of corrections.
Pre-send checklist
Before sending a prompt for a big task, run through the list:
- What exactly do I want? Can it be seen or checked?
- Where? Did I point at the files with
@? - What does Claude need to know? Audience, constraints, what I already tried?
- What not to change?
- Is this one task, or should I break it down?
- How will we know it works?
- Is there something here I write every time? If so, it belongs in CLAUDE.md.
Exercise
Rewrite these three prompts as strong ones, using the golden rule. Then try them on the practice project from the previous chapter:
- "Add photos"
- "There's an error"
- "Make the site look professional"
Summary
- The golden rule: specificity, context, step by step, and verification.
- Context comes from
@file, asourcesfolder,/add-dir, full error messages, screenshots and links. - Big tasks get broken into small, testable pieces, and plan mode helps when you're unsure.
- CLAUDE.md holds the standing rules, so you don't have to repeat them. Short, specific, and no secrets.
In the next chapter we'll connect Claude Code to the Cursor code editor, and watch every change it makes in real time.
Check yourself
1. What are the four principles of the golden rule?
2. You write 'use plain language' in every conversation. What's the fix?
Answering every quiz question marks the chapter as done automatically.