Cloud tasks: derive default git ref from environment/repo
Resolved 💬 4 comments Opened Jan 13, 2026 by liqiongyu Closed Feb 23, 2026
Context
codex cloud exec/ cloud task creation requires agit_refso the backend knows what to check out.- Today, when
--branchis not provided, the CLI resolvesgit_reffrom local git state (current branch -> repo default branch from git metadata -> hard-coded fallback"main").
Problem
- If the CLI can't resolve local git metadata (detached HEAD, missing remote HEAD, not in a checkout, etc.), it falls back to
"main". - This breaks for repos whose default branch is
"master"(see #9111). PR #9149 is a minimal-risk fix (retrymasterwhen fallbackmainis rejected), but the underlying UX remains: in “no local git metadata” scenarios, the CLI is guessing.
Proposal
Make the backend authoritative for the default branch (it already knows which repo a cloud environment is tied to):
Option A (preferred): allow omitting git_ref (or sending null/empty) when --branch isn't provided; backend defaults to the repo's configured default branch.
Option B: add an API endpoint / environment metadata field that returns the repo's default branch, so the CLI can pick it without guessing.
Why not call the GitHub API from the CLI?
- It would require additional GitHub auth/permissions and doesn't generalize to non-GitHub providers.
- In cases where the CLI isn't run inside a repo checkout, it may not even know the owner/repo to query.
Acceptance criteria
- Creating a cloud task without
--branchsucceeds for repos with default branches namedmaster,main, or anything else, even when local git metadata is unavailable. --branchcontinues to override.
Related
- Bug report: #9111
- Minimal-risk fix: #9149
This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗