How I Built an Autonomous AI Agent with Claude Code
Most people use AI as a chatbot. I turned it into a 24/7 autonomous agent that pulls analytics, drafts content, publishes to social media, and learns from every session — all running on my Mac while I sleep.
Here is how I built it, and how you can too.
The Problem
I run two products: Notipo (a SaaS that syncs Notion to WordPress) and Build & Automate (a Skool community for builders). Marketing both while working a full-time consulting job meant content was always the thing that slipped.
I needed a system that could handle the repetitive parts of marketing autonomously — pulling analytics, drafting posts, publishing content — while keeping me in control of what actually goes live.
The Architecture
The system has four components:
- The Daemon — Claude Code running inside a tmux session, connected to Discord. This is the brain. It stays alive 24/7 and auto-restarts if it crashes.
- The Autonomous Loop — A bash script that runs every 30 minutes via macOS launchd. It checks what tasks are due, then sends prompts into the daemon.
- The Memory System — Six layers of persistent files so the agent never forgets what works, what failed, and what I prefer.
- MCP Tools — Model Context Protocol servers that give the agent direct API access to YouTube, X, Bluesky, Discord, Skool, and more.
How It Works
Every 30 minutes, the autonomous loop wakes up and checks a state file to see what is due:
# The state file tracks what already ran
daily:2026-04-01
goalcheck:2026-04-01
content:2026-03-31
social:2026-03-31
skool:2026-03-29
Tasks fall into two categories:
Silent tasks (no approval needed):
- Pull YouTube 7-day analytics
- Pull Bluesky post engagement stats
- Review daily logs and update learnings
- Check goal gaps
- Scan trending topics on Bluesky
Approval-required tasks (drafted and sent to Discord):
- Social media post drafts for X and Bluesky
- Content proposals (video ideas, blog topics)
- Skool community posts
- Skool classroom lessons
The key insight: nothing publishes without my explicit approval. The agent drafts, I approve from my phone via Discord.
The Memory System
This is what makes it more than a chatbot. The agent has six layers of persistent memory:
Layer 1: Bootstrap files — CLAUDE.md defines behavior rules. SOUL.md defines personality and tone. USER.md tells the agent who I am, what my voice sounds like, and what my audience cares about.
Layer 2: Observations — After each conversation, an observer script extracts tagged observations like “space/science Shorts get 10x more views” or “user prefers no trailing summaries.”
Layer 3: Dream cycle — A cron job runs at 3 AM every night. It deduplicates observations, expires stale ones, and promotes recurring patterns to the learnings file.
Layer 4: Daily logs — What happened each day: actions taken, outcomes, decisions, errors.
Layer 5: Curated learnings — The distilled brain. Patterns that work, rules from past mistakes. The agent reads this before every task.
Layer 6: Retrieval — Search across all layers before making decisions.
The result: the agent gets smarter every day. It knows my top-performing YouTube content is space/science Shorts. It knows to use Edge TTS with the Andrew voice. It knows not to use markdown tables in Discord.
The Daemon Setup
The daemon is a bash script that starts Claude Code in a tmux session:
#!/bin/bash
SESSION="claude-daemon"
tmux kill-session -t "$SESSION" 2>/dev/null
tmux new-session -d -s "$SESSION" -x 200 -y 50 '
while true; do
claude \
--channels plugin:discord@claude-plugins-official \
--permission-mode bypassPermissions &
CLAUDE_PID=$!
sleep 12
tmux send-keys "Read CLAUDE.md for context." Enter
wait $CLAUDE_PID
sleep 5
done
'
A launchd plist makes it start on boot and restart on crash. The autonomous loop has its own launchd plist that fires every 1800 seconds (30 minutes).
What It Actually Does
Here is what a typical day looks like:
Morning (automatic):
- Pulls YouTube analytics: 2,850 views last week, +9 subscribers
- Pulls Bluesky engagement stats
- Checks goals: social followers is the biggest gap
- Logs everything to daily analytics file
Every 3 days (sends to Discord for approval):
- Drafts a social media post with a Gemini-generated image
- Proposes 2-3 content ideas based on what is performing
- Drafts a Skool community post
Weekly:
- Compiles a performance report across all platforms
- Drafts a Skool classroom lesson based on what was built that week
The Results
In the first autonomous cycle, the agent:
- Pulled YouTube analytics and identified that my space/science Shorts are driving 93% of traffic
- Checked Bluesky stats (7 followers, 17 posts)
- Identified social followers as the biggest goal gap
- Drafted a post about the autonomous agent itself
- Generated an image with Google Gemini
- Posted to both X and Bluesky after my approval
- Created a Skool community post with an image
- Published a 5-lesson course in the Skool classroom
All from Discord on my phone. I approved with a text reply. The agent did the rest.
Try It Yourself
The full implementation — daemon script, autonomous loop, memory system, launchd configs — is documented step by step inside my community.
Join Build & Automate to get the complete setup guide and build your own autonomous agent.
This blog post was written in Notion and published to WordPress automatically using Notipo — another tool I built to eliminate manual publishing workflows.