Skip to main content

35 - Letting Claude Code Work Alone: /goal, Auto Mode, Background Sessions and Their Limits

An unattended Claude Code job is safe with three brakes written beforehand: a verifiable stop criterion, minimal permissions and a spending cap.

What do you think about this article?

35 - Letting Claude Code Work Alone: /goal, Auto Mode, Background Sessions and Their Limits
Claudefedericocalo.dev

At a Glance

An unattended Claude Code job is safe with three brakes written beforehand: a verifiable stop criterion, minimal permissions and a spending cap.

The problem: you launch it, go to dinner, and do not know what it might do

A long Claude Code session, left alone, is a case in which caution cannot be a habit: if you sit in front of the screen you press "allow" at every step, if you leave somebody has to decide in your place, and that somebody must have been instructed beforehand. The short answer of this article is that autonomy is as safe as three things written before pressing Enter: a stop criterion that a command can verify, a permission level as small as still lets the work happen, and a spending cap. If even one of the three is missing, a long session is a risk, not a convenience. On top of that you need a fence: a job that can go wrong must go wrong in a copy, not in your working folder.

In the article you will see what I verified (the options your version of Claude Code knows, a stop criterion run on a test repository) and what I did not: I did not let any session work alone, so you will not find the story of a night that went well. For the basic security of permissions read first Security and Privacy with Claude Code; for the spending cap What a Claude Session Costs; for the monitoring tools, born with an earlier version, the snapshot Auto Mode, /loop and Monitor.

First brake: a stop criterion that a command can verify

"Finish when you are done" is not a criterion. A criterion is a sentence like "the tests pass and no file outside src/ and tests/ has changed", because a command can tell you yes or no without asking Claude. The /goal command, according to the commands page, makes Claude work over several turns until the condition is met or the goal closes for another reason. According to the dedicated page, after every turn a small, fast model compares the condition with what Claude has shown in the conversation: it does not run commands and does not read files on its own. So write the goal so that it coincides with a command, so that the condition says how to prove it (for example "npm test exits with 0") and so that you run that command yourself at the end, on your own account: the evaluator's judgement remains the judgement of a model on a text.

arresto.sh - run on a test git repository in three different states
#!/bin/sh
# Criterio di arresto verificabile: i test passano E nessun file fuori da src/ e tests/ e' cambiato.
set -u
python3 -m unittest discover -q tests >/dev/null 2>&1 || { echo "ARRESTO NEGATO: i test falliscono"; exit 1; }
fuori=$(git status --porcelain | awk '{print $2}' | grep -v -E '^(src|tests)/' || true)
if [ -n "$fuori" ]; then
  echo "ARRESTO NEGATO: file modificati fuori da src/ e tests/:"; echo "$fuori"; exit 1
fi
echo "ARRESTO CONFERMATO"

# Output:
# 1) copia pulita
# ARRESTO CONFERMATO
# exit=0
# 2) un test rotto
# ARRESTO NEGATO: i test falliscono
# exit=1
# 3) test verdi ma un file fuori perimetro
# ARRESTO NEGATO: file modificati fuori da src/ e tests/:
# config.ini
# exit=1

The test repository has a function doppio and a test. In the first state everything is in order and the script confirms. In the second I broke the function: the tests fail and the script denies, with a short message because I redirected the output of unittest to nothing (you want the detail of the failure in the log, not in the verdict). In the third the tests pass but there is a config.ini file outside src/ and tests/: the script denies all the same, and it is the case that matters most, because an agent that "makes the tests pass" by touching a configuration has solved the wrong problem. The git status --porcelain line also sees untracked files, which git diff would ignore.

Second brake: the lowest permission level that is enough

Permissions decide what Claude can do without asking. The list below sums up the modes according to the permissions page; the choice for an unattended job depends on how much you trust the fence, not on how much you trust Claude.

  • dontAsk: reads in the working folders and uses the pre-approved tools, everything else is denied; the page indicates it for CI and locked-down scripts;
  • acceptEdits: edits files and uses common filesystem commands without asking, the rest asks;
  • auto: a second model, the classifier, reviews the actions in your place;
  • bypassPermissions: everything goes through, and the page reserves it for isolated containers and virtual machines.

The order is not decorative: it goes from most restrictive to least restrictive, and every step moves the responsibility from a rule you wrote to somebody else's judgement. For a long, attended job auto reduces interruptions; for a night job on a repository you would not forgive yourself for losing, dontAsk with explicit consent rules is the choice you can explain afterwards, because every permitted action sits in a list you wrote. Two facts that weigh: deny rules apply in every mode, even bypassPermissions, and some actions (for example the removal of critical paths) are not approved automatically by any mode.

Third brake and the fence: the cap and the isolated copy

The cap is --max-budget-usd, covered in the article on costs: it works in -p mode, it also counts the sub-agents, and it is checked against an estimate. The fence is -w / --worktree, which creates a separate git working copy for the session, and --bg, which starts the session in the background and prints an identifier with which claude agents, claude attach, claude logs and claude stop manage it. Before trusting these options, check that your version knows them: the help changes between versions, and a script that passes an unknown option fails in the middle of the night.

preflight.py - run with python3 -I against Claude Code 2.1.325 installed here
"""Prima di lasciare Claude Code da solo: la versione installata conosce davvero i tre freni?"""
import re
import subprocess
import sys

FRENI = {
    "permessi": "--permission-mode",
    "tetto di spesa": "--max-budget-usd",
    "isolamento": "--worktree",
}
ALTRI = ("--bg", "--output-format", "--effort")


def leggi_aiuto():
    giro = subprocess.run(["claude", "--help"], capture_output=True, text=True, timeout=60)
    return giro.stdout


def modalita_dichiarate(aiuto):
    """Le scelte che l'aiuto elenca per --permission-mode, ad esempio (choices: "a", "b")."""
    blocco = re.search(r"--permission-mode <mode>.*?\(choices:\s*([^)]*)\)", aiuto, re.S)
    return re.findall(r'"([^"]+)"', blocco.group(1)) if blocco else []


def controlla(aiuto):
    mancanti = [f"{nome} ({flag})" for nome, flag in FRENI.items() if flag not in aiuto]
    mancanti += [flag for flag in ALTRI if flag not in aiuto]
    return mancanti


if __name__ == "__main__":
    testo = leggi_aiuto()
    mancanti = controlla(testo)
    print("modalita' dichiarate:", ", ".join(modalita_dichiarate(testo)) or "nessuna letta")
    print("mancanti:", ", ".join(mancanti) or "nessuno")
    sys.exit(1 if mancanti else 0)

# Output:
# modalita' dichiarate: acceptEdits, auto, bypassPermissions, manual, dontAsk, plan
# mancanti: nessuno
# exit=0

The script reads the real help (claude --help), looks for the three brakes and the three surrounding options, and from the --permission-mode line extracts the modes the version declares. The result on this machine confirms everything and shows a useful detail: the help calls manual the mode that the documentation calls default, and says that manual is an accepted alias. If an option were missing, the exit code would be 1: you can put it at the start of a night script, before everything else. The test with a deliberately truncated help returns the list of missing options.

Putting the pieces together: a launch with the three brakes

The launch below joins the fence (worktree on a new branch), the permissions (auto), the cap (2 USD, a value given as an example) and the final verdict entrusted to arresto.sh. It is a template to adapt and I did not run it: it requires a key and a real session. Note that the verdict is the last line and it is given by a command of yours; the JSON of the job is a by-product to read afterwards, not the proof of the result.

night launch - template to adapt, not executed (it requires a key)
git worktree add ../prova-notturna -b prova/notturna
cd ../prova-notturna
claude -p "Porta la copertura dei test del modulo src/ al 90% senza toccare altro" \
  --permission-mode auto \
  --max-budget-usd 2.00 \
  --output-format json > ../risultato-notturno.json
echo "exit=$?"
./arresto.sh

The prova/notturna branch is the way to make the experiment reversible: if the verdict is negative, you delete the branch and the copy, and your work has not been touched. The trade-off is that a job in an isolated copy does not see the uncommitted changes of your main folder: commit first, or start from a clean commit.

Status as of 2026-11-14: mode names and commands

Reread on the official pages and on the help of Claude Code 2.1.325 on 2026-11-14. According to the permissions page, since version 2.1.283 the auto mode is the starting one for interactive sessions in the terminal and in VS Code, so you may already be using it without knowing: check with an explicit claude --permission-mode. The names of the modes and of the commands (/goal, claude agents) are new and may change.

What stays true with the next generation

What stays true is the rule of the three brakes written beforehand, the stop criterion as a command you run, the choice of permissions for what you can lose and not for what you trust, and the work in an isolated copy. The names of the options and of the modes will change: that is why the preliminary check reads the help instead of taking the options for granted.

What I did not verify

I did not let any session work alone and I did not run --bg: the key is missing. The cap and --bg cannot be combined in the same launch: according to the options page --max-budget-usd only works with -p, and --bg does not pair with -p. I did not reread ScheduleWakeup and Monitor in the current version: they are not part of the thesis. The classifier of the auto mode is a model: I did not measure how often it gets it wrong.

Frequently asked questions

Is --max-budget-usd enough to leave a job alone?

No: it stops the spend, not the damage. A job that stays within the money can still modify files it should not: you also need a stop criterion that verifies the result and a restricted permission level.

When is bypassPermissions acceptable?

According to the permissions page only in isolated containers and virtual machines, where nothing the agent can touch has value. Deny rules apply even in that mode.

How do I keep an eye on a background session?

With claude agents you list it, with claude attach you reopen it in the terminal and with claude logs you read its log: these are the commands that the help of version 2.1.325 associates with the identifier printed by --bg.

What you can do now

You can write a stop criterion that a command verifies and test it on a test repository in the three cases that matter: clean, broken test, changes outside the perimeter. You can choose a permission mode for what you can afford to lose, you can check with a script that your version of Claude Code knows the options the launch needs, and you know where the proof is missing: the real session, which is left to you with a key and a low cap.

In this series. Previous article: Changing Model Generation Without Surprises: the Compatibility Matrix. Next article: Fable or Opus: When Moving Up a Model Pays Off.

Sources

The claude --help command was run on 2026-11-14 (Claude Code 2.1.325) and preflight.py and arresto.sh were run with Python 3 and git on a test repository. The night launch was not run (no key). Mode names, commands and options were compared with the official pages on 2026-11-14. The code listings and the program outputs are reproduced exactly as in the Italian original, so identifiers, messages and comments inside them are in Italian.

Commenti

Caricamento commenti...

Sign in to comment

New articles and tools on Telegram too

The Telegram channel flags the site's new articles and tools.

Did you like this article?

Explore other content on the blog or discover my projects