The --print (-p) flag in Claude Code is the most underrated feature for building autonomous AI agents.
Most people use Claude Code interactively. But with -p, you can run fully headless sessions where Claude:
- Reads files, writes code, executes commands
- Has access to the full tool suite (Bash, Read, Write, Edit, Glob, Grep)
- Works within a budget cap (
--max-budget-usd) - Outputs its entire work log to stdout
Here's exactly how I use it to run a developer tools business automatically.
The basic pattern
claude \
-p "You are an autonomous agent. Execute these tasks: ..." \
--dangerously-skip-permissions \
--add-dir /path/to/project \
--model sonnet \
--max-budget-usd 3
Key flags:
-
-p "$PROMPT"— non-interactive mode, executes prompt and exits -
--dangerously-skip-permissions— bypasses all tool permission prompts -
--add-dir— makes additional directories available as context -
--max-budget-usd— hard spend cap per session -
--model— which Claude model to use
Running it on a schedule
I use macOS launchd plists to trigger sessions 3x/day:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" ...>
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.myagent.morning</string>
<key>ProgramArguments</key>
<array>
<string>/bin/bash</string>
<string>/path/to/agent_wake.sh</string>
<string>morning</string>
</array>
<key>StartCalendarInterval</key>
<dict>
<key>Hour</key>
<integer>6</integer>
<key>Minute</key>
<integer>0</integer>
</dict>
</dict>
</plist>
Load it: launchctl load ~/Library/LaunchAgents/com.myagent.morning.plist
Writing effective autonomous prompts
The prompt structure matters a lot for headless sessions:
You are [agent name] — an AI agent autonomously running [business].
[Human] is NOT present. Execute all of the following without asking any questions.
CONTEXT:
- [Key facts about the business/environment]
- [Available scripts and their locations]
- [Current status/state]
TASKS (execute in order):
1. [Specific task with exact file paths]
2. [Specific task with exact commands]
3. [Write a report documenting what you did]
Work autonomously. If something is blocked, log it and move on. Never stop to ask a question.
Critical rules for autonomous prompts:
- Be specific about file paths — no "somewhere in the project"
- Give fallback instructions — "if X fails, log it and do Y instead"
- End with a report task — the agent documents its own work
- Set budget expectations — "this should cost < $2"
What can go wrong
-
Infinite loops — always set
--max-budget-usd -
Permission errors — use
--add-dirfor every directory you need - Ambiguous prompts — the agent will pick an interpretation, may not be the one you wanted
- Context overflow — very long sessions can lose early context; break tasks into multiple sessions
The result
With this pattern, I run an entire developer tools business with zero daily human input:
- 500+ dev.to articles published
- Stripe payment delivery automated
- Daily analytics logged
- Content queue maintained
The agent files its own daily reports, tracks its own progress, and escalates genuine blockers that need human input.
This is how whoffagents.com operates — products, content, and delivery all managed by a Claude Code agent.
Part of the whoffagents.com developer tools stack — MCP servers, AI starter kits, Claude Code skill packs
Top comments (0)