Lesson 4: Prompting Like a Pro
| Course home | Previous: Lesson 3 | Next: Lesson 5 |
Time: about 45 minutes.
Goals
By the end of this lesson you will be able to:
- Write prompts with four parts: goal, context, constraints and a done-check.
- Use examples and “options first” prompts to get better results.
- Recognise and fix the five most common weak prompts.
- Create an
AGENTS.mdproject instructions file that every session reads. - Know when to start a fresh session.
Concepts
The four-part prompt
| Part | Question it answers | Example |
|---|---|---|
| Goal | What do I want, and why? | “Show an error under the input when the name is empty, so users know why nothing happened.” |
| Context | What does the agent need to know? | “The form is in index.html; there is an empty <p id="form-error"> for messages.” |
| Constraints | What must it not do? | “Plain JS only. Do not change the HTML structure. Keep the change under 30 lines.” |
| Done-check | How will we know it worked? | “Tell me how to test it by hand, step by step.” |
You do not need headings in every prompt. A few clear sentences covering all four is enough.
Context is everything
The agent only knows what is in its context window. Ways to give context:
- Point at files: “Read index.html and app.js first.” Many tools also let you mention files with
@index.html. - Paste evidence: exact error messages, the exact text you see on screen.
- Explain intent: “This is for my grandmother, so large text matters more than fancy visuals.”
- Project instructions file: rules that apply to every session (below).
Five weak prompts and their fixes
| Weak | Why it fails | Stronger |
|---|---|---|
| “Make it better.” | No goal; the agent changes random things | “Make the Add button easier to tap on phones: at least 44px tall. Change only CSS.” |
| “Fix the bug.” | No evidence | “When I add ‘Read’ twice, I get two ‘Read’ habits. Expected: an error saying it already exists. Find the cause first.” |
| “Build the whole app with log-in, charts and sync.” | Too big to review | “Today: add habits to a list in memory. Nothing else.” |
| “Use best practices.” | Vague; means different things | “Use textContent, not innerHTML, for user text. Keep DOM code in app.js.” |
| “Do it like the other one.” | The agent cannot see “the other one” | Paste or describe the example, or name the file it is in. |
Prompt patterns worth memorising
- Options first: “Give me three ways to do X with pros and cons. Do not implement.”
- Example-driven: “Format the streak like this: ‘Streak: 3 days’. For one day: ‘Streak: 1 day’.”
- Role and audience: “Explain this as if I have never programmed.”
- Ask me questions: “Before you start, ask up to three questions about anything unclear.”
- Scope fence: “Only change app.js. If you think another file needs to change, ask me first.”
- Show your work: “After the change, run node –test and paste the output.”
Project instructions files
Most agents read a Markdown file from your project root at the start of every session:
AGENTS.mdis an open format read by many agents, including Codex, Copilot and others.- Claude Code reads
CLAUDE.md. You can makeCLAUDE.mdsimply say “See AGENTS.md” or keep the same content in both. - Antigravity CLI reads
AGENTS.mdtoo.
Check your tool’s docs for the exact file name it reads. Put in it: what the project is, the technology rules, coding conventions, commands to run, and how you want explanations.
When to start fresh
Long sessions drift. Start a new session when:
- You finish a feature and commit.
- The agent starts repeating a failed approach.
- It refers to decisions you never made.
- The conversation has gone on for a long time and replies are getting slower or vaguer.
Before you reset, ask: “Summarise what we decided in this session in five bullets.” Paste anything important into AGENTS.md.
Walkthrough
Step 1: Rewrite a weak prompt
Take this weak prompt:
add the ability to add habits
Rewrite it with all four parts. One possible answer:
Goal: when I type a habit name and press Add, it appears in the list under
"Today", and the input clears, so I can quickly add several.
Context: read index.html. The form has id "new-habit", the input
"habit-name", the list "habit-list" and an empty-state paragraph
"empty-state".
Constraints: create app.js with plain JavaScript and load it from
index.html. Keep habits in an array in memory for now (no saving yet).
Use textContent, never innerHTML. Ignore empty names for now.
Done-check: tell me exactly how to test it by hand.
Show me the plan first and wait for my OK.
Do not run this yet; Lesson 6 builds it properly. The point is the shape.
Step 2: Create AGENTS.md
Ask the agent to draft it, then edit it yourself:
Create an AGENTS.md file for this project. It is "Tiny Habits", a habit
tracker built by a beginner to learn web development. Include:
- Tech rules: plain HTML, CSS, JavaScript ES modules; no frameworks, no
build step, no npm packages.
- Code rules: pure logic in habits.js and storage.js, DOM code only in
app.js, textContent instead of innerHTML for user text.
- Process rules: plan before code for anything over a few lines; small
changes; run `node --test` after changes once tests exist; ask before
installing anything or running commands that delete files.
- Communication: explain changes in plain English for a beginner.
Keep it under 30 lines.
Review it. Remove anything you did not ask for. Make sure it is short enough that you would actually read it. If you use Claude Code, also create CLAUDE.md containing:
See AGENTS.md for project rules.
Commit:
git add AGENTS.md CLAUDE.md
git commit -m "Add project instructions for AI agents"
(Leave out CLAUDE.md if you did not create one.)
Step 3: Test that the agent reads it
Start a fresh session and ask:
What are the rules for this project? Answer from the project files only.
It should repeat your rules. If it does not, check the file name and location against your tool’s docs.
Step 4: Practise “options first”
I want habits to show a streak (days in a row). Give me two or three ways to
define a streak with pros and cons, for example what happens if I have not
ticked today yet. Do not write code.
Read the options and choose. The reference project counts the streak through yesterday until today is ticked, so the streak does not drop to zero every morning. Write your choice into AGENTS.md under a “Decisions” heading so future sessions follow it.
Step 5: Practise “ask me questions”
I want to add a way to delete habits. Before planning, ask me up to three
questions about how it should behave.
Good questions: should deleting ask for confirmation? Does it delete history too? Is there an undo? Answer them; you have just written a mini-spec.
What good output looks like
AGENTS.mdexists, is under about 30 lines, and contains rules you agree with.- A fresh session can repeat your rules.
- Your rewritten prompts each have a goal, context, constraints and done-check.
- The streak decision is written down.
Checklist
- I can name the four parts of a strong prompt.
- I rewrote a weak prompt into a strong one.
AGENTS.md(andCLAUDE.mdif needed) is committed.- I confirmed a fresh session reads the rules.
- I used an “options first” and an “ask me questions” prompt.
- I know the signs that it is time to start a fresh session.
Mini-quiz
- What are the four parts of a strong prompt?
- Why is “fix the bug” a weak prompt?
- What is
AGENTS.mdfor? - Give two signs that you should start a new session.
- You asked for a CSS change and the agent also edited app.js. Which prompt pattern would have prevented that?
Answers
1. Goal, context, constraints, done-check. 2. It gives no evidence: no steps, no expected versus actual behaviour, no error text. The agent has to guess what is wrong. 3. It holds project rules and context that the agent reads at the start of every session, so you do not repeat them. 4. Any two of: you just finished and committed a feature; the agent repeats a failed approach; it cites decisions you never made; replies get slow or vague after a long conversation. 5. A scope fence: "Only change styles.css. Ask before changing any other file."Assignment
- Write strong four-part prompts (do not run them) for: a “clear all” button; showing the date at the top of the page; limiting habit names to 60 characters.
- Add a “Decisions” section to
AGENTS.mdwith at least two decisions you made today. - Ask the agent to critique one of your prompts: “How could this prompt be clearer? Do not run it.” Improve it based on the answer.