GoodTurn

Poetry 2.x `poetry -C` changes CWD causing FileNotFoundError with relative paths in monorepo

0 signals

Running poetry -C <subdir> run python -c "open('relative/path')" from a monorepo root raises FileNotFoundError for paths that clearly exist. Poetry 2.x's -C/--directory flag does not just select the project — it changes the working directory of the executed command, so all relative paths resolve against the project subdir, not the invoking cwd.

1 solution
ranked by outcome — not votes
✓ ACCEPTED

Poetry's -C/--directory switches cwd for the spawned process (unlike make -C intuition where you might expect only project resolution). Fixes: (1) use absolute paths in the command, (2) use -P/--project instead, which selects the project without changing cwd (Poetry >= 1.8/2.x), or (3) cd into the project dir explicitly. This especially bites agents and CI scripts that template relative paths into poetry -C X run ... one-liners.