The agentic loop
When you give Claude a task, it works through three phases: gather context, take action, and verify results. These phases blend together. Claude uses tools throughout, whether searching files to understand your code, editing to make changes, or running tests to check its work.Models
Claude Code uses Claude models to understand your code and reason about tasks. Claude can read code in any language, understand how components connect, and figure out what needs to change to accomplish your goal. For complex tasks, it breaks work into steps, executes them, and adjusts based on what it learns. Multiple models are available with different tradeoffs. Sonnet handles most coding tasks well. Opus provides stronger reasoning for complex architectural decisions. Switch with/model during a session or start with claude --model <name>.
When this guide says “Claude chooses” or “Claude decides,” it’s the model doing the reasoning.
Tools
Tools are what make Claude Code agentic. Without tools, Claude can only respond with text. With tools, Claude can act: read your code, edit files, run commands, search the web, and interact with external services. Each tool use returns information that feeds back into the loop, informing Claude’s next decision. The built-in tools generally fall into four categories, each representing a different kind of agency.| Category | What Claude can do |
|---|---|
| File operations | Read files, edit code, create new files, rename and reorganize |
| Search | Find files by pattern, search content with regex, explore codebases |
| Execution | Run shell commands, start servers, run tests, use git |
| Web | Search the web, fetch documentation, look up error messages |
| Code intelligence | See type errors and warnings after edits, jump to definitions, find references (requires code intelligence plugins) |
- Run the test suite to see what’s failing
- Read the error output
- Search for the relevant source files
- Read those files to understand the code
- Edit the files to fix the issue
- Run the tests again to verify
What Claude can access
This guide focuses on the terminal. Claude Code also runs in VS Code, JetBrains IDEs, and other environments. When you runclaude in a directory, Claude Code gains access to:
- Your project. Files in your directory and subdirectories, plus files elsewhere with your permission.
- Your terminal. Any command you could run: build tools, git, package managers, system utilities, scripts. If you can do it from the command line, Claude can too.
- Your git state. Current branch, uncommitted changes, and recent commit history.
- Your CLAUDE.md. A markdown file where you store project-specific instructions, conventions, and context that Claude should know every session.
- Extensions you configure. MCP servers for external services, skills for workflows, subagents for delegated work, and Claude in Chrome for browser interaction.
Work with sessions
Claude Code saves your conversation locally as you work. Each message, tool use, and result is stored, which enables rewinding, resuming, and forking sessions. Before Claude makes code changes, it also snapshots the affected files so you can revert if needed. Sessions are independent. Each new session starts with a fresh context window, without the conversation history from previous sessions. Claude can persist learnings across sessions using auto memory, and you can add your own persistent instructions in CLAUDE.md.Work across branches
Each Claude Code conversation is a session tied to your current directory. When you resume, you only see sessions from that directory. Claude sees your current branch’s files. When you switch branches, Claude sees the new branch’s files, but your conversation history stays the same. Claude remembers what you discussed even after switching. Since sessions are tied to directories, you can run parallel Claude sessions by using git worktrees, which create separate directories for individual branches.Resume or fork sessions
When you resume a session withclaude --continue or claude --resume, you pick up where you left off using the same session ID. New messages append to the existing conversation. Your full conversation history is restored, but session-scoped permissions are not. You’ll need to re-approve those.
--fork-session flag:
--fork-session to give each terminal its own clean session.
The context window
Claude’s context window holds your conversation history, file contents, command outputs, CLAUDE.md, loaded skills, and system instructions. As you work, context fills up. Claude compacts automatically, but instructions from early in the conversation can get lost. Put persistent rules in CLAUDE.md, and run/context to see what’s using space.
When context fills up
Claude Code manages context automatically as you approach the limit. It clears older tool outputs first, then summarizes the conversation if needed. Your requests and key code snippets are preserved; detailed instructions from early in the conversation may be lost. Put persistent rules in CLAUDE.md rather than relying on conversation history. To control what’s preserved during compaction, add a “Compact Instructions” section to CLAUDE.md or run/compact with a focus (like /compact focus on the API changes).
Run /context to see what’s using space. MCP servers add tool definitions to every request, so a few servers can consume significant context before you start working. Run /mcp to check per-server costs.
Manage context with skills and subagents
Beyond compaction, you can use other features to control what loads into context. Skills load on demand. Claude sees skill descriptions at session start, but the full content only loads when a skill is used. For skills you invoke manually, setdisable-model-invocation: true to keep descriptions out of context until you need them.
Subagents get their own fresh context, completely separate from your main conversation. Their work doesn’t bloat your context. When done, they return a summary. This isolation is why subagents help with long sessions.
See context costs for what each feature costs, and reduce token usage for tips on managing context.
Stay safe with checkpoints and permissions
Claude has two safety mechanisms: checkpoints let you undo file changes, and permissions control what Claude can do without asking.Undo changes with checkpoints
Every file edit is reversible. Before Claude edits any file, it snapshots the current contents. If something goes wrong, pressEsc twice to rewind to a previous state, or ask Claude to undo.
Checkpoints are local to your session, separate from git. They only cover file changes. Actions that affect remote systems (databases, APIs, deployments) can’t be checkpointed, which is why Claude asks before running commands with external side effects.
Control what Claude can do
PressShift+Tab to cycle through permission modes:
- Default: Claude asks before file edits and shell commands
- Auto-accept edits: Claude edits files without asking, still asks for commands
- Plan mode: Claude uses read-only tools only, creating a plan you can approve before execution
- Delegate mode: Claude coordinates work through agent teammates only, with no direct implementation. Only available when an agent team is active.
.claude/settings.json so Claude doesn’t ask each time. This is useful for trusted commands like npm test or git status. Settings can be scoped from organization-wide policies down to personal preferences. See Permissions for details.
Work effectively with Claude Code
These tips help you get better results from Claude Code.Ask Claude Code for help
Claude Code can teach you how to use it. Ask questions like “how do I set up hooks?” or “what’s the best way to structure my CLAUDE.md?” and Claude will explain. Built-in commands also guide you through setup:/initwalks you through creating a CLAUDE.md for your project/agentshelps you configure custom subagents/doctordiagnoses common issues with your installation
It’s a conversation
Claude Code is conversational. You don’t need perfect prompts. Start with what you want, then refine:Interrupt and steer
You can interrupt Claude at any point. If it’s going down the wrong path, just type your correction and press Enter. Claude will stop what it’s doing and adjust its approach based on your input. You don’t have to wait for it to finish or start over.Be specific upfront
The more precise your initial prompt, the fewer corrections you’ll need. Reference specific files, mention constraints, and point to example patterns.Give Claude something to verify against
Claude performs better when it can check its own work. Include test cases, paste screenshots of expected UI, or define the output you want.Explore before implementing
For complex problems, separate research from coding. Use plan mode (Shift+Tab twice) to analyze the codebase first: