Skip to content
Session 1 of 8 Week 1

Session 1: Foundations

How AI coding assistants work, writing effective prompts, and iterating on responses.

By the end of this session you will understand how AI coding assistants generate code, and you will be able to write prompts that produce useful results and iterate on them to get exactly what you need.


How AI Coding Assistants Work

What it is: Large language models are pattern-completion engines trained on vast amounts of text and code. When you type a prompt, the model predicts the most likely next tokens (words or subwords) based on patterns it learned during training. It does not “think” the way you do — it generates plausible continuations of the text you provide. Three concepts matter most for daily use: tokens (roughly 1 token = 0.75 words; a 500-line file is ~2,000-4,000 tokens), context window (how much text the model can see at once — large, but filling it reduces quality), and in-context learning (the model adapts to examples you provide in the prompt, which is why showing your existing code patterns works so well).

Demo prompt:

Explain what happens, step by step, when I send you a prompt.
What are tokens? What is a context window? Why does it matter
how much text I include in my request?

Try it now: Open Claude Code in your own project directory. Ask it to explain the project structure and tech stack by reading the top-level files. Notice how the response quality depends on what files are available for it to read.

Go deeper: Prompting Patterns — core prompting principles and proven patterns for getting good results from Claude Code.


Your First Prompt

What it is: Start by asking Claude Code to read and explain existing code. This calibrates your expectations for how the model responds, what level of detail it provides, and how it handles ambiguity. Use code you already understand so you can judge the quality of the output. From there, move to small, concrete tasks — renaming a variable, adding a comment, writing a single test.

Demo prompt:

Read the main entry point of this project and explain what it does
in 3-4 sentences. Then list the key dependencies and what each one
is used for.

Try it now: Pick a file in your codebase that you know well. Ask Claude Code to explain it. Compare the explanation to your own understanding. Then ask a follow-up: “What would break if I removed [specific function or import]?” If your project does not have a clear entry point, try: What is this project? Read the README and the top-level files and explain what it does.

Go deeper: Prompting Cookbook — copy-paste prompt recipes for common tasks like code explanation, test generation, and refactoring.


Structuring Effective Prompts

What it is: The quality of Claude’s output depends directly on the quality of your input. Vague prompts produce generic code; specific prompts produce code that fits your project. An effective prompt has three ingredients: specificity (what exactly you want, in testable terms), context (which files, patterns, or conventions to follow), and constraints (boundaries like “no external dependencies” or “follow the existing error handling pattern”). Numbering your requirements gives the model a checklist to satisfy, and referencing existing files with @filename gives it concrete patterns to match.

Demo prompt:

Read @src/utils/helpers.ts. I need a new utility function called
formatCurrency that:
1. Accepts a number and a locale string
2. Returns a formatted currency string using Intl.NumberFormat
3. Defaults to 'en-US' and 'USD' if no locale is provided
4. Handles negative numbers and zero correctly

Follow the same export pattern used by the other functions in this file.
Write a test for it in the existing test file.

Try it now: Pick a small enhancement you have been meaning to make in your codebase. Write a prompt that includes: (1) what you want, stated as numbered requirements, (2) a reference to an existing file or pattern to follow, and (3) at least one constraint. Compare the result to what you would get from a one-line request like “add a utility function.”

Go deeper: Vague vs. Specific Prompts — side-by-side comparisons showing exactly how specificity changes output quality.


Iterating on Responses

What it is: Your first prompt rarely produces perfect output. The real skill is knowing how to steer Claude toward what you need. There are three moves: refine (the output is close — tell Claude what to change: “That’s close, but use the existing ErrorHandler class instead of throwing raw errors”), constrain (the output went in the wrong direction — add a requirement you forgot: “Also make sure this handles null input without crashing”), and start fresh (the conversation has gotten confused or too long — use /clear to reset context, or open a new session and write a better prompt using what you learned). Most people new to AI coding tools accept the first response or give up. Experienced users iterate 2-3 times per task, treating the first output as a draft.

Demo prompt:

(After Claude generates a function that works but doesn't match your style)

That works, but two changes:
1. Use early returns instead of nested if/else
2. The error message should include the actual value that failed validation,
   not just "invalid input"

Try it now: Go back to the code Claude generated in the previous exercise. Find one thing that is not quite right — wrong variable name, missing edge case, style mismatch, or an approach you would not have chosen. Tell Claude specifically what to change. Notice how a targeted follow-up (“change X to Y because Z”) produces better results than “try again.”

Go deeper: Sessions & Context — when to continue a conversation vs. start fresh, and how context length affects output quality.


Key Takeaways

  • AI coding assistants are pattern-completion engines, not reasoning engines. They generate plausible code based on context you provide.
  • Verify AI output by reading the diff, running the code, and checking for hallucinated imports or APIs that do not exist in your project.
  • Specificity is the single biggest lever for prompt quality: state what you want, where it goes, and what constraints apply.
  • Reference existing code with @filename so the model matches your project’s conventions instead of inventing its own.
  • Treat the first response as a draft. Iterate 2-3 times with targeted feedback to get output that actually fits your project.
  • Know when AI is the wrong tool: writing a one-line config change is faster manually, and security-critical cryptography should never be AI-generated without expert review.
  • Different models trade off speed, cost, and capability. Use /model to switch when a task needs more reasoning power or when a faster model would do. See Model Selection for guidance.

Practice

Ready to apply what you learned? Try the Foundations Scenarios — hands-on exercises using your own codebase that reinforce the prompting fundamentals from this session.