Skip to content

feat: add --workdir flag for deterministic relative patch paths#13

Open
lyonsno wants to merge 1 commit intoagynio:mainfrom
lyonsno:workdir-cli
Open

feat: add --workdir flag for deterministic relative patch paths#13
lyonsno wants to merge 1 commit intoagynio:mainfrom
lyonsno:workdir-cli

Conversation

@lyonsno
Copy link

@lyonsno lyonsno commented Mar 4, 2026

Summary

Add a --workdir CLI option to codex-tools-mcp so relative file paths used by apply_patch resolve deterministically from a caller-provided working directory.

This makes stdio hosts (like Zed) more reliable when they launch the MCP server from an unpredictable process cwd.

Changes

  • Add CLI parsing for:
    • --workdir <path>
    • --workdir=<path>
  • Extend CliAction::Run to carry optional workdir.
  • In main, call env::set_current_dir(workdir) before starting the server loop.
  • Improve help text to document --workdir.
  • Add integration test that proves behavior:
    • server launched from directory A
    • --workdir points to directory B
    • relative apply_patch writes into B, not A

Why

Without an explicit cwd setting, relative patch paths depend on the host process launch directory. In some MCP host setups this causes relative paths to fail or land in the wrong place.

--workdir gives hosts a stable and explicit path anchor.

Testing

Commands run:

  • cargo test applies_patch_in_explicit_workdir -- --nocapture
  • cargo test

Results:

  • New integration test passes.
  • Full test suite passes (3 passed, 0 failed).

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