On the second afternoon of December, I was watching a scheduled task run when it stopped on its very first step — fetching a repository. The reply was a sentence I hadn't seen before:
Permission for this action was denied by the Claude Code auto mode classifier.
Reason: [Destructive or Unwanted Actions].
The task itself is ordinary indie developer work: pull my own website's repository and update it. I had only run the line my runbook told me to run, so for a moment I just stared at it.
Looking closer, though, what got stopped was the way I had written the step. This is a record of how I narrowed it down and how I rewrote the instructions.
First, figure out which message you actually got
There are at least three messages that show up in similar moments, and each has a different cause and a different fix. I nearly mistook mine for a broken permission setting.
| Message | What it means | First move |
|---|---|---|
| denied by the ... auto mode classifier (with a Reason) | The classifier read the action and judged it risky | Rewrite the command |
| auto mode "cannot determine the safety" of an action | The request to the classifier itself failed | Usually transient; retry later |
| A permission prompt or a wait for approval | Not in auto mode, or auto mode has paused | Check the mode and the block count |
The official Permission modes page describes the second one as a separate message meaning a classifier request failed. Mine was the first kind, Reason included — the classifier had read the command and decided to stop it.
Narrow it down by asking which word in the call triggered it
Here is roughly what I had sent. I had bundled a line that reads a note with the lines that prepare the repository, all in a single call.
# The step that was blocked (trimmed to the essentials)
sed -n '1,60p' "$WS/_documents/notes.md"
if [ -d "$WORK/.git" ]; then
cd "$WORK" && git remote set-url origin "$URL" \
&& git reset --hard HEAD -q && git clean -fdq \
&& git pull --rebase origin main
else
git clone --depth 1 --branch main "$URL" "$WORK"
fiThe official "blocked by default" list includes git reset --hard, git clean -fd, git checkout -- ., and git stash drop, which the classifier presumes would discard uncommitted changes. The same page says a remote repointed during the session with git remote set-url is not trusted.
Then I noticed something. $WORK didn't exist yet, so only the else branch — the clone — would ever have run. The reset sat in a branch that could not execute.
The whole call was still blocked, and the harmless sed at the top never ran either. As far as I can tell, the classifier judges the command as written, not the branch that would actually be taken. The docs even note that under server-side review, git reset --hard can be blocked on a clean working tree.
This is the order I used to narrow it down:
- Check whether the message carries a Reason (if so, it's a judgment about the content)
- Look for verbs from the default list in the call: reset, clean, stash drop, force push,
rm -rf "$VAR" - Check whether the remote is repointed mid-session
- Check whether a delete target is still a bare variable (the docs say an unassigned variable leaves the classifier unable to tell what would be deleted)
The fix is to split and to replace
My first impulse was to send the same step again. That isn't a good idea. According to the docs, after 3 blocks in a row or 20 in total, auto mode pauses. In an unattended run, the blocked step simply doesn't happen while the rest of the work carries on without it.
What actually worked for me was this: confirm with ls alone that the folder didn't exist, then clone into a fresh location in a separate call.
# Call 1: look only
ls -ld /tmp/repos /tmp/repos/* 2>&1 | head# Call 2: add only (no deleting, no repointing)
mkdir -p /tmp/repos
git clone --depth 1 --branch main "$URL" /tmp/repos/site-repoThat went straight through. The thinking behind it comes down to three things:
- Split: reading, checking, and changing go into separate calls, so one word no longer takes unrelated lines down with it
- Replace: instead of "delete the old copy and tidy it up," put a new copy somewhere fresh — clone into an empty folder rather than reset and clean
- Name it: if you truly must delete, write the literal path instead of a variable; the docs say this clears that particular block
Never put a cleanup step and a step forward on the same call. That was the line that helped most this time.
Check the instructions before they get blocked
Once a scheduled task's runbook is written, I sometimes don't reread it for months. So I put together a small script that scans instruction files and shell scripts for steps the classifier tends to block by default.
#!/usr/bin/env python3
"""定期タスクの指示文・シェルスクリプトから、auto モードの分類器が既定で止めやすい一手を拾う。"""
import re
import sys
from pathlib import Path
# (名前, 正規表現, 置き換えの方向)
RULES = [
("git reset --hard", r"git\s+reset\s+--hard", "新しいフォルダへ clone し直す"),
("git clean -f", r"git\s+clean\s+-[a-z]*f", "新しいフォルダへ clone し直す"),
("git checkout -- .", r"git\s+checkout\s+--\s+\.", "変更を残したまま別ブランチで作業する"),
("git restore .", r"git\s+restore\s+\.", "変更を残したまま別ブランチで作業する"),
("git stash drop/clear", r"git\s+stash\s+(drop|clear)", "stash は消さずに残す"),
("rm -rf $変数", r"rm\s+-[a-z]*r[a-z]*f?[a-z]*\s+\"?\$\{?[A-Za-z_]", "消す先をそのまま書くか、退避フォルダへ mv する"),
("強制 push", r"git\s+push\b[^\n]*(\s--force\b|\s-f\b)", "通常の push と pull --rebase に戻す"),
("curl | sh", r"curl\b[^\n|]*\|\s*(ba)?sh\b", "落としてから中身を見て実行する"),
("remote の付け替え", r"git\s+remote\s+(set-url|add)\b", "clone の URL で最初から決める"),
]
def scan(path: Path):
hits = []
for no, line in enumerate(path.read_text(encoding="utf-8", errors="replace").splitlines(), 1):
for name, pattern, advice in RULES:
if re.search(pattern, line):
hits.append((no, name, advice, line.strip()))
return hits
def main(argv):
if len(argv) < 2:
print("usage: scan_blocked_steps.py FILE_OR_DIR ...")
return 2
files = []
for arg in argv[1:]:
p = Path(arg)
files += sorted(x for x in p.rglob("*") if x.suffix in {".md", ".sh", ".txt"}) if p.is_dir() else [p]
total = 0
for f in files:
for no, name, advice, line in scan(f):
total += 1
print(f"{f}:{no}: [{name}] -> {advice}\n {line[:90]}")
print(f"--- {len(files)} files / {total} hits")
return 1 if total else 0
if __name__ == "__main__":
sys.exit(main(sys.argv))Running it over three files — the instructions with the blocked step, a cleanup script, and the instructions after the fix — gave me this:
prompts/cleanup.sh:2: [rm -rf $変数] -> 消す先をそのまま書くか、退避フォルダへ mv する
rm -rf "$OLD"
prompts/cleanup.sh:3: [rm -rf $変数] -> 消す先をそのまま書くか、退避フォルダへ mv する
rm -rf "$HOME/work/tmp_thumbs_2026-12-01"
prompts/repo_refresh.md:3: [git reset --hard] -> 新しいフォルダへ clone し直す
prompts/repo_refresh.md:3: [git clean -f] -> 新しいフォルダへ clone し直す
prompts/repo_refresh.md:3: [remote の付け替え] -> clone の URL で最初から決める
--- 3 files / 5 hits
The fixed instructions produced no hits. The script also flags variables whose value is easy to read, like "$HOME/...", and the hints are in Japanese because that's how my own runbooks are written — swap in your own wording freely.
The over-matching is deliberate. I'd rather it catch too much than miss something, and leave the final "is the target obvious here?" call to a human. I treat it as a first draft for review, not a verdict.
It exits with 1 when there are hits, so running it only on days you edit a runbook is plenty.
If it still gets blocked
If the rewrite still gets stopped, the quickest route is to see what your environment blocks by default. In Claude Code, claude auto-mode defaults prints the built-in rules as JSON.
In an interactive session, the docs say a blocked action appears in /permissions under the Recently blocked tab, where you can approve it so Claude may retry. If trusted internal repos or buckets get blocked routinely, an administrator can add them through autoMode.environment.
An unattended scheduled task, though, has nobody to approve anything. What I prefer is writing into the instructions: if a step is blocked, skip it, log it, and finish. I keep one rule at the very top of those instructions — never look for a roundabout way past the reason it was blocked.
For another day when the clone location itself was the problem, Why I Stopped Borrowing a Stale Repo and Started Cloning Fresh After a Scheduled Task Couldn't Write to Shared /tmp covers a script for choosing the working directory and a check before pushing. It also measures what re-cloning every run actually costs, which may help if you're deciding whether "replace instead of clean" fits your own setup.
The one thing I'd suggest doing next is running the script above, just once, over your own scheduled-task runbooks. In my case only one line had been blocked, but rewriting it made the whole runbook far easier to follow.