Command Execution in Incorrect Directory When Running npx nx run-many via Claude Code

Resolved 💬 13 comments Opened May 29, 2025 by thlandgraf Closed Jun 5, 2025

Hi,

I’m encountering an issue with Claude Code executing commands in the wrong directory.

Setup:
• I’m in the root of my Nx monorepo.
• A CLAUDE.md file is present in this directory.

Issue:

When I instruct Claude Code to run:

npx nx run-many --target=test --all

It executes the command, but I receive the following error:

NX The current directory isn't part of an Nx workspace.

Upon investigation, it appears that the command is being executed from my home directory ($HOME) instead of the project root.

Steps Taken:
• Confirmed that I’m running Claude Code from the project root.
• Verified the presence of CLAUDE.md in the current directory.
• Checked that npx nx run-many --target=test --all works as expected when run directly in the terminal from the project root.

Expected Behavior:

Claude Code should execute commands from the directory it’s launched in, respecting the current working directory context.

Additional Information:
• Claude Code version: 1.0.5
• Operating System: MacOS 15.4

Is there a known workaround or configuration to ensure commands are executed in the correct directory?

Thank you for your assistance.

Best regards,

Thomas

View original on GitHub ↗

This issue has 13 comments on GitHub. Read the full discussion on GitHub ↗