[BUG] Claude Code Routines (cloud scheduled agents) land work on a random harness-assigned session branch, overriding the agent's own `git checkout -B`, so work is silently stranded and never merged
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
Summary
I run a fleet of ~9 scheduled Claude Code Routines (cloud agents) nightly against a single
private repo. Each routine's prompt explicitly pins its work to a canonical branch
(git checkout -B claude/elf-<slug>-YYYY-MM-DD as its first git action) and then
merges that branch into main at the end of a clean run.
Intermittently, a run's work does not land on the canonical branch and is not
merged to main. Instead the commit appears only on a harness-assigned session branch
named claude/<adjective>-<noun>-<random> (e.g. claude/stoic-fermi-azzeU). The
canonical branch is never created, main is never updated, and the work is invisible to
the downstream automation that scans for canonical branch names. The agent's owngit checkout -B appears to be overridden by the harness's managed commit/push step.
It is intermittent on the _same_ routine: the routine succeeds (merges to main) on most
nights and strands on others, which suggests a race or a budget-exhaustion interaction
rather than a static misconfiguration.
Environment
- Product: Claude Code Routines (scheduled cloud agents, claude.ai/code/routines).
- Repo: single private GitHub repo, agents operate on a fresh clone of
main. - Each routine has its own prompt; all share a common include that pins the branch at
session start and merges to main at the end on a clean gate run.
- Roughly 9 routines, scheduled 03:05-03:55 daily.
What I have already tried (prompt-side mitigations that do NOT fully fix it)
git checkout -B claude/elf-<slug>-<date>as the first git action, so every commit
lands on the canonical branch by default - work still ends up on the harness branch on
stranded nights.
- An explicit
git push origin HEAD:refs/heads/<canonical>before the merge step. - An end-of-run verification gate: re-check
HEAD, force-push to the canonical ref on
mismatch, and emit a loud STRANDED marker into the report.
These reduce the frequency but do not eliminate it, because (a) on a heavy/long run the
closing git steps are the most likely to be skipped under budget pressure, and (b) even
when the agent pushes the canonical branch, the harness's own managed push/PR still
targets the random session branch. A prompt cannot reliably win against the harness's
git management - this needs a platform-side fix.
Impact
- Silent data loss from the user's perspective: a correct, gated, committed run looks like
it "didn't run." Recovering it requires manually hunting orphan claude/<adjective>-<noun>-*
branches and cherry-picking / merging by hand.
- Any automation that coordinates multiple routines (scanning for per-routine output
branches, or expecting main to advance) is unreliable.
Suggested fix (in priority order)
- Make the agent's committed branch authoritative for the harness push/PR, OR
- Make the session branch name deterministic/configurable per routine, OR
- Expose the harness-assigned session branch name to the agent at runtime (e.g. an env
var) so the agent can deterministically merge it to main itself.
Questions for the team
- Is the random
claude/<adjective>-<noun>-<random>branch created by the harness, and
does the harness push/PR step run _after_ the agent's prompt completes (i.e. can the
agent's git checkout -B ever win)?
- Is there a supported way for a Routine to control its output branch name, or to merge
directly to main from within the run?
What Should Happen?
Expected behavior
One of the following (any would resolve it):
- The agent's own git operations are authoritative: if the agent runs
git checkout -B claude/elf-fancy-… and git push origin HEAD:refs/heads/claude/elf-fancy-…,
the work lands on exactly that branch and the harness does not silently create or push to
a different branch.
- The harness honors the branch the agent committed to when it opens its PR / pushes,
rather than substituting a random claude/<adjective>-<noun>-<random> session branch.
- At minimum: the per-run session branch name is **deterministic / configurable per
routine** (e.g. derivable from the routine name) instead of a random adjective-noun, so
downstream automation can reliably locate the run's output.
Actual behavior
On stranded nights:
- The commit lands only on
claude/<adjective>-<noun>-<random>. - The canonical
claude/elf-<slug>-<date>branch is never created on origin. mainis never updated.- The morning-briefing automation (which scans canonical branch names and
main)
reports the elf as "silent," because the work is on an orphan branch it does not look at.
Error Messages/Logs
Steps to Reproduce
Concrete reproduction / evidence (from my repo)
Routine "Fancy" (design-system sweep). Its harness session prefix is consistentlyclaude/stoic-fermi-*.
- 2026-06-05 run: worked correctly. Committed
2527088and merged tomain. - 2026-06-06 run: same routine, same prompt. Committed
5504071c ("fix(design-system): token fix + formal exemptions for hardcoded 48/32px
layout dims"). This commit exists only on claude/stoic-fermi-azzeU. It is not
an ancestor of origin/main (verified with git merge-base --is-ancestor -> not
merged), and the canonical branch claude/elf-fancy-design-system-2026-06-06 was
never created (origin has …-06-05 and …-06-07 but no …-06-06).
The harness session prefixes are stable per routine across runs, with only the random
suffix changing - strong evidence the harness assigns a fixed-per-routine session branch
that the agent cannot override. Counts of harness-style branches currently on origin:
10 claude/confident-bell-*
8 claude/intelligent-dirac-* (routine: Booky)
4 claude/stoic-fermi-* (routine: Fancy)
3 claude/charming-volta-* (routine: Frenchy)
2 claude/eager-ramanujan-*
2 claude/great-goodall-* (routine: Mutty, retired)
2 claude/elegant-cray-*
1 claude/busy-hopper-* (routine: Sneaky)
1 claude/ecstatic-maxwell-*
1 claude/kind-mendel-*
These coexist with the canonical claude/elf-<slug>-<date> branches the agents _do_
manage to create on successful nights, so the two branch families are clearly distinct:
the elf-* ones are agent-authored, the adjective-noun ones are harness-assigned.
Specific stranded branches confirmed present on origin (work never reached main):claude/stoic-fermi-azzeU (Fancy, 2026-06-06), claude/intelligent-dirac-WYdyg
(Booky, 2026-05-21), claude/stoic-fermi-mDgry (Fancy, 2026-05-24),claude/busy-hopper-qhm7or (Sneaky, 2026-06-19), claude/charming-volta-nxzlv5
(Frenchy, 2026-06-18).
Claude Model
Not sure / Multiple models
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
Unknown (routines run recently on claude code). Also don't know what OS anthropic routines run on, so picked "Other" from the dropdown
Platform
Anthropic API
Operating System
Other
Terminal/Shell
Other
Additional Information
_No response_
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗