codex - 💡(How to fix) Fix Codex app shows stale merged/closed PR for main branch

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Root Cause

Because --state all omits state:open from the GitHub search query, merged and closed PRs are returned for head:main. A stale reverse/sync PR whose head branch was main can therefore be selected and shown forever on new chats.

Fix Action

Fix / Workaround

Temporary local workaround that confirmed the diagnosis:

Code Example

{
  "limit": 30,
  "q": "author:@me head:main repo:OWNER/REPO type:pr",
  "type": "ISSUE_ADVANCED"
}

---

{
  "data": {
    "search": {
      "issueCount": 4,
      "nodes": [
        { "number": 310, "state": "MERGED", "url": "https://github.com/OWNER/REPO/pull/310" },
        { "number": 158, "state": "CLOSED", "url": "https://github.com/OWNER/REPO/pull/158" },
        { "number": 155, "state": "CLOSED", "url": "https://github.com/OWNER/REPO/pull/155" }
      ]
    }
  }
}

---

gh pr list \
  --repo OWNER/REPO \
  --author @me \
  --head main \
  --state all \
  --json number,url,state \
  --limit 30

---

# Put a wrapper before /opt/homebrew/bin/gh in PATH.
# For only this shape:
#   gh pr list --state all --head main --json number,url,state ...
# rewrite --state all to --state open.
RAW_BUFFERClick to expand / collapse

What version of the Codex App are you using (From "About Codex" dialog)?

26.527.31326

What subscription do you have?

Not sure from the local app UI; paid Codex app access.

What platform is your computer?

Darwin 25.5.0 arm64 arm

What issue are you seeing?

The Codex Mac app can show an old merged/closed pull request in the Environment panel when starting a new chat on the default branch.

In my case, opening a new chat in a local repo on main briefly showed "Checking PR..." and then displayed a historical PR row in the Environment panel. The PR was not open and was not associated with current local work. Renaming the historical PR on GitHub changed the label shown in Codex after restart, confirming the app was loading live GitHub PR metadata rather than stale local state.

After intercepting the app's GitHub traffic, I found that Codex/gh was searching for PRs with this query:

{
  "limit": 30,
  "q": "author:@me head:main repo:OWNER/REPO type:pr",
  "type": "ISSUE_ADVANCED"
}

The response contained only historical PRs:

{
  "data": {
    "search": {
      "issueCount": 4,
      "nodes": [
        { "number": 310, "state": "MERGED", "url": "https://github.com/OWNER/REPO/pull/310" },
        { "number": 158, "state": "CLOSED", "url": "https://github.com/OWNER/REPO/pull/158" },
        { "number": 155, "state": "CLOSED", "url": "https://github.com/OWNER/REPO/pull/155" }
      ]
    }
  }
}

Codex then fetched PR details for the first returned result and displayed it as if it were relevant to the current chat.

This appears equivalent to running:

gh pr list \
  --repo OWNER/REPO \
  --author @me \
  --head main \
  --state all \
  --json number,url,state \
  --limit 30

Because --state all omits state:open from the GitHub search query, merged and closed PRs are returned for head:main. A stale reverse/sync PR whose head branch was main can therefore be selected and shown forever on new chats.

What steps can reproduce the bug?

  1. In a GitHub repo, have no open PR for the local default branch, for example main.
  2. Have at least one historical merged or closed PR authored by the current GitHub user where the PR head branch was main.
  3. Open the Codex Mac app in that repo and start a new chat.
  4. Watch the Environment panel.

Observed behavior:

  • The app briefly shows "Checking PR..."
  • It displays a merged/closed historical PR in the Environment panel.
  • Clicking the PR opens the historical PR on GitHub.

I verified the root cause by putting a narrow wrapper earlier in PATH for gh that rewrites only this specific lookup from --state all to --state open. After relaunching Codex, the stale PR row disappeared. The same command with the wrapper disabled reproduced the bad result.

What is the expected behavior?

Codex should only show an associated PR when the PR is currently open and relevant to the active branch/worktree.

For the PR lookup, Codex should either:

  • query only open PRs, for example gh pr list --state open ..., or
  • filter the returned PRs and ignore MERGED / CLOSED results before showing the Environment PR row.

If no open PR exists for the current branch, the Environment panel should not show a historical PR.

Additional information

I searched existing issues before drafting this and did not find an obvious duplicate for "stale pull request", "Environment PR card", "gh pr list" "--state all", or "Checking PR".

The open-source TUI path appears to do the safer thing already: codex-rs/tui/src/branch_summary.rs filters GitHub PR search results to state == open. This issue seems specific to the Codex Mac app PR-discovery path.

Temporary local workaround that confirmed the diagnosis:

# Put a wrapper before /opt/homebrew/bin/gh in PATH.
# For only this shape:
#   gh pr list --state all --head main --json number,url,state ...
# rewrite --state all to --state open.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

codex - 💡(How to fix) Fix Codex app shows stale merged/closed PR for main branch