8000 Terminal working directories are lost after session restoration (CMD and Git Bash) · Issue #427 · amirlehmam/wmux · GitHub
[go: up one dir, main page]

Skip to content

Terminal working directories are lost after session restoration (CMD and Git Bash) #427

Closed

Description

@ZvikaZ

What happens

wmux successfully restores workspace layouts and Claude Code conversations after restarting, but terminals reopen in the user's home directory instead of their original project directories.

This occurs with both CMD and Git Bash.

Expected: Each terminal should reopen in its previous working directory, including when resuming a Claude Code conversation.

Actual: Terminals start in C:\Users\<USERNAME>.

Interestingly, wmux correctly displays the current working directory in its sidebar before closing. This suggests directory detection works, but the directory information may not be persisted or restored correctly.

Impact: Restored Claude Code agents may operate in the wrong project directory, potentially reading or modifying unintended files.

Update: Workaround found

Opening a project using Ctrl+O (Open folder as workspace) resolves the problem: wmux correctly restores the project's working directory after restarting.

The issue appears to affect terminals where the working directory was changed using cd.

Observed behavior:

  • cd into a project directory → wmux displays the correct directory in the sidebar, but does not restore it after restarting.
  • Ctrl+O to open a project directory → wmux restores the directory correctly.

Possible cause (AI-assisted hypothesis): wmux persists the initial project directory but does not update the saved working directory when it changes through shell integration.

Suggested fix: Persist the latest reported working directory for each terminal, not just the initial directory.

This update was written by ChatGPT (OpenAI GPT-6), based on the user's testing.

Steps to reproduce

  1. Open wmux on Windows 11.
  2. Open a terminal using CMD or Git Bash.
  3. Navigate to a project directory using cd (for CMD, use cd /d when changing drives).
  4. Verify that wmux displays the correct directory in its sidebar.
  5. Save the session.
  6. Close wmux normally.
  7. Reopen wmux and restore the session.
  8. Check the terminal's working directory.

Result: The terminal opens in the user's home directory instead of the original project directory.

Reproduced with both CMD and Git Bash.

wmux version

2.54.0

Windows version

Windows 11 25H2 26200.9711

Anything else

Environment

  • OS: Windows 11
  • Shells tested: CMD and Git Bash
  • Other shells in use: WSL
  • Agent: Claude Code
  • Configuration: Multiple workspaces and terminal panes
  • wmux: Latest available version

Diagnostic findings

I inspected:

  • %APPDATA%\wmux\sessions\session.json
  • %APPDATA%\wmux\pty-ledger.json

1. No terminal surfaces contain working-directory information.

Example from the actual session.json (identifiers anonymized):

{
  "id": "<SURFACE_ID>",
  "type": "terminal",
  "resolvedShell": "C:\\Program Files\\Git\\bin\\bash.exe",
  "claudeSessionId": "<CLAUDE_SESSION_ID>"
}

CMD example:

{
  "id": "<SURFACE_ID>",
  "type": "terminal",
  "shell": "cmd.exe",
  "resolvedShell": "C:\\Windows\\System32\\cmd.exe",
  "claudeSessionId": "<CLAUDE_SESSION_ID>"
}

Neither contains cwd or currentCwd.

2. Workspace-level directories are inconsistent.

The saved session contains three workspaces.

Workspace 1 contains:

{
  "title": "Workspace 1",
  "shell": "",
  "cwd": "C:\\Users\\<USERNAME>"
}

Workspaces 2 and 3 contain no workspace-level cwd property.

None of the terminal surfaces has a working-directory property.

3. The PTY ledger contains no working directories.

pty-ledger.json tracks process IDs, executable names, and start times, but no working directories.

This may be intentional.

Possible root cause (AI-assisted hypothesis)

The current working directory may be tracked correctly for the sidebar but not propagated into the state serialized by session persistence.

Possible sequence:

  1. Shell integration reports the current working directory.
  2. wmux updates the sidebar.
  3. Session serialization omits the terminal's latest working directory.
  4. Session restoration starts the terminal in the default directory.

This is a hypothesis, not a verified source-code diagnosis.

Suggested fix

Investigate the path from shell working-directory reporting to session serialization and terminal restoration.

Persist the latest working directory per terminal surface, rather than relying exclusively on workspace-level state.

Conceptually:

const savedSurface = {
  ...surface,
  cwd: liveTerminalCwd ?? surface.currentCwd ?? surface.cwd,
};

Then restore that directory when spawning the terminal:

spawnTerminal({
  shell: savedSurface.shell,
  cwd: savedSurface.cwd ?? workspace.cwd ?? defaultCwd,
});

The directory should be restored before resuming Claude Code.

Please also consider:

  • Multiple terminals in the same workspace with different directories.
  • CMD, Git Bash, PowerShell, and WSL.
  • Windows/Linux path differences.
  • Backward compatibility with older saved sessions.
  • Missing or deleted directories.

Questions

  1. Is per-terminal working-directory restoration currently supported?
  2. Should cwd or currentCwd be serialized for each terminal?
  3. Is there an existing workaround?

AI disclosure

This bug report was written by ChatGPT (OpenAI GPT-6) based on the user's observations and diagnostic files.

ChatGPT analyzed the supplied session.json and pty-ledger.json and suggested the possible root cause and implementation approach.

The bug was experienced and reproduced by a human user. The technical diagnosis and proposed fix are AI-generated hypotheses and have not been independently verified against the complete wmux source implementation.

Activity

  1. strayge commented on Nov 2, 2026

    @strayge
    Contributor

    Is per-terminal working-directory restoration currently supported?

    Yes, tested with PowerShell and WSL panes.

    WSL required shell hook from docs\wsl-explorer.md

    For cmd.exe it looks like bug. Fix in #429

    Git Bash also requires manually added hook, that reports changed cwd:

    ~/.bashrc

    _wmux_report_cwd() {
        printf '\033]9;9;%s\033\\' "$(pwd -W)"
    }
    PROMPT_COMMAND+=('_wmux_report_cwd')
  2. amirlehmam commented on Nov 3, 2026

    @amirlehmam
    Owner

    Fixed in 2.55.0, for both shells:

    • CMD: wmux now honours the OSC 9;9 cwd reports CMD's integration already sent (Fix cwd tracking in CMD panes #429, thanks @strayge).
    • Git Bash: wmux now loads its bash integration in Git Bash panes by itself (--init-file, and your ~/.bashrc or login files still run). It reports the directory as a Windows path after every cd, so the pane reopens there and claude --resume finds its project. Previously the reports went to a temp file nothing read, and the /c/... spelling was taken for a WSL path. You can drop the manual PROMPT_COMMAND hook once you update.

    Please reopen if a restored pane still lands in your home directory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0