Lesson 04: How Does Vibecoding Actually Work
Embark on your journey to building production grade apps.
You've learned that an AI agent is different from a chatbot: it doesn't just respond, it acts. You describe what you want, the agent writes the code, runs it, and iterates.
But how? What's actually inside a coding agent that lets it do all that?
Every agent you'll use in this course (Replit's agent, Codex, Cursor, and others) is built from the same core parts. They differ in packaging and defaults, but under the hood they share the same structure: a model, a context window, tools, a loop, and a harness around it all. Once you understand those parts, you can reason about any coding agent, which one to reach for, and why it behaves the way it does.
To make the parts concrete, we'll use Anthropic's Claude as our running example. Looking at one specific agent in depth makes the structure easier to see than comparing five at once. Everything we cover applies to the others with minor naming changes.
Think of it like a car. You don't need to be a mechanic to drive, but knowing there's an engine, a transmission, wheels, and a gas tank helps you understand why it behaves the way it does. That's what we're doing with coding agents.
The Big Picture
Claude isn't a single thing. It's a stack of layers that work together:
- The Model: the "brain" that reads and writes text.
- The Context Window: everything the brain can see right now.
- The System Prompt: the standing instructions that shape behavior.
- Tools: the "hands" that let the brain do things in the real world.
- The Agentic Loop: the engine that makes the brain act, observe, and iterate.
- Memory & CLAUDE.md: long-term notes that persist across sessions.
- Skills, Hooks & Settings: the harness that configures how Claude runs.
- MCP: the plug that lets Claude connect to outside systems.
Let's go through each one.
Claude is best described as…
Layer 1: The Model (The Brain)
At the center of Claude is a large language model (LLM): a neural network trained to predict what text comes next given some input. That sounds almost too simple, but scale changes everything. Trained on enormous amounts of code, documentation, and writing, the model learns to reason, follow instructions, and generate working code across dozens of languages.
The Claude family comes in different sizes:
- Opus: the most capable, best for hard reasoning and long tasks.
- Sonnet: a balance of capability and speed. The default workhorse.
- Haiku: the fastest and cheapest, great for simple high-volume tasks.
The model is stateless. By itself, it doesn't remember anything between requests. Every time you send it a message, you have to send along everything it needs to know. That's where the context window comes in.
The model at the core of Claude is…
Which Claude model is typically best for hard reasoning?
The model by itself is stateless, meaning…
Layer 2: The Context Window (What Claude Sees)
The context window is everything Claude can see at once: your current message, past messages in the conversation, files it has read, and outputs from tools it ran. It's like Claude's short-term working memory for this session.
Context is measured in tokens. A token is roughly ¾ of a word, or a short chunk of code. Modern Claude models can see up to 200,000 tokens (standard) or even 1,000,000 tokens (extended), enough to hold a whole small codebase.
A few important things about the context window:
- Bigger is not always better. More tokens means more cost and more processing time.
- It can fill up. On long tasks, Claude Code automatically summarizes older turns to stay under the limit.
- Anything not in context doesn't exist to Claude. If a relevant file hasn't been read, Claude can't reason about it. It has to
Readit first.
This is why good vibecoding often means pointing Claude at the right files. You're shaping what ends up in the context window.
The context window is…
A 'token' is roughly…
If a file hasn't been read into context, Claude…
Layer 3: The System Prompt (The Standing Orders)
Before you ever send your first message, Claude already has instructions. These come from the system prompt: a block of text the application (like Claude Code) puts at the very top of the context window every turn.
The system prompt tells Claude:
- Who it is ("You are Claude Code, Anthropic's official CLI…").
- What tools it has access to and how to use them.
- The rules of engagement (how to handle risky actions, when to confirm with the user, how to format responses).
- Any project-specific context (more on
CLAUDE.mdbelow).
You can think of the system prompt as the job description Claude reads at the start of every shift. It's always there, quietly steering behavior. If Claude Code is being cautious about deleting files, that's the system prompt doing its job.
The system prompt is…
The system prompt is visible to…
Layer 4: Tools (The Hands)
The model can read and write text, but text alone doesn't edit a file or run a test. Tools are what give Claude the ability to actually do things.
A tool is a named capability with a defined input and output. When Claude decides a tool is needed, it outputs a structured request, something like Read(file_path="src/app.js"), and the harness runs it and sends the result back.
In Claude Code, the built-in toolbox includes:
Read: open a file and see its contents.Write: create a new file.Edit: make a precise change to an existing file (diff-style).Bash: run a shell command (tests, builds, git, anything).Grep: search file contents for a pattern.Glob: find files by name pattern.WebFetch/WebSearch: look things up online.Agent: spawn a sub-agent for a focused subtask.
Without tools, Claude could only produce text. With tools, Claude can investigate a codebase, change it, run it, and see what happened. Tools are the difference between an AI that gives you advice and an AI that finishes the job.
A tool is…
Without tools, Claude can only…
Which of these is NOT a real Claude Code tool?
Layer 5: The Agentic Loop (The Engine)
We've got a model (brain), context (short-term memory), a system prompt (job description), and tools (hands). The piece that ties it all together is the agentic loop.
Every turn, Claude does this:
- Think. Read the full context, reason about what to do next.
- Act. Either respond with text, or call a tool.
- Observe. If a tool was called, read the result.
- Repeat. Use the new information to decide the next step.
The loop keeps running until Claude decides the task is done.
This is the whole game. A fix-the-tests task might look like: run tests (Bash), read the failing test (Read), read the source (Read), hypothesize, edit (Edit), re-run tests (Bash), green, report. Each step is one turn of the loop.
Because the loop continues until the task is done, Claude can handle tasks that take many steps without you approving each one. You describe the goal; the loop grinds until the goal is reached.
The 'agentic loop' is…
The agentic loop stops when…
Layer 6: Sub-Agents (Delegation)
For big tasks, Claude can spin up sub-agents: separate instances of the agentic loop that handle a focused subtask and report back.
Say you ask Claude to refactor the auth system. It might spawn:
- An Explore sub-agent to map out all the auth-related files.
- A Plan sub-agent to design the refactor.
- Several focused general sub-agents to implement individual pieces in parallel.
Each sub-agent has its own context window. It does a bunch of messy searching and reading in its own scratchpad, then returns a concise summary to the main agent. This keeps the main conversation's context clean and focused on the high-level plan.
Sub-agents are why Claude Code can take on surprisingly large tasks without drowning in clutter.
A sub-agent is useful because…
Each sub-agent has…
Layer 7: Memory and CLAUDE.md (The Long-Term Notes)
The context window is short-term memory. It resets when the conversation ends. For things that should persist across sessions, Claude has two mechanisms:
CLAUDE.md is a project-level instructions file. When you start Claude Code in a folder, it automatically reads any CLAUDE.md in the project and puts it into the system prompt. This is where you put project conventions, key file locations, commands to run, and anything else Claude should "know" about this codebase. It's the closest thing to onboarding docs for your AI collaborator.
Memory files are a folder of Markdown files where Claude can save notes about the user, ongoing projects, feedback, and references. Before each session, Claude checks the memory index. After a session, it can write new memories. This is how Claude "remembers" that you prefer terse responses, or that the Linear project for bugs is called "INGEST."
Together, CLAUDE.md (project knowledge) and memory (user and cross-project knowledge) are what give Claude continuity.
`CLAUDE.md` is used to store…
The memory system is for…
When the conversation ends, the context window…
Layer 8: Skills, Hooks, and Settings (The Harness)
Around the model is a harness: the application code (like Claude Code) that assembles the context, executes tools, and manages the loop. The harness is configurable.
- Skills / Slash Commands: reusable workflows you invoke with
/name. Examples:/initto generate a CLAUDE.md,/reviewto review a PR,/security-reviewto audit recent changes. Skills bundle a prompt, often with specific tools and steps, into one command. - Hooks: shell commands the harness runs automatically at specific events, before a tool call, after Claude stops, when a file is edited. Great for auto-formatting code, blocking risky commands, or sending notifications.
- Settings (
settings.json): controls permissions (what tools auto-approve), environment variables, default model, and hook configuration. This is where you tune Claude's behavior from "asks about everything" to "can run freely in this sandbox." - Keybindings: customize keyboard shortcuts for common actions.
The harness is what turns a raw model into a usable product. Different harnesses (Claude Code vs. Cursor vs. Replit) wrap the same kind of model in different ways for different workflows.
A 'slash command' or 'skill' is…
'Hooks' in Claude Code are…
The 'harness' is…
Layer 9: MCP (The Plug)
Built-in tools cover files, shells, and the web. But what about your systems: your database, your Linear board, your Gmail?
MCP (Model Context Protocol) is an open standard, created by Anthropic, for connecting AI assistants to external tools and data sources. An MCP server exposes a set of tools. Any MCP-compatible client (including Claude Code) can use them.
This turns tool use from a custom integration into a plug-and-play ecosystem:
- Want Claude to read your Gmail? Install the Gmail MCP server.
- Want Claude to query your Postgres database? Install the Postgres MCP server.
- Want Claude to talk to an internal API? Write a small custom MCP server.
MCP is how Claude's abilities extend past what ships in the box.
MCP stands for…
MCP is used to…
Putting It All Together
Here's the full picture of a single Claude turn:
┌──────────────────────────────────────────────────────┐
│ HARNESS (Claude Code) │
│ │
│ ┌──────────────────────────────────────┐ │
│ │ CONTEXT WINDOW │ │
│ │ - System prompt │ │
│ │ - CLAUDE.md │ │
│ │ - Memory index │ │
│ │ - Conversation history │ │
│ │ - Tool outputs │ │
│ │ - Your current message │ │
│ └──────────────────────────────────────┘ │
│ ▼ │
│ ┌──────────┐ │
│ │ MODEL │ ← think │
│ └──────────┘ │
│ ▼ │
│ text response OR tool call │
│ │ │
│ ▼ │
│ ┌───────────────────────────┐ │
│ │ TOOLS │ │
│ │ Read, Edit, Bash, Grep… │ ← act │
│ │ + MCP tools │ │
│ └───────────────────────────┘ │
│ │ │
│ ▼ │
│ tool result ← observe │
│ │ │
│ └──► back into context │
└──────────────────────────────────────────────────────┘
(repeat until task is done)
Every impressive thing Claude does, fixing a bug end-to-end, refactoring a module, exploring an unfamiliar codebase, is just this structure running in a loop. The model reasons, the tools act, the context holds everything together, and the harness keeps the whole thing running safely.
Now when Claude surprises you (good or bad), you can ask: which layer did that? Was it the model reasoning poorly? The context missing a file? The system prompt being too cautious? The wrong tool being chosen? Knowing the structure is how you go from "magic" to "debuggable."
Final check: every turn Claude takes involves…
When Claude does something unexpected, the debugging move is…
What's Next
You can now reason about any coding agent in terms of its parts: the model, the context window, the tools, the loop, and the harness. Next, you'll learn about threat awareness — your first look at security, and how to think about the ways a real, shipped app gets attacked so you can get ahead of it.
0/26 correct
0% — get all correct to complete