Back to Insights

How to Build Production AI Agents with Claude Code (2026)

By Dominik Fretz||7 min read
claude-codeai-agentsmcpsubagentsproduction

How to Build Production AI Agents with Claude Code

Most tutorials about Claude Code show you how to use it as a faster way to write code. That's fine, but it misses the bigger picture. Claude Code isn't just a coding assistant — it's an agent framework for building systems that think, plan, and execute autonomously.

I've shipped production agent systems using Claude Code for clients across multiple industries. As an Anthropic Claude Community Ambassador (one of 60 globally), I've also had early access to features that are now available to everyone. Here's how I actually build agents with this tool.

This isn't theory. These are the patterns I use in production and teach in my workshops.

The Building Blocks

Claude Code gives you several agent primitives that most people underuse:

Subagents — Claude can spawn child agents that work on specific tasks independently. The main agent coordinates, delegates, and aggregates results. This is how you parallelise work. Instead of one agent grinding through a 50-file refactor sequentially, you spawn 10 subagents that each handle a module.

MCP Servers (Model Context Protocol) — These give Claude access to external tools and data sources. Database connections, API integrations, file system access, browser control. MCP is how you make Claude useful beyond just writing code — it can query your database, read your Jira tickets, check your deployment status, and act on what it finds.

Worktrees — Git worktrees let you run multiple agents on isolated copies of your repository simultaneously. No merge conflicts between agents. Each one works on its own branch, and you merge when they're done. This is crucial for parallel agent workflows.

Hooks — Custom scripts that run at specific points in Claude's lifecycle. Before a tool call, after a response, when an error occurs. Hooks let you add guardrails, logging, and custom behaviour without modifying Claude's core logic.

Agent Teams — Now in research preview, agent teams let multiple Claude instances collaborate with shared memory. This is the cutting edge, and it's going to change how we think about complex development tasks.

The Architecture: How I Structure Agent Systems

Here's the pattern I use for any non-trivial agent system:

orchestrator (main Claude Code instance)
├── planner subagent (reads spec, creates implementation plan)
├── implementer subagents (one per module/feature, uses worktrees)
│   ├── module-a (worktree branch: agent/module-a)
│   ├── module-b (worktree branch: agent/module-b)
│   └── module-c (worktree branch: agent/module-c)
├── reviewer subagent (runs after implementation, checks quality)
└── integrator subagent (merges branches, runs full test suite)

The orchestrator doesn't write code. It manages the workflow. It reads the spec, delegates to the planner, distributes work to implementers, and coordinates review and integration.

Each implementer gets:

This pattern scales. I've run it with 2 implementer agents on small features and 8+ on large refactors. The key is that each agent has a clear, bounded scope.

MCP Servers: Making Agents Useful Beyond Code

The real power of Claude Code agents comes from MCP integrations. Here are the ones I use most:

Database MCP — Let your agent query production data (read-only) to understand the current state of the system. "What's the schema for the users table? How many active subscriptions do we have?" The agent can write better code when it understands the data it's working with.

GitHub/GitLab MCP — Let agents read issues, create PRs, and check CI status. An agent that can read a Jira ticket, implement the feature, create a PR, and respond to review comments is dramatically more autonomous than one that just writes code in a terminal.

Browser MCP (Claude in Chrome) — For agents that need to interact with web applications. Testing UIs, scraping documentation, verifying deployments. I use this for end-to-end verification — the agent deploys, then uses the browser to check that the deployment actually works.

File system + Slack MCPs — For agents that need to communicate status. An agent that posts its progress to a Slack channel while you're in a meeting is genuinely useful.

The Guardrails: CLAUDE.md and Why It Matters

Every project I work on has a CLAUDE.md file in the root. This is Claude Code's project memory — it reads this file at the start of every session. Here's what mine typically includes:

# Project: [name]

## Stack
- TypeScript, Bun, Biome
- TanStack Router for frontend
- Drizzle ORM + PostgreSQL
- Deployed on Cloudflare Workers

## Rules
- Strict TypeScript only. No `any` type.
- All new functions must have tests.
- No direct database queries outside the data layer.
- Use Biome for formatting. Do not use Prettier or ESLint.
- Commit messages follow conventional commits.

## Architecture
[Brief description of the system architecture]

## Current Sprint
[What we're working on now, linked to spec files]

This isn't just documentation — it's behavioural control for the AI agent. Every subagent spawned from this project inherits these rules. It's the difference between an agent that produces whatever code works and one that produces code that fits your team's standards.

Context Management: The Part Everyone Gets Wrong

Here's the insight that separates productive Claude Code users from frustrated ones: context is a depletable resource, and managing it is an engineering discipline.

Most people start a Claude Code session, work for an hour, and wonder why the output quality degrades. The context window fills up with accumulated conversation, previous attempts, error messages, and tangential explorations. The agent starts hallucinating because it's drowning in noise.

My approach:

  1. Keep context files, not context conversations — specs, plans, and guardrails live in files. The agent reads them fresh each session.
  2. Clear sessions frequently — when starting a new task, start a new session. Don't carry baggage from the last feature into the next one.
  3. Use subagents for isolation — each subagent gets its own context. The orchestrator passes only what's relevant.
  4. Check /usage regularly — know where you are in your token budget. If you're at 80%+ of your window, clear and restart.

Think of Claude sessions like containers. Keep the artifacts. Reset the runtime. Fresh context from actual files beats accumulated conversation every time.

What's Coming Next

Claude Code Opus 4.6 is now the default model with a 1 million token context window. Agent teams are in research preview. Voice mode just shipped. The loop command lets you run prompts at intervals.

The trajectory is clear: Claude Code is becoming less of a "coding assistant" and more of an "engineering platform." The agents you build today will be more capable tomorrow, and the patterns you learn now will compound.

Start Building

If you want to learn these patterns hands-on, I run a Claude Code Masterclass where we build a real agent system from scratch using the framework described here. Half-day intensive, small groups, you leave with working code and a methodology you can apply immediately.

I also run team transformation workshops for engineering teams who want to adopt agentic development practices org-wide.

Dominik Fretz | Anthropic Claude Community Ambassador | LinkedIn

Want to discuss agentic AI engineering?

I help engineering teams adopt AI without creating tomorrow's legacy nightmare.

Book a Discovery Call