Skip to content

[Bug] Session Resume Fails With Misleading Error When Working Directory Differs From Launch Directory #35226

Description

@jordan-of

Bug Description
Bug Report: Session Resume Fails When Working Directory Differs From Launch Directory

Issue Summary

claude --resume cannot resume a session from a different working directory than where it was originally launched. The session ID is reported as "invalid or expired" — with no indication that the actual
problem is a directory mismatch. This forces users to choose between losing their session or living with a misconfigured workspace for the session's lifetime.

Steps to Reproduce

  1. Launch Claude Code from a parent directory:
    cd ~/code
    claude
  2. Work extensively on files inside a subdirectory repo (~/code/monofolk) using absolute paths — everything functions correctly.
  3. Notice the statusline shows code instead of monofolk and no git branch, because workspace.current_dir is set to the launch directory.
  4. Exit the session.
  5. Attempt to resume from the correct directory:
    cd ~/code/monofolk
    claude --resume
  6. Claude Code reports the session ID is "invalid or expired".
  7. If you ask Claude Code about the error, it tells you the session ID is invalid or expired — blaming the user rather than identifying the directory mismatch as the cause.

Expected Behavior

claude --resume should resume any session regardless of the current working directory. Ideally, workspace.current_dir should update to the new launch directory on resume, so the statusline
and any directory-dependent behavior reflects where the user actually is.

At minimum, if directory mismatch is the reason for failure, the error message should say so: "Session was created in ~/code. Resume from that directory, or use --cwd to override."

Actual Behavior

  1. The session ID is valid — it exists in ~/.claude/history.jsonl and the transcript file is intact.
  2. Resume fails with a misleading "invalid or expired" error because the session is scoped to a different directory.
  3. Claude Code itself (when asked to diagnose) parrots the error back — "the session ID is invalid or expired" — providing no actionable guidance.

Root Cause Analysis

Based on how Claude Code stores sessions:

  1. Session storage: Sessions are stored in ~/.claude/projects/ under paths encoded from the original working directory, and indexed in ~/.claude/history.jsonl with the absolute project path.
  2. Directory coupling: --continue explicitly filters to "most recent session in the current directory." --resume also scopes session lookup by directory. A session created in ~/code is invisible from
    ~/code/monofolk — the lookup fails and surfaces as "invalid or expired."
  3. Misleading error: The "invalid or expired" message is a catch-all for "session not found in the current directory's scope." It doesn't distinguish between a genuinely missing session and a directory
    mismatch. This is the worst part — the session exists, the ID is correct, and the user is told they're wrong.
  4. Immutable workspace.current_dir: The workspace.current_dir field is set once at session creation and never updated. This value is passed to the statusline command, tools, and likely influences file
    resolution. There is no /cd command or mechanism to update it mid-session or on resume.
  5. Cascading impact: Because workspace.current_dir can't change, even if resume worked across directories, the session would still reference the old directory — the statusline would show the wrong info,
    and relative path resolution could break.

Impact

  • Lost work: Users who accidentally launch from the wrong directory face a choice: continue with a broken statusline/workspace, or abandon the session (potentially hours of context).
  • No recovery path: There's no claude --resume --cwd or similar mechanism to relocate a session. Going back to the original directory works, but then you're stuck with the wrong workspace
    config.
  • Misleading diagnostics: The error message actively misleads. A user with a valid session ID is told it's "invalid or expired." When they ask Claude Code for help, it reinforces the false diagnosis.
    This erodes trust.
  • Silent failure at launch: Nothing warns the user at session start that they're in a non-ideal directory. By the time they notice (via statusline), they may have hours of context built up.

Suggested Fixes

P0 — Fix the error message:

  • When a session ID exists but belongs to a different directory, say so: "Session was created in ~/code — run claude --resume from that directory."
  • This is a one-line fix in the session lookup error handling and eliminates the most frustrating part of the bug.

P1 — Allow cross-directory resume:

  • claude --resume should work from any directory. The session ID is globally unique — directory scoping should be a filter for the picker, not a hard gate on resume-by-ID.
  • The interactive picker could …
    Note: Content was truncated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    duplicateThis issue or pull request already exists

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions