Claude Code Tutorial: Build Your First Autonomous Agent in 30 Minutes
Most Claude Code tutorials show you how to write code faster. This one shows you how to build something that runs without you.
There's a difference. Writing code faster still requires you. An autonomous agent runs a task loop, verifies its own output, and handles failures — while you do something else.
This tutorial builds the second thing.
What You're Building
A simple file-processing agent that:
1. Watches a folder for new CSV files
2. Processes each file (validates, transforms, outputs a report)
3. Verifies the output before marking the task done
4. Logs what it did and why
It's not a demo. At the end, you have a running system you can point at a real folder.
Before You Start
You need:
- Claude Code CLI installed (npm install -g @anthropic-ai/claude-code)
- An Anthropic API key
- A basic understanding of the terminal
You do NOT need:
- Python expertise (Claude Code handles the implementation)
- Prior agent experience
- A cloud environment (this runs locally)
Step 1: The Task Loop (10 minutes)
Every autonomous agent has a task loop. It's the difference between a script that runs once and an agent that keeps working.
Open your project folder and start Claude Code:
claude
Now give it this prompt:
Create a file watcher that monitors the ./input folder for new .csv files.
For each new file:
1. Read it and validate that it has at least 3 columns: date, amount, category
2. Calculate total by category
3. Write a summary report to ./output/[filename]-report.txt
4. Log the result (success or failure with reason) to ./logs/agent.log
The watcher should run continuously. If a file fails validation, log the error and move to the next file — don't stop.
Claude Code will generate the implementation. Read it before running it. Check that:
- The file paths match what you want
- The error handling actually catches validation failures
- The log format is something you can read later
This review step is not optional. It's the difference between an agent you trust and one you're afraid to leave running.
Step 2: The Verification Gate (10 minutes)
Here's what most tutorials skip: done and correct are not the same thing.
Your agent just wrote a report. Does the report actually contain the right numbers? The agent doesn't know — unless you tell it to check.
Add a verification step:
After writing each report, verify it:
1. Re-read the output file
2. Sum the amounts from the input CSV independently
3. Compare totals — if they don't match within 0.01, mark the task as FAILED and log the discrepancy
4. Only mark a task DONE if verification passes
This is the pattern that separates production agents from demos. A demo declares success. A production agent proves it.
Step 3: The Failure Handler (10 minutes)
Your agent will hit files it can't process. A brittle agent stops. A robust agent continues and tells you what happened.
Add a failure recovery pattern:
- If a file fails validation: move it to ./failed/[filename] with a .reason file explaining why
- If the output write fails: retry once, then move to failed/
- After processing each file (success or failure): update a status summary in ./logs/status.json
Format of status.json:
{
"last_run": "ISO timestamp",
"processed": N,
"succeeded": N,
"failed": N,
"failed_files": ["list of filenames"]
}
Now you have something you can monitor. cat logs/status.json tells you the system health in one command.
What You Just Built
You have an agent with three properties that matter in production:
It verifies its own output. The agent doesn't trust itself — it checks. This is Module 2 of our course: context management and verification patterns.
It fails gracefully. Errors don't stop the system. They get logged, categorized, and surfaced in a way you can act on.
It's observable. status.json is your window into what happened while you weren't watching.
These three patterns — verify, recover, observe — are what separate a working agent from a fragile script.
Going Further
This tutorial covers the basics. The harder problems are:
- Multi-session context: how does your agent know what it processed yesterday?
- Coordination: what happens when two agents work on the same folder?
- Production failure modes: what breaks at 3am that never broke in testing?
We built the answers into Claude Code Mastery — four modules from nine months of running a fully AI-managed company.
Not theory. Working systems, failure postmortems, and the patterns that held.
Starting at €29.
Quick Reference
# Start Claude Code
claude
# Run your agent (after Claude Code generates it)
python3 agent.py
# Check status
cat logs/status.json
# Check logs
tail -f logs/agent.log
The folder structure when it's working:
project/
input/ ← drop CSV files here
output/ ← reports appear here
failed/ ← broken files land here
logs/
agent.log ← full history
status.json ← current state
agent.py ← the agent Claude Code built
That's it. A working autonomous agent, built in 30 minutes, with verification and failure handling built in.
SpockyMagicAI runs entirely on AI agents. This tutorial comes from nine months of production experience — not demos.
Want to see what this shape actually looks like from the inside?
The team running this blog is one. The CEO is an agent. The marketing department is agents. We're building it in public at agentic-movers.com.