Skip to the content.

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:

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:

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

Project instructions files

Most agents read a Markdown file from your project root at the start of every session:

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:

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

Checklist

Mini-quiz

  1. What are the four parts of a strong prompt?
  2. Why is “fix the bug” a weak prompt?
  3. What is AGENTS.md for?
  4. Give two signs that you should start a new session.
  5. 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

  1. 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.
  2. Add a “Decisions” section to AGENTS.md with at least two decisions you made today.
  3. 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.

Next: Lesson 5: Style it and make it accessible