Most "build an AI agent" tutorials end at the API call. They show you how to send a prompt and parse a response. That is not an agent. That is a script with a language model in it.
This post is different. I am going to walk you through the exact architecture I use to run a Claude Code autonomous agent 24/7 on a $600 Mac Mini. It handles email triage, calendar management, task delegation to four sub-agents, financial dashboard monitoring, and messaging-based human interaction — all without me touching it.
The agent has been running continuously for weeks. I assign it 12 tasks before bed, and they are done by morning.
Here is how the whole thing works.
What Claude Code CLI Actually Is (And Why It Matters)
If you have used Claude on claude.ai, you have used the chat interface. If you have hit the Anthropic API, you have used the raw model. Claude Code is neither of those.
Claude Code is Anthropic's official CLI tool. You install it globally with npm, and it gives you a terminal-native AI agent that can:
- Read and write files on your local filesystem
- Execute shell commands directly (bash, git, curl, ssh — anything)
- Connect to external services via MCP (Model Context Protocol) servers
- Maintain persistent context through a
CLAUDE.mdfile it reads on startup - Run headlessly with
claude -p "prompt"for scripted, non-interactive execution
That last point is the key. Claude Code is not just a fancy chat window. It is a programmable agent runtime that can operate without human input.
# Install it globally
npm install -g @anthropic-ai/claude-code
# Interactive mode
claude
# Headless mode — this is what makes autonomous agents possible
claude -p "Check my email for anything urgent and summarize it"
The headless -p flag is what separates Claude Code from every other AI interface. You can call it from cron, from a script, from another agent. It reads CLAUDE.md for context, executes the task, and exits. No human in the loop.
The Architecture: How a Claude Code Autonomous Agent Actually Runs
Here is the full stack, top to bottom:
+-------------------------------------+
| Messaging App (Human Interface) | ← Human interface
+-------------------------------------+
| tmux session (persistent) | ← Keeps agent alive
| +-- Claude Code CLI | ← The agent runtime
| |-- CLAUDE.md (identity) | ← Who the agent IS
| |-- MCP: Gmail | ← Read/draft emails
| |-- MCP: Google Calendar | ← Manage schedule
| |-- MCP: Supabase | ← Task queue, brain dumps
| |-- MCP: Stripe | ← Payment monitoring
| |-- MCP: Notion | ← Knowledge base
| |-- MCP: Vercel | ← Deployment management
| +-- Shell access (ssh, etc.) | ← Infrastructure control
+-------------------------------------+
| Mac Mini M4 | ← Always-on hardware
+-------------------------------------+
The critical insight: Claude Code is not the whole system. It is the brain. Everything else — MCP servers, tmux, messaging, cron — is the nervous system that lets the brain operate continuously and interact with the real world.
Step-by-Step: Setting Up a Persistent Claude Code Autonomous Agent
Step 1: Install Claude Code CLI
npm install -g @anthropic-ai/claude-code
Set your API key or authenticate with your Anthropic account. If you are running on a dedicated machine, the Max plan ($200/month) gives you Opus-level intelligence. The Pro plan ($20/month) gives you Sonnet, which honestly handles 80% of tasks just fine — more on that later.
Step 2: Write a CLAUDE.md Identity File
This is where most people underinvest. The CLAUDE.md file is not a system prompt. It is the agent's entire identity, knowledge base, and operating manual. Claude Code reads it automatically on every startup.
Here is the structure I use:
# AI Chief of Staff
## Soul
You anticipate needs before being asked. You organize chaos into clarity.
You protect the founder's time and attention.
## Identity
You are not a chatbot waiting for instructions.
You are a trusted right hand.
## Businesses (context the agent needs)
| Business | Type | Key Context |
|----------|------|-------------|
| Service Company | S-corp | Mid six-figure revenue, small crew |
| AI Products | Studio | Building playbook products |
## Infrastructure (what the agent can access)
| Service | Location | Notes |
|---------|----------|-------|
| PostgreSQL | NAS:5432 | Financial data |
| Vault | NAS:8200 | Secrets management |
## Permissions
### Do Without Asking
- Read emails, calendar, databases
- Draft documents (save as drafts only)
- Create and assign tasks to sub-agents
### Requires Approval
- Sending any external message
- Financial transactions over $100
- Modifying infrastructure
The permissions section is crucial. A Claude Code autonomous agent with filesystem and shell access is powerful. You need explicit guardrails written into its identity, not bolted on after the fact.
Step 3: Start in tmux for Persistence
Claude Code runs as a terminal process. If your terminal closes, the agent dies. tmux solves this.
# Create a named session
tmux new-session -d -s agent
# Attach and start Claude Code
tmux send-keys -t agent 'cd ~/project && claude' Enter
Now you can detach (Ctrl+B, D), close your laptop, and the agent keeps running on the Mac Mini. Reconnect anytime with tmux attach -t agent.
Step 4: Connect MCP Servers for External Services
MCP (Model Context Protocol) is how Claude Code talks to the outside world. Each MCP server exposes tools — functions the agent can call. You configure them in your Claude Code settings:
{
"mcpServers": {
"gmail": {
"type": "url",
"url": "https://mcp.anthropic.com/gmail"
},
"google-calendar": {
"type": "url",
"url": "https://mcp.anthropic.com/google-calendar"
},
"supabase": {
"type": "url",
"url": "https://mcp.anthropic.com/supabase"
}
}
}
With these connected, the agent can read your email, check your calendar, query your database, and message you — all within a single Claude Code session.
Step 5: Configure a Messaging Interface
A messaging app becomes your command channel. When the agent needs to notify you, it sends a message. When you need to give the agent a task, you message it.
This is what makes the setup feel like having a real assistant. You text "morning briefing" and within 30 seconds, the agent checks your calendar, scans your email, reviews pending tasks, and sends back a structured summary.
The Cron Pattern: Scheduled Autonomous Tasks
The interactive tmux session handles ad-hoc requests. But the real power is scheduled execution:
# Every 2 hours during business hours, check for urgent items
0 7-23/2 * * * cd ~/project && claude -p "Check Gmail for urgent emails. \
Check Supabase for pending brain dumps. If anything is urgent, notify me."
# Daily at 6 AM, prepare morning briefing
0 6 * * * cd ~/project && claude -p "Prepare my morning briefing: \
today's calendar, urgent emails, pending tasks, agent status updates."
# Weekly on Monday at 7 AM, generate summary
0 7 * * 1 cd ~/project && claude -p "Generate weekly summary: \
completed tasks, revenue updates, outstanding items."
Each claude -p invocation is a fresh session that reads CLAUDE.md, understands its identity and context, executes the task, and exits. No state leakage between runs. Clean, predictable, auditable.
The Multi-Agent Layer: Delegating to Sub-Agents
The chief of staff agent does not do everything itself. It delegates to four specialized CEO agents, each with their own CLAUDE.md identity file:
- Agent 1 — Product and revenue strategy (runs every 4 hours)
- Agent 2 — Operations for the contracting business (runs every 6 hours)
- Agent 3 — E-commerce brand marketing (runs every 8 hours)
- Agent 4 — Home services business (runs every 12 hours)
The coordination mechanism is simple: Supabase acts as a shared task queue. The chief of staff writes tasks to a database table with the target agent and a pending status. When the target agent's cron fires, it queries for its pending tasks, executes them, and marks them complete.
-- Chief of staff assigns a task
INSERT INTO tasks (content, category, delegated_to, status)
VALUES ('Draft Q1 revenue report', 'operations', 'agent_2', 'pending');
-- Agent 2 picks it up on next cron run
SELECT * FROM tasks WHERE delegated_to = 'agent_2' AND status = 'pending';
No custom orchestration framework. No LangChain. No agent framework du jour. Just a database table and cron jobs running claude -p. It is boring infrastructure, and it works.
The Overnight Shift: 12 Tasks, Zero Supervision
Here is what a typical evening handoff looks like. Before bed, I send the agent a batch of tasks:
"Tonight's list: Draft the Q1 invoice summary. Check if any subscriptions are past due. Research contractor bonding requirements. Update the dashboard pending transactions count. Draft a response to that vendor email. Review the landing page copy..."
The chief of staff triages each item. Some it handles directly (email drafts, research, data queries). Others it delegates to the appropriate sub-agent. By 6 AM, my morning briefing includes status on all twelve items — most completed, a few flagged for my review.
That is the difference between using AI as a tool and running AI as an autonomous agent. Tools wait for you. Agents work while you sleep.
Pro vs Max: When Sonnet Is Enough
Running Opus 24/7 costs $200/month on the Max plan. That is worth it during a sprint when you are building complex systems. But for steady-state operations, Sonnet on the Pro plan ($20/month) handles roughly 80% of agent tasks without issue.
Sonnet handles well: Email triage, calendar management, task routing, database queries, file operations, template-based content, status checks.
Opus is worth it for: Complex multi-step analysis, nuanced writing, architecture decisions, debugging tricky infrastructure issues, anything requiring deep reasoning across many files.
My approach: sprint on Max when building, drop to Pro when operating. The CLAUDE.md file and MCP configuration stay identical — you are just swapping the model underneath.
What This Is Not
This is not a toy demo. It is not a weekend project you show off and never use again. The agent has been running in production for real businesses, handling real email, managing a real calendar, delegating real tasks to real sub-agents that produce real deliverables.
But it is also not magic. You still need to:
- Write a thorough
CLAUDE.md(mine is 200+ lines) - Set up proper permissions boundaries
- Monitor outputs, especially early on
- Handle OAuth token refreshes and infrastructure maintenance
- Accept that the agent will occasionally get things wrong
The advantage is not perfection. It is leverage. One person managing multiple businesses with an AI chief of staff and AI department heads, running on a Mac Mini.
Get the Full Blueprint
This post covers the architecture. The Ax Playbook covers everything else: the complete multi-agent system design, every CLAUDE.md template, the database schema, cron configurations, bot setup, MCP server configs, and the operational playbook for running AI agents in production.
If you are building with Claude Code and want to skip the months of trial and error, the Playbook is the shortcut.