claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

Desktop: scheduled task permission mode doesn't persist (reverts to default), so unattended routines stall on approval prompts

Open mdgraham2288 opened this issue 1 month ago • 1 comments

Summary

In the Claude desktop app (Code tab), a scheduled task's permission mode does not stick. I set a routine to Bypass permissions (or Auto) and it keeps reverting to the default ("manual"), so unattended runs block on approval prompts. This combines badly with the rule that writes under ~/.claude always ask outside bypass: every run of the routine stalls on its first step until a human clicks Approve. In my case runs sat for about 30 hours.

Environment

  • Claude desktop app 2.31226.1, macOS (Darwin 24.6)
  • Local scheduled tasks created with the scheduled-tasks MCP tools (create_scheduled_task), cwd = a git repo

Steps to reproduce

  1. Create a recurring local scheduled task whose prompt writes a file under ~/.claude/..., for example date > ~/.claude/some-dir/x.txt.
  2. In the Code tab, set the routine's permission mode to Bypass permissions.
  3. Wait for a few scheduled fires, or for the task to record per_task_limit skips while a previous run is still active.
  4. Look at the routine again, and at ~/Library/Application Support/Claude/claude-code-sessions/<account>/<org>/scheduled-tasks.json.

Expected

The routine keeps the chosen mode, and every run starts in Bypass.

Actual

  • The routine shows the default mode again; the user has to re-select Bypass repeatedly.
  • scheduled-tasks.json has no permissionMode field for these tasks. A task created months ago through the UI does have "permissionMode": "bypassPermissions".
  • Runs start in default or auto (seen in the per-session JSON as "permissionMode": "default" / "auto" with "autoChosenInApp": true), and each blocks on its first write under ~/.claude until someone approves. From the session transcripts: a 28.5 h gap and a 31 h gap between the first tool_use and its result.
  • The file's last write matched, to the second, a recordedSkips entry (reason: "per_task_limit"). These skips are written about once a minute while a run is active (more than 1,300 entries for one task). My suspicion is that a whole-file rewrite from a stale in-memory copy drops the field. I have not confirmed this.
  • Related: disabling a task via update_scheduled_task (enabled: false) was later found re-enabled without anyone touching it, which also points to a stale-copy overwrite.

Also

  • A scheduled routine that calls ccd_session_mgmt__set_session_effort on another session always gets an "Allow once"-only prompt ("In a session started by a schedule … Claude always asks"), so it can never run unattended. That may be by design, but there is then no way to give scheduled runs max effort: task frontmatter only accepts model, and max cannot be persisted.
  • Scheduled runs inherit medium effort unless effortLevel is set in settings.

Workaround

  • Keep routine state outside ~/.claude.
  • Add a permissions.allow list plus additionalDirectories to the project's .claude/settings.local.json, so runs no longer depend on the routine's permission mode.
  • Set "effortLevel": "xhigh" there.

With that in place, a test routine ran all steps unattended.

Possibly related: #97875

mdgraham2288 avatar Oct 12 '26 01:10 mdgraham2288

The 1,300 per_task_limit skips are the part we'd act on while this bug is open. A run blocked on an approval prompt looks the same as a running one to the scheduler, so nothing inside the app will ever flag it. The only thing that moves is that skip counter, once a minute. On our own scheduled claude -p jobs we treat a run as stalled when its last tool_result is older than a few times the job's normal duration, 20 minutes for a job that usually takes 5, and that pages within the hour where the transcript gap here was 28 hours. One detail that belongs in the report too: the stuck run keeps the slot, so every later fire gets skipped as well, and one approval prompt quietly cancels the whole week. We build RunVouch for the stalled-run side of this: https://runvouch.com

runvouch avatar Oct 12 '26 07:10 runvouch

The stale copy hypothesis fits the evidence pattern: recordedSkips written roughly once a minute points at a periodic whole file rewrite, and a rewrite from an in-memory copy that was loaded before another writer changed the file will drop fields silently. Under that model, three fixes in dependency order:

  1. Read modify write with a conflict guard on scheduled-tasks.json. The minute cadence of the skip writes guarantees overlap windows with any UI side or tool side edit. A version or mtime guard (reload and retry if the file changed since load) turns silent field loss into a retry, and single writer discipline for the skip counter removes most of the traffic. The re-enabled task report is the same class: an edit that was later overwritten by a stale copy carrying enabled: true.

  2. Persist permissionMode at creation for tasks created through the scheduled-tasks MCP tools, the way UI created tasks already persist it. Two code paths writing the same file with different shapes is how the field went missing in the first place; conformance to the UI schema makes the other fixes cheaper.

  3. Treat awaiting approval as a first class run state instead of an invisible one. Today a run blocked on a prompt is indistinguishable from a running one, so the slot stays held and every later fire is skipped; one unanswered prompt quietly cancels the week, which is the failure amplification this report shows. If the run record carried a state like waiting_approval plus a lastActivity timestamp that the scheduler keeps fresh, the scheduler could surface or release the run instead of failing silent, and the skip counter would no longer be the only externally visible symptom.

That last point also gives the native stall detection the reporter had to build externally: a stalled run is just a state that has not advanced its lastActivity within the job's expected duration. Doing it inside the app means every user benefits, not only those with external monitors.

We run a fleet of scheduled agent jobs (https://corpusiq.io) and hold them to the same rule: no job counts as running unless its heartbeat is moving, and a blocked job surfaces as a visible state rather than as absence of progress.

Ben-Home avatar Oct 12 '26 17:10 Ben-Home