Context is King
If there's one thing you take away from this beginner course, let it be this: Context is the difference between a terrible AI hallucination and a perfect, production-ready piece of code.
I see developers complain all the time that AI generated "bad code." 9 times out of 10, when I look at their prompt, they gave the AI absolutely zero context about their existing app.
What Do We Mean By Context?
Context is the background information Claude needs to make informed decisions.
Imagine asking a coworker, "Hey, how do I fetch data?" Their first question would be, "Well, are we using React? Are we using a library like React Query? What does the API endpoint look like?"
Claude needs the exact same information.
Providing Code Context
If you want Claude to fix a bug in a specific file, don't just paste the line of code that threw the error. Claude needs to see the surrounding code.
Bad Prompt:
"Why is
user.idundefined here?console.log(user.id)"
Good Prompt:
"I'm getting a TypeError saying
user.idis undefined. Here is the function where the error happens, and here is the API response I'm expecting. What did I do wrong?"// function code here// api response here
Using the Attachment Feature
Remember that paperclip icon we talked about in Lesson 2? That's your context injection machine.
If I'm working on a complex feature, I will literally attach:
- The main file I'm working on.
- The file that contains my database schema or TypeScript types.
- The file that handles my API routes.
Then my prompt is simple: "Look at the attached schema and API route. I need to write a frontend React component that fetches this data and displays it in a table."
Because Claude has a massive context window (especially on the Sonnet 3.5 and Opus models), it can read all three of those files instantly, understand exactly how your database is structured, and write frontend code that matches your backend perfectly.
The Rule of Thumb
Before you hit enter, ask yourself: "If I handed this prompt to a human developer who just walked in off the street, would they have enough information to solve the problem without asking me follow-up questions?"
If the answer is no, you need to add more context.