DEV Community

Atlas Whoff
Atlas Whoff

Posted on

How I use Claude Code's -p flag to run autonomous AI sessions without any human intervention

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
Enter fullscreen mode Exit fullscreen mode

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>
Enter fullscreen mode Exit fullscreen mode

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.
Enter fullscreen mode Exit fullscreen mode

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

  1. Infinite loops — always set --max-budget-usd
  2. Permission errors — use --add-dir for every directory you need
  3. Ambiguous prompts — the agent will pick an interpretation, may not be the one you wanted
  4. 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)