How AI Actually Works
Tokens, context windows, temperature, hallucination — the concepts behind AI behavior explained through Excel analogies.
Before you can use Claude Code effectively, you need a model in your head of how it actually works. Not the academic version — the practical version that helps you give better instructions, understand its limitations, and predict its behavior.
This page covers the six concepts that matter.
1. Tokens — The Unit of Everything
When you type a message to Claude, it does not see letters or words the way you do. It sees tokens.
A token is roughly 3–4 characters. Most common English words are one token. Longer words split into multiple tokens. Code has more tokens than prose because of all the punctuation.
The Excel analogy: Think of cells in a spreadsheet. Every piece of content — whether a word, a punctuation mark, or a variable name — occupies one or more cells. The AI's limit is not on pages or words, it is on how many cells its working memory can hold at once.
Why tokens matter for you:
- Your subscription plan limits how many tokens Claude can process per day or month
- Longer conversations use more tokens — and cost more
- The more context you give Claude (pasting code, files, instructions), the more tokens it uses
CLAUDE.mdis designed to be cached so it does not consume tokens every session (more on this later)
Rough token estimates:
| Content | Approximate tokens |
|---|---|
| One word | 1 |
| One average sentence | 15–20 |
| One page of prose | 300–400 |
| One React component (100 lines) | 500–800 |
Your entire CLAUDE.md | 2,000–5,000 |
| A large codebase | 50,000–500,000+ |
You do not need to count tokens. You need to understand that everything has a cost — and that writing a clear, focused prompt is cheaper and more effective than a vague, rambling one.
2. Context Window — The AI's Working Memory
The context window is the total amount of text Claude can "see" at once during a conversation — your messages, Claude's responses, any files it has read, and its own previous outputs.
The Excel analogy: Imagine Excel can only keep a certain number of sheets open in memory at once. Once you hit the limit, the oldest sheets get pushed out. If you need to reference Sheet 1 again, you have to re-open it — and Excel has forgotten everything it was doing with that sheet.
Claude's context window works the same way. When a conversation gets very long:
- The earliest parts of the conversation get compressed or dropped
- Claude may not remember something you said 50 messages ago
- You start to notice it giving responses that seem to forget earlier context
In practice:
Claude's context window is very large — hundreds of thousands of tokens. For most coding sessions, you will not hit the limit in a single conversation. But for very long, complex sessions, it matters.
This is part of why CLAUDE.md exists: the file is cached and stays available across sessions without being counted against your context window as fresh tokens every time.
What to do when context gets full: Start a new session. Brief Claude on the current state at the start. This is more effective than trying to continue a very long conversation where early context has been lost.
3. Temperature — The Creativity Dial
Temperature is a setting that controls how creative (or predictable) Claude's outputs are.
Low temperature (near 0): Very deterministic. Given the same prompt twice, Claude will give nearly identical answers. Best for: writing code, following strict instructions, producing consistent outputs.
High temperature (near 1): More creative and varied. Given the same prompt twice, Claude will explore different directions. Best for: brainstorming, writing marketing copy, generating multiple ideas.
The Excel analogy: Think of the random number function. =RAND() gives you something different every time (high temperature). =1+1 always gives you 2 (low temperature). Most of your coding work is more like =1+1 — you want the right answer, not a creative interpretation of the right answer.
For you: Claude Code is already set to a low temperature by default for coding tasks. You do not need to change anything. Understanding temperature helps you understand why Claude sometimes sounds slightly different between sessions — and why code generation is intentionally more predictable than creative writing.
4. Hallucination — When AI Makes Things Up
Hallucination is when an AI produces output that is confident, plausible-sounding, and completely wrong.
This is the most important concept to understand about AI limitations. Claude will sometimes:
- Cite a function that does not exist in a library
- Describe an API endpoint that was deprecated two years ago
- State a fact about a company that is simply incorrect
- Explain how something works in a way that sounds right but is not
Why it happens: Claude was trained on text from the internet. It learned patterns — what kinds of sentences follow what kinds of prompts. When you ask a question it has not seen clearly, it generates a plausible-sounding continuation of the pattern. Sometimes that continuation is wrong.
The Excel analogy: Imagine an autocomplete that finishes your sentences based on what typically follows your words — except it is working on knowledge from three years ago and has no access to your actual spreadsheet to check. It sounds confident because autocomplete always sounds confident.
For code, this is less dangerous than for facts:
| Type of hallucination | Risk level | Why |
|---|---|---|
| Wrong fact (history, company, person) | High | Cannot verify without research |
| Outdated library API | Medium | Tests will catch it |
| Non-existent function | Lower | Your editor will show a type error |
| Wrong approach to a problem | Lower | You will see it not work |
The correct response to hallucination is not to stop using Claude. The correct response is to:
Claude is excellent at generating code structure, patterns, and logic. It is less reliable about specific version compatibility, third-party API details, and factual claims. Always verify those against official sources. Never trust Claude on GST rates, ICAI regulations, or legal requirements — verify those with authoritative sources every time.
5. Prompt Engineering — The Art of Clear Instructions
Prompt engineering is simply: the quality of what you put in determines the quality of what you get out.
This is not a technical skill. It is the same skill a good manager uses when briefing a team member — giving enough context, being specific about the outcome, and not wasting their time with ambiguity.
A bad prompt:
"Make a form"
Claude has no idea: What kind of form? What fields? What does it connect to? What style? What validation?
A good prompt:
"Create a contact form component in
src/components/ContactForm.tsx. It should have fields for name (required), email (required, validated), phone (optional), and message (required, min 20 characters). Use react-hook-form and Zod for validation. On submit, call thesubmitContactFormfunction fromsrc/lib/api.ts. Show a success toast using our existing toast system. Use shadcn/ui Form components."
Same request. Completely different output.
The core principle: Give Claude the context it needs to behave like a good developer who has been on your team for months. The more precisely you describe the current state, the desired outcome, and the constraints — the better the output.
You will get a full breakdown of prompt anatomy in the Master Prompts page.
6. Claude Code vs Claude.ai — Two Different Tools
This distinction confuses people who are new to this. They are both "Claude" but they work very differently.
Claude.ai (the website at claude.ai):
- Conversational chat interface
- Does NOT have access to your files or computer
- Cannot run code
- Cannot read your codebase
- Good for: brainstorming, explaining concepts, writing documents, answering questions
- Memory does not persist between conversations by default
Claude Code (the CLI tool and VS Code extension):
- A coding agent that runs on your machine
- CAN read and write files on your computer
- CAN run terminal commands (npm install, git commit, etc.)
- CAN search your codebase for relevant code before answering
- CAN install packages, run tests, check TypeScript errors
- Reads
CLAUDE.mdat the start of every session - Memory persists through
CLAUDE.mdand skill files
The Excel analogy:
- Claude.ai is like calling a very knowledgeable accountant on the phone. You describe your situation and they advise you.
- Claude Code is like that same accountant sitting at your computer with your actual files open, able to make changes, run calculations, and test their own work.
When to use which:
| Task | Use |
|---|---|
| Understanding a concept | Claude.ai |
| Brainstorming feature ideas | Claude.ai |
| Writing an email or document | Claude.ai |
| Writing actual code in your project | Claude Code |
| Debugging a bug in your codebase | Claude Code |
| Making database migrations | Claude Code |
| Running tests | Claude Code |
Claude.ai — the conversational interface. You type a question, Claude responds. Great for thinking through problems, drafting content, and getting explanations. Not wired into your project files.
Claude Code — the agentic coding tool. It reads your files, writes code, runs terminal commands, and iterates until the task is done. This is what the training is built around.
Do not share client data, client names, PAN numbers, financial details, or any personally identifiable information in Claude.ai chat prompts. Claude.ai conversations may be used to improve the model. Use Claude Code on your local machine for anything involving real project data — it stays on your computer.
Claude Code vs GitHub Copilot
You may have heard of GitHub Copilot, which is another AI coding tool. Here is the practical difference:
| Feature | GitHub Copilot | Claude Code |
|---|---|---|
| Autocomplete while typing | Excellent | Not designed for this |
| Understand full project context | Limited | Excellent |
| Run terminal commands | No | Yes |
| Read and write multiple files | No | Yes |
Follow custom project rules (CLAUDE.md) | No | Core feature |
| Reasoning through complex problems | Limited | Excellent |
| Best for | Line-by-line suggestions | Building full features |
They serve different purposes. Copilot is a fast autocomplete engine. Claude Code is an agent that can plan, investigate, implement, test, and fix — across your entire project at once.
For building web applications end-to-end, Claude Code is categorically more capable.
What to do next: Now that you understand how AI works at a conceptual level, the next page goes into exactly how Claude Code works as a coding agent — the tool system, permission model, and session lifecycle that makes it powerful.