Skip to main content

Guide

How Claude Code’s Agent System Works

The four layers of Claude Code's agent system and how they connect to the agentic loop.

By The Codegen Team · Updated June 2026

Key insight
Claude Code's agent system has four layers that stack on each other. CLAUDE.md sets behavioral rules that load every session, skills add on-demand workflows, MCP servers connect external tools, and hooks enforce mechanical rules deterministically. You only need CLAUDE.md to start building.
Key takeaways
  • CLAUDE.md loads into every session automatically. It is the baseline that makes Claude follow your project's conventions.
  • Skills load on demand when invoked or contextually matched, so they cost context only when needed.
  • MCP servers let Claude interact with GitHub, Slack, databases, and other tools through a standard protocol.
  • Hooks fire shell commands at lifecycle events without AI involvement, providing guaranteed enforcement where behavioral guidance falls short.
  • Start with CLAUDE.md alone. Add skills, MCP, and hooks as your agent workflow grows.

What Are the Building Blocks?

The configuration breaks into four layers. Each one adds a different kind of capability to the agentic loop covered in the previous lesson.

CLAUDE.md is the rules file. It tells Claude how to behave in your project. Skills are reusable markdown instructions that add new commands and workflows. MCP servers connect Claude to external services like GitHub, databases, and browsers. Hooks run shell commands automatically at specific points in the session lifecycle, with no AI involvement.

You do not need all four to build something useful. A well-written CLAUDE.md alone makes Claude Code noticeably better at following your project’s conventions. Each additional layer adds capability, but the system works from day one with just the rules file.

How Does CLAUDE.md Set the Baseline?

CLAUDE.md is a markdown file in your project root. Claude reads it at the start of every session and follows its instructions throughout. Think of it as a briefing document that stays active for the entire conversation.

# CLAUDE.md

## Build Commands
- Run tests: npm test
- Run dev server: npm run dev
- Lint: npm run lint

## Code Conventions
- Use TypeScript strict mode. No `any` types.
- Prefer named exports over default exports.
- Write tests for every new function.

## Do Not
- Do not commit directly to main.
- Do not delete migration files.

This is a minimal but complete example. The build commands section saves Claude from guessing how to run your project. The conventions section prevents common AI coding mistakes. The restrictions section blocks destructive actions. In practice, most productive CLAUDE.md files are 20 to 50 lines. Every line costs tokens because it loads into every request, so conciseness matters.

What Do Skills, MCP Servers, and Hooks Add?

Skills are markdown files stored in .claude/skills/. Each one teaches Claude a specific workflow and creates a slash command you can invoke. A /deploy skill loads only when you type /deploy. A code review skill can load automatically when Claude detects a review-related task. The key distinction from CLAUDE.md is that skills load on demand. They do not consume context until they are needed.

MCP servers connect Claude to external tools. A GitHub MCP server lets Claude read pull requests, create issues, and check CI status without leaving the terminal. A Postgres MCP server lets Claude query your database directly. Each server runs as a separate process and exposes its capabilities as callable tools. You configure them once and Claude uses them whenever the task requires external data.

Hooks are fundamentally different from both. They are shell commands that fire on lifecycle events like file edits, tool calls, and session start. A PostToolUse hook that runs prettier --write after every file edit does not depend on Claude deciding to format the code. It just runs. Hooks are where you enforce rules that CLAUDE.md can only suggest. If CLAUDE.md says “always format code after editing,” Claude might forget. A hook never forgets.

How Do the Layers Stack Together?

Here is what a configured project directory looks like with all four layers in place:

my-project/
├── CLAUDE.md                  # Always loads. Project rules.
├── .claude/
│   ├── skills/
│   │   └── deploy/
│   │       └── SKILL.md       # Loads when /deploy is invoked
│   ├── settings.json          # Hooks and MCP server config
│   └── rules/                 # Scoped rules (load selectively)
├── src/
└── tests/

CLAUDE.md at the root always loads. Files in .claude/rules/ load selectively based on relevance, which makes them cheaper for rules that only apply to certain parts of the codebase. Skills sit in their own directories. Hooks and MCP servers are configured in settings.json.

The layers build on each other in a natural progression. Start with CLAUDE.md for project rules. Add skills when you find yourself repeating the same multi-step workflow. Connect MCP servers when you need Claude to interact with external tools. Wire up hooks when you need guarantees that CLAUDE.md’s behavioral guidance cannot provide.

The next three lessons walk through CLAUDE.md, skills, and MCP servers hands-on. You will configure each one in your own project.

What's next

Keep building on what you just learned.

Frequently Asked Questions

Build faster with AI-powered agents

See how Codegen automates the full development workflow — from ticket to pull request.

Get Started →