Claude Code — Goals, Loops, Memory, and Terminal Agents
Use Claude Code as a repo-aware terminal agent: set goals, manage memory, choose models deliberately, verify work, and keep loops bounded.
Use the lesson prompt before you improvise
This lesson already contains a scoped prompt. Copy it first, replace the task and file paths with your real context, and make the agent stop after one reviewable change.
Matching prompts nearby
23
When you finish this lesson prompt, use the related prompt set to keep the same supervision pattern on the next task.
Use Claude Code as a repo-aware terminal agent: set goals, manage memory, choose models deliberately, verify work, and keep loops bounded.
"I'm using Claude Code on this project.
First, read the codebase and summarize:
1. what the app does
2. how the architecture is organized
3. the risky areas to avoid touching casually
Then propose a `CLAUDE.md` file and a safe goal for this change: [describe change].Claude Code is different from every other tool in this path. There's no visual editor. No drag-and-drop interface. No colorful preview pane. It's a terminal application -- you type commands, it reads your files, thinks about your codebase, calls tools, and can make changes.
That might sound intimidating. But terminal and repo-aware agents are now one of the most important categories of AI coding tool, and Claude Code is worth understanding even if you do not use it right away.
What Claude Code Is
Claude Code is Anthropic's command-line coding assistant. You run it in your terminal (the text-based interface on your computer), point it at a project, and have a conversation about your code. It can:
- Read any file in your project
- Create new files
- Edit existing files
- Run commands (like starting your development server or running tests)
- Search through your entire codebase
- Understand how different parts of your project connect
- Use project memory and instructions
- Work from explicit goals
- Use hooks, MCP servers, subagents, skills, and external tools when configured
- Loop on bounded checks like tests, deploy status, or browser verification
The key difference from beginner chat tools: Claude Code can operate inside the repo. That makes it powerful enough to save hours and powerful enough to make a mess if you give it a vague mission.
Why Someone Would Choose This
If visual tools like Cursor and Bolt exist, why would anyone use a terminal-based tool?
Deep Codebase Understanding
Claude Code can read and reason about your entire project at once. Where Cursor works file-by-file with some project context, Claude Code can hold a mental model of how hundreds of files connect. For complex projects, this matters enormously.
Multi-Step Operations
Need to rename a function across 30 files, update every test that references it, and modify the documentation? Claude Code handles this as a single conversation. In a visual editor, you'd be doing this file by file.
The CLAUDE.md System
Every project can have a CLAUDE.md file (and nested ones in subdirectories) that gives Claude Code persistent context about the project. Think of it as a combination of rules file, runbook, and project wiki. It can include:
- Project architecture and conventions
- How to run and test the project
- Important decisions and their reasoning
- Known issues and workarounds
Claude Code reads these files automatically every time it starts, giving it institutional knowledge about your project.
Goals, Loops, Hooks, MCP, and Subagents
Claude Code is not only a chat window. It is an operating surface.
Depending on your setup, it can use:
- goals to organize longer work around a visible outcome
- loops for repeated status checks or bounded follow-through
- hooks to run commands or checks at key moments
- MCP servers to reach tools like GitHub, browser automation, docs, databases, or internal systems
- subagents and skills for specialized work inside a larger session
This is where beginners need discipline. Do not turn on every capability because it sounds advanced. Start with goals and verification. Add loops only when the loop has a maximum count, a safe command list, and a clear stop condition.
Model Choice
Claude Code can use different Claude models depending on availability and configuration. Stronger models such as Fable-class or high-reasoning Sonnet-class releases are better for complex planning, migrations, security review, and messy debugging. Faster or cheaper models can be enough for explanations, small text edits, and obvious refactors.
Model names change. Availability changes. Some teams will talk about "5.6," Fable, Sonnet, Opus, or whatever the newest label is. The durable practice is:
- use stronger reasoning for high-risk plans
- use smaller/faster models for low-risk routine edits
- do not confuse model power with permission to skip review
- always keep scope, proof, and rollback visible
How It Works in Practice
Here's what a typical Claude Code session looks like:
$ claude
> What does the authentication system in this project do?
Claude Code reads your auth files and explains the flow:
"This project uses Clerk for authentication. The middleware at
src/middleware.ts protects routes under /dashboard. The auth
state is accessed via useAuth() hook in client components and
auth() in server components..."
> Add a feature that logs when users sign in, including their
email and timestamp, to a new file called auth-log.ts
Claude Code proposes changes:
- Creating src/lib/auth-log.ts with a logging function
- Modifying src/app/api/webhooks/clerk/route.ts to call the logger
- Adding the log file path to .gitignore
You review and approve each change.Notice the workflow: ask, review, approve, verify. Claude Code is strongest when you make it show the plan, make one reviewable change, and prove the result.
Setting Up Claude Code
Prerequisites
Claude Code requires:
- A computer with a terminal (Mac Terminal, Windows PowerShell, or Linux terminal)
- Node.js installed (version 18 or higher)
- An Anthropic API key or a Claude subscription with Claude Code access
Installation
npm install -g @anthropic-ai/claude-codeFirst Run
Navigate to your project directory and run:
cd your-project
claudeClaude Code will read your project's files and start a conversation. Try asking it to describe what the project does — it's a great way to verify it understands the codebase.
First Commands to Learn
Do not try to memorize every command. Learn the ones that create control:
| Command or habit | Why it matters |
|---|---|
| /init | Creates or updates project memory so Claude has durable instructions |
| /model | Shows or changes which model is being used, when your setup supports it |
| /help | Shows the command surface available in your current install |
| /goal or goal-setting prompt | Makes the outcome, scope, proof, and stop condition explicit |
| /loop or loop-setting prompt | Useful only for bounded monitoring, testing, or status checks |
| checkpoint / rewind flow | Gives you a recovery path before broad edits |
If a command is not available in your install, the concept still matters. Write the goal or loop bounds in plain English.
The CLAUDE.md File
Creating a CLAUDE.md file in your project root is the single most impactful thing you can do with Claude Code. It's like writing a briefing document for a new team member.
Here's a practical example:
# My Project
## What This Is
A personal finance tracker built with Next.js and Supabase.
## Tech Stack
- Next.js App Router
- TypeScript
- Tailwind CSS
- Supabase (database + auth)
- Recharts for data visualization
## How to Run
npm run dev — starts the dev server at localhost:3000
npm run build — production build
npm test — runs the test suite
## Important Conventions
- All database queries go through src/lib/db/ functions
- Use server components by default
- Client components go in src/components/client/
- API routes handle webhooks and external integrations only
- Do not touch Stripe, Clerk, DNS, or production data without explicit approval
- Run npm test before saying a code change is complete
## Known Issues
- The CSV import breaks on files with more than 10,000 rows
- Mobile charts don't resize properly on orientation change
## Agent Operating Rules
- Start each task with the goal, expected files, verification, and stop condition
- Prefer one reviewable change at a time
- Ask before adding packages, changing config, or running destructive commands
- Update this file when a durable project decision changesEvery time Claude Code starts a session, it reads this file. You don't need to re-explain your project every time.
When to Use Claude Code vs. Cursor vs. Codex
This is the question most people have, and the honest answer is: it depends on your comfort level and the task.
| Task | Better Tool | Why | |------|-------------|-----| | Building a new feature visually | Cursor | Visual preview helps | | Refactoring across many files | Claude Code | Better multi-file reasoning | | Debugging with error messages | Either | Both handle this well | | Learning/exploring a new codebase | Claude Code | Better at explaining architecture | | Quick UI changes | Cursor | See the result immediately | | Complex business logic | Claude Code | Deeper reasoning | | Day-to-day development | Cursor | Visual interface is faster for most tasks | | Large-scale migrations | Claude Code | Can reason about project-wide changes | | Goal-driven implementation with verification | Codex or Claude Code | Strong fit for plans, tool use, tests, and closeout | | Production-readiness review | Codex, Claude Code, or Cursor | The important part is repo access plus explicit verification |
Many developers use more than one. Cursor for daily work where they want to see what's happening. Claude Code or Codex for heavier work where they need the AI to reason across the repo, follow project instructions, use tools, and prove the result.
Claude Code for AI Builders
You might be thinking, "I'm an AI builder, not a terminal expert. Is this for me?"
Maybe not today. But here's why you should know about it:
Your projects will grow. The tool you use for a simple bookmark manager isn't the same tool you need when that bookmark manager has users, a database, payment processing, and email notifications. Claude Code scales to complex projects better than any other tool.
The terminal gets easier. Every time you use the terminal in Cursor or Replit, you're building terminal skills. Claude Code will feel less intimidating the more you code.
CLAUDE.md is a transferable concept. Even if you never use Claude Code, the idea of writing context files for your AI tools makes all of them work better. Codex uses AGENTS.md, Cursor has rules, and many tools now support project memory. The principle is the same: tell the agent about your project, get better results.
The 2026 Agent Pattern
The newer pattern is not "ask the terminal agent to code forever." It is:
- set the goal
- define the files, systems, or production surfaces that are in scope
- name the things the agent must not touch
- require a plan before edits
- make the agent run tests or browser checks
- stop for human review before risky follow-up work
This matters more as agents gain access to GitHub, Vercel, Supabase, Clerk, Stripe, Sentry, Slack, browsers, and databases. Tool access is powerful only when permissions and stop conditions are clear.
The Beginner Operating Recipe
For your first week, use this recipe:
- Start Claude Code in a clean repo.
- Ask for a plain-English architecture summary.
- Create or update
CLAUDE.mdwith run commands, protected systems, and project decisions. - Set one tiny goal.
- Ask for the plan before edits.
- Let it make one reviewable change.
- Run the agreed verification.
- Inspect the diff.
- Checkpoint if it worked, or rewind if the change went sideways.
- Only then set the next goal.
That recipe is slower than a demo video. It is much closer to how you build something you can trust.
Practical Tips
Start with questions, not commands. When you first use Claude Code on a project, ask it to explain things. "What does this project do?" "How is the database structured?" "What happens when a user signs up?" This builds trust in its understanding.
Be explicit about what you don't want changed. Claude Code can modify files, so be clear: "Add the logging feature but don't modify the existing auth flow." Claude Code shows you proposed changes before making them, but being explicit up front produces better proposals.
Use CLAUDE.md for decisions, not just facts. Don't just list your tech stack. Document why you made those choices: "We use Supabase instead of Firebase because we need PostgreSQL's full-text search." This helps Claude Code make consistent decisions in the future.
Review changes carefully. Claude Code shows diffs (the before and after of each file change) before applying them. Read these. The tool is powerful, and reviewing its work is how you stay in control.
Keep loops boring. Use loops for "run this check until it passes or fails three times," not "keep improving the app." Boring loops protect you. Creative loops create surprise.
Use frontier models where risk is highest. Ask Fable-class or other high-reasoning models to plan migrations, review auth, inspect security, or reason through business logic. Do not burn them on tiny copy edits unless speed does not matter.
Try this now
- Write a real
CLAUDE.mdfile for one project, even if it is only one page long. - Start with explanation prompts before you ask for edits so you can judge the tool's understanding.
- Try one bounded task with an explicit "do not touch" list and review the diff carefully.
Prompt to give your agent
"I'm using Claude Code on this project. First, read the codebase and summarize:
- what the app does
- how the architecture is organized
- the risky areas to avoid touching casually
Then propose a
CLAUDE.mdfile and a safe goal for this change: [describe change]. Include:
- outcome
- scope
- expected files
- tools or commands needed
- verification
- stop condition
- rollback or checkpoint plan
Do not modify [list protected areas] without asking first. Use loops only for bounded verification, not open-ended improvement. Include the verification command or browser check you will use before saying the task is done."
What you must review yourself
- Whether terminal-based workflow is a fit for your current comfort level and task type
- Whether
CLAUDE.mdcontains live decisions and constraints rather than stale documentation - Whether you are reviewing diffs carefully before accepting broad changes
- Whether Claude Code is the right tool for the task or whether a visual editor would be faster
- Whether goals, loops, hooks, MCP, subagents, and model choice are making the work safer or merely more complicated
Common Mistakes to Avoid
- Using Claude Code before you know what should stay untouched. Powerful tools need clear boundaries.
- Letting
CLAUDE.mddecay. Persistent context is only useful if it remains true. - Skipping the exploratory questions. Understanding-first usage builds trust faster than edit-first usage.
- Choosing terminal power for work that needs visual feedback. Tool fit still matters.
- Running open-ended loops. A loop without a maximum bound and a stop rule is not a workflow.
- Treating model names as strategy. Better models help, but the strategy is still scope, proof, review, and recovery.
Key takeaways
- Claude Code is strongest at deep, multi-file reasoning in a codebase
CLAUDE.mdis a durable prompt surface, not optional decoration- The same durable-instructions idea applies to Codex
AGENTS.md, Cursor rules, and other modern agent tools - Boundary-setting matters more as tool power increases
- Goals, loops, hooks, MCP, subagents, and skills are production power tools, not beginner toys
- Fable-class models and other frontier releases are most useful when paired with explicit proof and rollback
- Many teams benefit from using repo agents and visual tools side by side
What's Next
Next up: GitHub Copilot — The AI That Lives in Your Editor. Set up GitHub Copilot for inline code completions and AI-assisted development in VS Code. This builds directly on what you learned here, so carry the same discipline forward: define the constraints first, then use your AI agent to implement against them.