codex - 💡(How to fix) Fix Remote connections can mix project/thread host state when SSH hosts share HOME [1 comments, 2 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#20399Fetched 2026-05-01 05:43:26
View on GitHub
Comments
1
Participants
2
Timeline
5
Reactions
0
Author
Timeline (top)
labeled ×4commented ×1

Codex Desktop remote connections can mix up remote projects and threads when multiple SSH hosts share the same remote $HOME directory.

In this setup, a project can appear under one remote machine in the sidebar, while opening a thread from that project resumes against another machine. The visible symptom is a remote-host mismatch plus Current working directory missing, even though SSH connectivity and the remote Codex app servers are otherwise healthy.

Root Cause

  • The sidebar showed the project under the expected remote host.
  • Opening an existing thread showed a different remote host in the bottom-right connection badge.
  • The composer showed Current working directory missing / This chat's working directory no longer exists.
  • Follow-up turns could not proceed normally because the thread was effectively attached to the wrong host/context.

Fix Action

Fix / Workaround

Local Hotfix

As a workaround, I set a host-specific CODEX_HOME in the remote shell startup before codex app-server launches:

Code Example

$HOME/.codex/history.jsonl
$HOME/.codex/session_index.jsonl
$HOME/.codex/state_5.sqlite
$HOME/.codex/archived_sessions/...

---

ssh <host-a> 'hostname -f; realpath ~/.codex; df -hT "$HOME"; ls -lh ~/.codex/session_index.jsonl ~/.codex/state_5.sqlite'
ssh <host-b> 'hostname -f; realpath ~/.codex; df -hT "$HOME"; ls -lh ~/.codex/session_index.jsonl ~/.codex/state_5.sqlite'

---

CODEX_HOME="$HOME/.codex/remotes/<stable-remote-connection-id>"

---

history.jsonl
session_index.jsonl
state_5.sqlite
archived_sessions/
logs/
shell_snapshots/

---

# In remote shell startup, e.g. ~/.bashrc
_codex_remote_host="$(hostname -s 2>/dev/null || hostname)"
case "$_codex_remote_host" in
  <host-a>|<host-b>|<host-c>)
    export CODEX_HOME="$HOME/.codex-hosts/$_codex_remote_host"
    mkdir -p "$CODEX_HOME" 2>/dev/null || true
    ;;
esac
unset _codex_remote_host

---

mkdir -p ~/.codex-hosts/<host>/rules ~/.codex-hosts/<host>/archived_sessions ~/.codex-hosts/<host>/log
cp -p ~/.codex/auth.json ~/.codex/config.toml ~/.codex/AGENTS.md ~/.codex-hosts/<host>/ 2>/dev/null || true
cp -a ~/.codex/rules/. ~/.codex-hosts/<host>/rules/ 2>/dev/null || true
touch ~/.codex-hosts/<host>/history.jsonl ~/.codex-hosts/<host>/session_index.jsonl

---

tr '\0' '\n' < /proc/<codex-app-server-pid>/environ | grep '^CODEX_HOME='

---

host A: CODEX_HOME=$HOME/.codex-hosts/<host-a>
host B: CODEX_HOME=$HOME/.codex-hosts/<host-b>
RAW_BUFFERClick to expand / collapse

Summary

Codex Desktop remote connections can mix up remote projects and threads when multiple SSH hosts share the same remote $HOME directory.

In this setup, a project can appear under one remote machine in the sidebar, while opening a thread from that project resumes against another machine. The visible symptom is a remote-host mismatch plus Current working directory missing, even though SSH connectivity and the remote Codex app servers are otherwise healthy.

What Happened

I configured multiple SSH remotes in Codex Desktop and opened the same remote project path on different hosts in an HPC/research-style environment.

The app entered a mixed state:

  • The sidebar showed the project under the expected remote host.
  • Opening an existing thread showed a different remote host in the bottom-right connection badge.
  • The composer showed Current working directory missing / This chat's working directory no longer exists.
  • Follow-up turns could not proceed normally because the thread was effectively attached to the wrong host/context.

This was not caused by SSH auth failure or a stale remote Codex binary:

  • Both SSH hosts were reachable.
  • Both codex app-server processes could run.
  • Updating the remote Codex CLI and restarting stale app-server processes fixed version/model-list issues, but not this project/thread host mismatch.

Who This Affects

This likely affects users on systems where multiple SSH hosts share the same network home directory, including:

  • university/research clusters;
  • GPU/login/compute node fleets;
  • enterprise Linux environments;
  • servers using NFS, AFS, Lustre, or similar shared home mounts.

This is a common pattern in exactly the kinds of remote-first environments where Codex Desktop remote connections are most useful.

Why It Happens

The remote Codex app server appears to use $HOME/.codex as its state root unless CODEX_HOME is explicitly set.

On shared-home systems, different SSH hosts can resolve to distinct machines but still share the same $HOME, so all of these files are shared across hosts:

$HOME/.codex/history.jsonl
$HOME/.codex/session_index.jsonl
$HOME/.codex/state_5.sqlite
$HOME/.codex/archived_sessions/...

That means sessions created or indexed from host A are visible to host B. The desktop UI can then group a project by one host/path while the opened conversation still carries or resolves to another host binding.

A diagnostic that exposed the issue was checking both hosts:

ssh <host-a> 'hostname -f; realpath ~/.codex; df -hT "$HOME"; ls -lh ~/.codex/session_index.jsonl ~/.codex/state_5.sqlite'
ssh <host-b> 'hostname -f; realpath ~/.codex; df -hT "$HOME"; ls -lh ~/.codex/session_index.jsonl ~/.codex/state_5.sqlite'

In the failing case, both hosts reported the same shared home filesystem and the same .codex state files.

Potential Product Remedy

Codex Desktop should not assume that ~/.codex is machine-local when launching or connecting to a remote app server.

A robust fix would be to namespace mutable remote state by remote connection identity, for example by launching the remote app server with:

CODEX_HOME="$HOME/.codex/remotes/<stable-remote-connection-id>"

where <stable-remote-connection-id> is derived from the configured SSH connection identity, such as the connection UUID, user, host alias/resolved hostname, and port.

Important details:

  • The namespace should be per remote connection, not just per project path or folder label.
  • Project/thread keys should include both hostId and remotePath.
  • Thread resume should validate that the thread's stored host matches the currently selected/attached host.
  • If a mismatch is detected, the UI should show a clear message like This thread belongs to <host> instead of opening it under a different project row.
  • Auth/config/plugin state may need a migration/copy/symlink strategy so users do not need to re-authenticate separately for every namespaced remote state directory.

A smaller partial fix would be to keep global config/auth shared but split mutable runtime/session stores by remote host:

history.jsonl
session_index.jsonl
state_5.sqlite
archived_sessions/
logs/
shell_snapshots/

Local Hotfix

As a workaround, I set a host-specific CODEX_HOME in the remote shell startup before codex app-server launches:

# In remote shell startup, e.g. ~/.bashrc
_codex_remote_host="$(hostname -s 2>/dev/null || hostname)"
case "$_codex_remote_host" in
  <host-a>|<host-b>|<host-c>)
    export CODEX_HOME="$HOME/.codex-hosts/$_codex_remote_host"
    mkdir -p "$CODEX_HOME" 2>/dev/null || true
    ;;
esac
unset _codex_remote_host

Then I seeded each host-specific directory with the shared config/auth files needed by the app server:

mkdir -p ~/.codex-hosts/<host>/rules ~/.codex-hosts/<host>/archived_sessions ~/.codex-hosts/<host>/log
cp -p ~/.codex/auth.json ~/.codex/config.toml ~/.codex/AGENTS.md ~/.codex-hosts/<host>/ 2>/dev/null || true
cp -a ~/.codex/rules/. ~/.codex-hosts/<host>/rules/ 2>/dev/null || true
touch ~/.codex-hosts/<host>/history.jsonl ~/.codex-hosts/<host>/session_index.jsonl

After restarting the remote app servers, I verified each process had a distinct CODEX_HOME:

tr '\0' '\n' < /proc/<codex-app-server-pid>/environ | grep '^CODEX_HOME='

Expected:

host A: CODEX_HOME=$HOME/.codex-hosts/<host-a>
host B: CODEX_HOME=$HOME/.codex-hosts/<host-b>

New remote chats then used the correct machine-local state. Existing broken threads may still carry stale host metadata, so the reliable validation path is to create a fresh thread after splitting the state directories.

Expected Behavior

Remote project and thread state should be scoped to the selected remote host/connection. A thread created on host A should not appear resumable as if it belonged to host B solely because both machines share $HOME/.codex.

Actual Behavior

With shared $HOME, host A and host B share Codex remote state. This can cause the sidebar project host, opened thread host, and working directory to disagree.

extent analysis

TL;DR

Set a host-specific CODEX_HOME environment variable to namespace mutable remote state by remote connection identity.

Guidance

  • Identify the shared home directory issue by running the diagnostic command provided in the issue body to verify that both hosts report the same shared home filesystem and .codex state files.
  • Set a host-specific CODEX_HOME in the remote shell startup, as shown in the Local Hotfix section, to split mutable runtime/session stores by remote host.
  • Seed each host-specific directory with the shared config/auth files needed by the app server.
  • Verify that each remote app server process has a distinct CODEX_HOME after restarting the servers.

Example

The Local Hotfix section provides an example of how to set a host-specific CODEX_HOME in the remote shell startup:

# In remote shell startup, e.g. ~/.bashrc
_codex_remote_host="$(hostname -s 2>/dev/null || hostname)"
case "$_codex_remote_host" in
  <host-a>|<host-b>|<host-c>)
    export CODEX_HOME="$HOME/.codex-hosts/$_codex_remote_host"
    mkdir -p "$CODEX_HOME" 2>/dev/null || true
    ;;
esac
unset _codex_remote_host

Notes

This fix assumes that the issue is caused by the shared home directory and that setting a host-specific CODEX_HOME will resolve the issue. However, this may not be the case in all scenarios, and additional debugging may be required.

Recommendation

Apply the workaround by setting a host-specific CODEX_HOME environment variable, as this is a relatively simple and non-invasive fix that can help to resolve the issue. This approach allows for a clear separation of remote state by host, which should prevent the project and thread host mismatch.

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 Remote connections can mix project/thread host state when SSH hosts share HOME [1 comments, 2 participants]