Skip to content

Sessions filed under the previous project after switching projects (wrong project mapping) #1183

Todo

Description

@imharikumaran

Summary

After switching the active project, new (and reopened) sessions are written to the previous project's catalog folder, so the chat shows up under the wrong project — while the session itself runs correctly in the new directory. The transcript's first-line header records the correct cwd, but the file's path is under the other project's slug.

Because the session catalog is project-scoped (~/.commandcode/projects/<cwd-slug>/<session-id>.jsonl), a misfiled session is invisible to /resume and -c inside the project it actually belongs to, and appears in a project it never touched.

Expected Behavior

A session started or resumed in project B is stored under ~/.commandcode/projects/<slug-of-B>/, and the project switcher / sidebar / /resume list it under project B. The transcript path and the header cwd agree.

Actual Behavior

The transcript path is chosen from the previously active project (A) while the header records B's cwd:

~/.commandcode/projects/users-...-project-a/<session-id>.jsonl
  line 1: {"type":"session","version":3,"id":"<id>","timestamp":"...","cwd":"~/project-b"}

Everything else about the session works — tools, git, edits all act on project B — so it looks fine until you look under the project in the sidebar or try /resume there.

Steps to reproduce

  1. Open a session in project A (e.g. cmd in ~/project-a), then switch the active project to project B in the app.
  2. Start a new chat (or reopen one) without restarting the app.
  3. Run /session-file (or inspect ~/.commandcode/projects/) — the transcript is filed under A's slug, but its header cwd is B.
  4. Open project B and run /resume — that session is not listed; open A and it is.

Not 100% reproducible, but it has happened repeatedly across unrelated project pairs over ~5 weeks (Oct 22, Oct 25, Nov 2, Nov 23, Nov 27).

Evidence from one machine

I scanned every stored session (1,877) and compared each header cwd, slugified, against the folder it lives in. 9 were misfiled:

3  cwd=~/project-b   filed under  users-...-project-a
2  cwd=~/project-b   filed under  users-...-project-c
1  cwd=~/project-b   filed under  users-...-project-d
1  cwd=~/project-b   filed under  users-...-project-e
1  cwd=~/project-f   filed under  users-...-project-g
1  cwd=~/project-h   filed under  users-...-project-a

Same pattern every time: the file sits under the project that was active before the switch.

Things that are not the cause (checked):

  • Not a symlinked working directory: the slug follows realpath, so ~/link-to-repo and ~/repo produce the same slug.
  • Not a stale cwd in the header — the header is correct; the path is the wrong half.
  • Not user flags: no --session / --add-dir / --resume path involved.

Impact

  • Sessions silently disappear from the project they belong to, and pollute another project's history.
  • cmd -c / /resume can pull the wrong history into a session that then operates on a different repo.
  • Renaming/deleting a project's history affects the wrong chats.

Workaround applied

Moved the 8 non-running transcripts (.jsonl + .meta.json + .checkpoints.jsonl) into the folder matching each header's cwd; a re-scan then showed 0 misfiled except the live session. A restart is needed before the app's catalog reflects the moves.

Suggested fix: derive the transcript path from the session's own resolved cwd at write time (and re-check it on each append), rather than from the app's cached "active project".

Environment

  • Command Code 1.93.4
  • macOS 27.0.1
  • Desktop app, interactive sessions
  • Trace id (this session): 40428be545140954981303d6f8a8694b

Activity

  1. vipulgupta2048 commented on Nov 27, 2026

    @vipulgupta2048
    Member

    Hello @imharikumaran Thanks for the feedback. Will ensure this reaches the Desktop team for them to work on it

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions