C
Vibe Coding/Intro/Lesson 05

Prompts in Practice — *20 Token-Saving Patterns*

45 min·theory
This chapter
3/3

Prompts in Practice — *20 Token-Saving Patterns*

🎯 After reading this lesson

After finishing this lesson, you will be able to confidently do the following 3 things.

  • ✅ The 4 elements of a prompt (scope · context · constraints · output format)
  • ✅ Choosing between Few-shot vs Zero-shot
  • ✅ Chain-of-Thought · Self-Critique patterns

Keep the learning objectives as a checklist and close the lesson once you can answer all of them.

Why *Prompt Patterns*?

The One-Line Core

The secret of a pro vibe coder is getting the same results with 10x fewer tokens. It makes a difference in cost, speed, and accuracy alike.

Token savings = more than just money

EffectMeaning
💰 Cost10x difference in API costs
⏱️ SpeedShorter output means faster responses
🎯 AccuracyMore specific = AI doesn't guess
🧠 Context preservationShorter output → conversation lasts longer

Token estimation formula

  • English: 1 word ≈ 1.3 tokens
  • Korean: 1 character ≈ 1.5–2 tokens
  • Code: 1 line ≈ 10–30 tokens

→ 100 lines of code output = approx. 1,500–3,000 tokens. Cutting unnecessary output lowers costs ↓.

How this lesson is structured

The next 4 sections contain 20 pattern comparisons (❌ bad vs ✅ good). Each pair shows the expected token difference.

Formatted so you can copy and paste directly into Cursor.

Patterns 1–5: *Scope Limiting* Patterns

Pattern 1 — Specify the file

❌ "Take a look at this code" (expected output ~2500 tokens)

✅ "Fix only the type error on line 47 of @src/auth.ts. No other code changes." (expected output ~150 tokens)

16x savings. Specifying a file with @ makes the AI look at only that file.

Pattern 2 — Function-level scope

❌ "Improve the login logic" (~3000 tokens)

✅ "Only the validatePassword function in @auth.ts. Update bcrypt cost to 12. Do not touch other functions." (~200 tokens)

Pattern 3 — Emphasize no changes

❌ "Make the button red" (can trigger full component rewrite)

✅ "Change bg-blue-500bg-red-500 on line 21 of @Button.tsx. That only. No other changes. Show only the diff after the change." (~50 tokens)

Pattern 4 — Request diff format

❌ "Fix it" (outputs the entire file)

✅ "Show only the changed parts in diff format:

diff
- old line
+ new line
" (~100 tokens)

Pattern 5 — Explicit Out of scope

❌ "Take a look at the payment logic" (looks at all related files)

✅ "@payment.ts only. Do not touch user.ts or order.ts. Review only the payment processing logic. No README changes either."

→ AI does not arbitrarily modify other files.

Summary — Patterns 1–5

Smaller scope = better. @file + single line/function + nothing else is the golden combination.

Patterns 6–10: *Context Compression* Patterns

Pattern 6 — Use CLAUDE.md

❌ "I'm using Next.js 15 App Router with TypeScript and Tailwind and Drizzle ORM... make me a login API" (repetitive)

✅ "Based on the stack in @CLAUDE.md. POST /api/auth/login. zod validation + bcrypt + JWT"

→ No need to explain the stack every time. 30x savings (per conversation).

Pattern 7 — Specify output format

❌ "Help me" (free-form, usually verbose)

✅ "Use this format:

  • List of changed files
  • Diff of changes per file
  • Summary in 5 lines or fewer"

→ AI outputs only that format.

Pattern 8 — Code only / no explanations

❌ "Create the function" → usually outputs code + usage + gotchas + alternatives

✅ "Code only. No explanations or comments." (~70% savings)

Only request explanations separately when you truly need them.

Pattern 9 — Request concise responses

❌ (free-form response)

✅ "One line per paragraph. Conclusion first."

Or: "Keep it readable in under 30 seconds."

Pattern 10 — Specify where to put the result

❌ "Write a test" → AI deliberates and explains where to put it

✅ "Write vitest tests for @src/auth.ts in src/auth.test.ts. Create the file right there."

→ Zero follow-up conversation.

Summary — Patterns 6–10

Do not give the AI freedom. Specify format, location, and length explicitly. Save 50–70% of output tokens.

Patterns 11–15: *Clarity* Patterns

Pattern 11 — Specify input and output

❌ "Create a login function"

✅ "Function signature:

ts
async function login(input: LoginInput): Promise<LoginResult>
type LoginInput = { email: string; password: string }
type LoginResult = { ok: true; token: string } | { ok: false; error: string }

bcrypt comparison + JWT issuance. On error, put the message in LoginResult.error"

→ AI implements exactly the signature. Zero meaningless guessing.

Pattern 12 — Provide examples and counter-examples

❌ "Add validation" (AI arbitrarily picks zod, yup, or valibot)

✅ "Validate with zod:

ts
const schema = z.object({
  email: z.string().email(),
  password: z.string().min(8)
})

Add it in this style."

Pattern 13 — Specify the version

❌ "In Next.js..."

✅ "In Next.js 15.0.3 App Router..."

Different versions mean completely different APIs. Without specifying, AI guesses the latest (and may be wrong).

Pattern 14 — Prohibit what is not allowed

❌ "With security in mind"

✅ "Security considerations:

  • dangerouslySetInnerHTML absolutely prohibited
  • ❌ eval and new Function prohibited
  • ❌ No direct user input in SQL
  • ✅ Parameterized query
  • ✅ DOMPurify"

→ AI will not violate explicit prohibitions.

Pattern 15 — Say you don't know if you don't know

❌ (ask as-is)

✅ "If you're not sure, say 'I don't know.' Don't make things up. Verify function and library names against official docs before answering."

→ Hallucinations drastically reduced.

Summary — Patterns 11–15

Clarity = eliminating guesswork. Signatures, examples, versions, prohibitions, and 'say you don't know' — all included in the prompt.

Patterns 16–20: *Repetition Avoidance* Patterns

Pattern 16 — Leverage accumulated context

❌ (explain from scratch for each request)

✅ "Based on our previous conversation. Additional task: ..."

Within the same chat session, use the previous context as-is. Don't start a new conversation.

Pattern 17 — Chaining pattern

❌ "Create the function and write tests too" → both at once (long output)

✅ Step 1: "Only the validatePassword function in @auth.ts"
→ Receive it
→ Step 2: "Only the vitest tests for the above function"
→ Receive it

Verify each step + short output × 2.

Pattern 18 — Retry optimization

❌ If you don't like the AI response, "Redo it" → starts from scratch (wasteful)

✅ "Change only part X from the above response:

  • bcrypt cost 10 → 12
  • Keep all other code as-is"

→ Only the changed part is regenerated.

Pattern 19 — Small model first

❌ Use Opus for everything

✅ Simple tasks → Haiku ($1/M input)
Complex tasks → Sonnet ($3/M)
Truly difficult → Opus ($15/M)

You can switch models via the option in Cursor.

Pattern 20 — Prompt Caching

❌ Send the system prompt every time

✅ When using the Anthropic API, add cache_control:

python
system=[{
    "type": "text",
    "text": "Long system prompt...",
    "cache_control": {"type": "ephemeral"}
}]

90% discount when the same system prompt is reused within 5 minutes.

Overall — Effect of Applying All 20 Patterns

TaskInefficient tokensEfficient tokensSavings
Small bug fix2,50015016x
Adding a function5,0008006x
Creating a component8,0001,5005x
Full-stack feature30,0006,0005x

Average 5–10x savings. Monthly $50 → $5–10.

Summary

Core of the 20 patterns:
1. Scope small (@file · function only · nothing else)
2. Context compressed (CLAUDE.md · specify format and length)
3. Clarity (signatures · versions · prohibitions)
4. Avoid repetition (chaining · retry optimization · caching)

Master these 4 axes and you'll instantly become a pro vibe coder.

🤖 Try asking AI like this

Once you understand the concepts in this lesson, you can give specific instructions to the AI. Not a vague 'fix this' but a request with vocabulary — that's the starting point of token savings.

  • "Rewrite this vague prompt using the 4 elements: scope · context · constraints · output format"
  • "This prompt has a high hallucination risk — add a request for evidence."

Why does this reduce tokens?

Without understanding the concepts, even after receiving an AI response you have to ask 'What does that mean?' again. That follow-up question eats up tokens. Learn the concepts once and the conversation ends in one go.

Practical Prompts — 20 Token-Saving Patterns - Vibe Coding