Skip to content

codex-rescue: forward intended worktree cwd to detached task #493

Description

@rh7

Problem

A coding task launched through the Claude codex:codex-rescue forwarder can be instructed to work in a secondary worktree, but the forwarder launches the companion task from Claude's current/main checkout. The prompt-level cd instruction is only advisory, so Codex may root its workspace in and dirty the main checkout.

This happened during a multi-worktree Command Center session: the detached task edited the main checkout for roughly 20 minutes before self-relocating, and the dirty main later blocked the repository's post-merge fast-forward sync.

Original report: https://github.com/gr-ai-labs/message-assistant/issues/889

Current behavior

plugins/codex/agents/codex-rescue.md invokes:

node "${CLAUDE_PLUGIN_ROOT}/scripts/codex-companion.mjs" task ...

The companion already accepts task --cwd <path> and uses that cwd for the worker and workspace root, but the rescue command/agent has no routing argument for an intended worktree and therefore does not pass it.

Suggested approach

Add an explicit rescue routing control for the target checkout/worktree (for example --cwd <path>), validate/resolve it before launch, and pass it to codex-companion.mjs task --cwd .... Keep the cwd out of the natural-language task prompt.

Acceptance criteria

  • A rescue-forwarded coding task targeted at a worktree is rooted at that worktree by the runtime.
  • The task cannot dirty the caller's main checkout merely because Claude was launched there.
  • Foreground and detached/background task paths preserve the selected cwd.
  • A regression test covers a caller cwd different from the target worktree.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions