Skip to content

Conversation

@ThomasK33
Copy link
Member

Copy plan file when forking workspace so the forked workspace can continue working with the same plan context.

Changes:

  • Add copyPlanFile helper in src/node/utils/runtime/helpers.ts (mirrors existing movePlanFile pattern)
  • Call copyPlanFile in workspaceService.fork() after session files are copied

📋 Implementation Plan

Plan: Copy Plan File on Workspace Fork

Summary

Add functionality to copy the source workspace's plan file when forking, allowing the forked workspace to continue working with the same plan context.

Problem

When a workspace is forked via /fork, the following files are copied:

  • chat.jsonl (chat history)
  • partial.json (partial streaming state)
  • session-usage.json (usage tracking)

However, the plan file (~/.mux/plans/{project}/{workspace}.md) is not copied. This means the forked workspace starts without the plan context, even though it inherits the chat history where the plan was discussed.

Solution

Add a copyPlanFile helper function and invoke it during the fork operation in workspaceService.fork().

Implementation

1. Add copyPlanFile helper in src/node/utils/runtime/helpers.ts

Create a new function following the same pattern as movePlanFile:

/**
 * Copy a plan file from one workspace to another (e.g., during fork).
 * Silently succeeds if source file doesn't exist.
 */
export async function copyPlanFile(
  runtime: Runtime,
  sourceWorkspaceName: string,
  targetWorkspaceName: string,
  projectName: string
): Promise<void> {
  const sourcePath = getPlanFilePath(sourceWorkspaceName, projectName);
  const targetPath = getPlanFilePath(targetWorkspaceName, projectName);

  try {
    await runtime.stat(sourcePath);
    await execBuffered(runtime, `cp "${sourcePath}" "${targetPath}"`, { cwd: "/tmp", timeout: 5 });
  } catch {
    // No plan file to copy, that's fine
  }
}

2. Update src/node/services/workspaceService.ts

  1. Add import for copyPlanFile:

    import { movePlanFile, copyPlanFile } from "@/node/utils/runtime/helpers";
  2. Call copyPlanFile in the fork() method after successfully copying session files (~line 924):

    // Copy plan file if it exists (uses workspace name, not ID)
    await copyPlanFile(runtime, sourceMetadata.name, newName, projectName);

File Changes

File Change
src/node/utils/runtime/helpers.ts Add copyPlanFile function (~15 LoC)
src/node/services/workspaceService.ts Import + call copyPlanFile (~3 LoC)

Net LoC estimate: ~+18 lines

Testing

The existing test patterns for movePlanFile in rename operations provide a template. The change is straightforward:

  • copyPlanFile follows the same error-handling pattern as movePlanFile
  • Silently succeeds if no plan file exists (idempotent)
  • Uses runtime abstraction, so works for both local and SSH runtimes

Manual verification:

  1. Create a workspace with a plan
  2. Fork it with /fork new-name
  3. Verify the new workspace has a copy of the plan file at ~/.mux/plans/{project}/new-name.md

Edge Cases

  • No plan file exists: Silent success (matches movePlanFile behavior)
  • Target file already exists: cp will overwrite, which is correct for forks
  • SSH runtime: Works via runtime abstraction (same as existing movePlanFile)

Generated with mux • Model: anthropic:claude-opus-4-5 • Thinking: high

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@ThomasK33 ThomasK33 force-pushed the workspace-fork-plan branch 2 times, most recently from 1994c5f to e5b019c Compare December 17, 2025 10:32
@ThomasK33
Copy link
Member Author

@codex review

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@ThomasK33
Copy link
Member Author

@codex review

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

When a workspace is forked via /fork, the plan file is now copied
along with the chat history, partial state, and usage tracking.

This allows the forked workspace to continue working with the same
plan context as the original.

Changes:
- Add copyPlanFile helper in src/node/utils/runtime/helpers.ts
- Call copyPlanFile in workspaceService.fork() after session files

Change-Id: Iaee04cb44c1b5a98e13eb693fa729a078b8d0013
Signed-off-by: Thomas Kosiewski <tk@coder.com>
@ThomasK33
Copy link
Member Author

@codex review

@chatgpt-codex-connector
Copy link

Codex Review: Didn't find any major issues. Hooray!

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@ThomasK33 ThomasK33 added this pull request to the merge queue Dec 17, 2025
Merged via the queue into main with commit 36b88ce Dec 17, 2025
20 checks passed
@ThomasK33 ThomasK33 deleted the workspace-fork-plan branch December 17, 2025 11:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant