codex - ✅(Solved) Fix codex fork --last ignores default cwd filtering and can fork a session from another project [1 pull requests, 1 participants]

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…
GitHub stats
openai/codex#20945Fetched 2026-05-05 05:55:51
View on GitHub
Comments
0
Participants
1
Timeline
7
Reactions
0
Participants
Assignees
Timeline (top)
labeled ×4assigned ×1cross-referenced ×1unlabeled ×1

Root Cause

Current behavior appears to allow the latest session from project A to be selected instead, because the local fork --last lookup does not pass a cwd filter.

Fix Action

Fixed

PR fix notes

PR #21089: [codex] Fix fork --last cwd filtering

Description (problem / solution / changelog)

Fixes #20945.

This keeps codex fork --last aligned with the neighboring latest-session lookup flows. The local fork path now uses the same cwd-scope helper as resume --last, which is also a small code cleanup around how this selection logic is shared.

Credit to @chanwooyang1 for the report and for pointing out the narrow fix direction.

What changed:

  • Route fork --last through the shared latest-session cwd filter.
  • Preserve --all as the explicit opt-in for global latest-session selection.
  • Keep remote cwd override behavior unchanged.
  • Add focused coverage for local default, --all, and remote override filter semantics.

Validation:

  • Ran just fmt.
  • Ran git diff --check.
  • Reviewed the fork --last, resume --last, and fork picker selection paths against the issue report.

Changed files

  • codex-rs/tui/src/lib.rs (modified, +181/-10)

Code Example

codex fork --last
RAW_BUFFERClick to expand / collapse

What version of Codex CLI is running?

codex-cli 0.128.0

What subscription do you have?

ChatGPT Pro

Which model were you using?

gpt-5.5

What platform is your computer?

Darwin 25.3.0 arm64 arm

What terminal emulator and version are you using (if applicable)?

cmux 0.63.2 (79) [179b16ce6]

What issue are you seeing?

codex fork --last appears to ignore the default cwd filtering used by nearby session-selection flows.

For local sessions, codex resume --last selects the latest session for the current cwd unless --all is passed. The fork picker also applies cwd filtering by default unless --all is passed.

However, the local codex fork --last path appears to pass no cwd filter when looking up the latest session. As a result, running codex fork --last from one project can select and fork a newer session from a different project.

This makes codex fork --last behave like codex fork --last --all with respect to cwd filtering.

What steps can reproduce the bug?

A minimal scenario is:

  1. Create or have a recent Codex session in project A.
  2. Create or have an older Codex session in project B.
  3. cd into project B.
  4. Run:
codex fork --last

Expected target would be the latest session for project B.

Current behavior appears to allow the latest session from project A to be selected instead, because the local fork --last lookup does not pass a cwd filter.

From code inspection:

  • resume --last uses latest_session_cwd_filter(...).
  • The fork picker also applies cwd filtering by default unless --all is passed.
  • The local fork --last branch passes None as the cwd filter.

What is the expected behavior?

For local sessions, codex fork --last should mirror codex resume --last and the fork picker default behavior:

  • codex fork --last should select the latest session for the current cwd.
  • codex fork --last --all should select the latest session across all cwd values.

This would keep --all as the explicit opt-in for global session selection.

Additional information

I searched for existing issues/PRs around fork --last, cwd filtering, latest session selection, and resume/fork/history cwd behavior, and I did not find an exact duplicate.

Related but different items:

  • #19931 moved local resume/fork picker cwd filtering into thread/list, but codex fork --last appears to remain unaffected.
  • #17302 is about resume --last cwd filtering/path normalization and supports the expectation that --last should match picker filtering.
  • #15494 involved provider filtering rather than cwd filtering.
  • #14257 is about restored cwd casing under WSL, not source-session lookup.

A narrow fix direction would be to make the local fork --last path use the same latest_session_cwd_filter(...) helper as resume --last, while preserving --all and remote cwd override behavior.

extent analysis

TL;DR

The issue can be fixed by modifying the codex fork --last command to use the latest_session_cwd_filter(...) helper, similar to codex resume --last, to apply the default cwd filtering.

Guidance

  • Review the code for codex fork --last and identify where the cwd filter is being passed as None, causing it to ignore the default filtering.
  • Update the codex fork --last command to use the latest_session_cwd_filter(...) helper, ensuring it applies the default cwd filtering unless --all is specified.
  • Verify the fix by running the minimal scenario provided in the issue description and checking that the expected behavior is achieved.
  • Consider testing the fix with different project setups and session configurations to ensure it works as expected in various scenarios.

Example

No code snippet is provided as the issue does not contain sufficient code details, but the fix direction is to make the local fork --last path use the same latest_session_cwd_filter(...) helper as resume --last.

Notes

The fix should preserve the --all and remote cwd override behavior, ensuring that the default filtering is only applied when --all is not specified.

Recommendation

Apply the workaround by modifying the codex fork --last command to use the latest_session_cwd_filter(...) helper, as this will fix the issue and align the behavior with codex resume --last and the fork picker default behavior.

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 - ✅(Solved) Fix codex fork --last ignores default cwd filtering and can fork a session from another project [1 pull requests, 1 participants]