This lesson is being recorded

Every video of this course is being uploaded to my YouTube channel. Subscribe so you do not miss it.

Bruno AshfordBruno Ashford @brunoashfordSubscribe

Module 10 · Lesson 10.2 · 12 min

Hands-Off Runs, Safely

Understand headless mode (claude -p), its limits, and how to give an unattended run only the permissions it needs.

Module 10
Agents That Work While You Sleep

Schedules, headless runs, hooks and one-word commands

Bruno Ashford
Bruno Ashford · Module 1001 / 12
The problem
A routine that depends on your memory is not a routine.
Bruno Ashford
Bruno Ashford · Module 1002 / 12
Lesson 10.1

Three ways to schedule

OptionRuns whereBest when
Cloud routine (/schedule)Anthropic cloudLaptop closed, sources are connectors or GitHub
Desktop scheduled taskYour computerYou use the Claude desktop app
launchd, cron, Task SchedulerYour computerFiles live locally, full control

Cloud routines are a research preview; check your plan's limits.

Bruno Ashford · Module 1003 / 12
Lesson 10.2

Headless, in one line

claude -p runs the work without the conversation.

  • Nobody is there to approve
  • Decide permissions in advance
  • dontAsk plus a short allowlist
  • Redirect output to a dated file
Bruno Ashford · Module 1004 / 12
Lesson 10.2

Safe defaults for unattended runs

  1. 1Read onlyStart with the Read tool
  2. 2dontAskAnything else is denied
  3. 3Right folderLoads your CLAUDE.md
  4. 4Never skip checksOnly in isolated containers
Bruno Ashford · Module 1005 / 12
Lesson 10.3
Instructions guide the agent. Hooks enforce the rules.
Bruno Ashford
Bruno Ashford · Module 1006 / 12
Lesson 10.3

Hooks you will actually use

EventWhen it runsUse it to
PreToolUseBefore an actionBlock risky commands
PostToolUseAfter an actionKeep an audit log
NotificationWhen Claude needs youGet a desktop alert
StopWhen Claude finishesRun a final check
Bruno Ashford · Module 1007 / 12
Lesson 10.4

One word, same result

Commands and skills are now the same thing.

  • Name becomes the slash command
  • $ARGUMENTS passes in the details
  • Manual-only for client-facing work
  • Share the .claude folder
Bruno Ashford · Module 1008 / 12
Lesson 10.5

The morning brief

  1. 1Yesterday in numbersSales, leads, cash
  2. 2RisksOverdue and at risk
  3. 3Needs youMessages only you can answer
  4. 4TodayMeetings and top three priorities
Bruno Ashford · Module 1009 / 12
Illustrative example, not research

One partner's mornings

50 to 12minutes to get oriented
6:45ambrief ready
1missed deadline caught in week one
Bruno Ashford · Module 1010 / 12
Project

Seven days in production

Trust is built with evidence, not hope.

  • One routine, scheduled
  • Hooks tested and firing
  • One log line per run
  • Improve the prompt on day seven
Bruno Ashford · Module 1011 / 12
Recap
The best automation is the work you find already done, checked and logged when you sit down.
Bruno Ashford
Bruno Ashford · Module 1012 / 12
01 / 12

Use ← → to move. The marker highlights text and the pencil draws on the slide; navigation locks while you annotate. Undo removes the last mark, Esc exits.

1Run your first headless command

From your business folder, run a read-only question with -p. Claude reads what it needs, prints the answer and exits. This is exactly what a scheduler will run for you later.

Terminal
claude -p 'Read finance/open-invoices.csv and list the five largest overdue invoices with client, amount and days late.'
2Send the output to a file

Headless output is plain text, so you can redirect it into a dated report. This means the agent only needs permission to read, not to write, which is a much safer starting point.

Terminal
claude -p "$(cat prompts/weekly-ops-check.md)" > "ops/reports/ops-check-$(date +%F).md"
3Lock it down with a permission mode and an allowlist

Add --permission-mode dontAsk and --allowedTools. In dontAsk mode, anything that would normally ask for your approval is denied, and only the tools you list (plus ordinary file reads in your folder) are allowed. For a report routine, Read is often all it needs.

Terminal
claude -p "$(cat prompts/weekly-ops-check.md)" --permission-mode dontAsk --allowedTools "Read" > "ops/reports/ops-check-$(date +%F).md"
4Get structured output when a script needs it

If another tool will read the result, ask for JSON with --output-format json. The response includes the text result, a session ID and an estimated cost, which you can record in your run log.

Terminal
claude -p 'Summarise this week in three bullet points from ops/reports' --permission-mode dontAsk --allowedTools "Read" --output-format json
5Know the limits

A headless run cannot ask you a clarifying question, so vague prompts produce vague work. It loads your CLAUDE.md, skills, hooks and MCP servers from the folder it runs in, so run it in the right folder. And never use the setting that skips all permission checks on your own computer; it is meant only for isolated containers.

When you work with Claude Code interactively, you are the safety net. It asks before running a command, and you can say no. At 7am on a Monday, nobody is there to say no. That changes the question from what can the agent do to what should it be allowed to do when nobody is watching.

Headless mode is simply Claude Code without the conversation: you run claude -p with a prompt, it does the work and prints the result. The skill is in the flags. You decide which tools it may use, and anything outside that list is refused instead of waiting for an approval that never comes.

Key points

  • claude -p runs Claude Code without the conversation.
  • Unattended means nobody can approve, so decide permissions in advance.
  • dontAsk plus a short allowlist is the safe default for routines.
  • Redirect output to a file so the agent only needs to read.

Avoid

  • Giving a scheduled run broad permissions because it worked interactively.
  • Using the skip-all-permissions option outside an isolated container.
  • Running the command from the wrong folder, so it misses your CLAUDE.md.
  • Writing a prompt that assumes it can ask you questions.
Real-world example: an e-commerce store

A US outdoor gear store ran its first headless stock report with no restrictions, and the agent helpfully decided to also tidy up the exports folder by renaming files. Nothing was lost, but the next day's import failed. The owner rebuilt the routine with dontAsk mode, Read only, and output redirected to a dated file. It has run every morning for four months without touching a single source file.

Bruno Ashford Subscribe