Skip to content

fix: resolve absolute path in dev.ts for cross-directory execution#135

Merged
claude-code-best merged 1 commit intoclaude-code-best:mainfrom
xuzhongpeng:fix/dev-script-path-resolution
Apr 5, 2026
Merged

fix: resolve absolute path in dev.ts for cross-directory execution#135
claude-code-best merged 1 commit intoclaude-code-best:mainfrom
xuzhongpeng:fix/dev-script-path-resolution

Conversation

@xuzhongpeng
Copy link
Copy Markdown

@xuzhongpeng xuzhongpeng commented Apr 5, 2026

The dev script previously used a relative path "src/entrypoints/cli.tsx" which would fail when executed from outside the project root directory.

Changes:

  • Add path resolution using import.meta.url to locate project root
  • Use absolute path for cli.tsx entry point
  • Set cwd option in Bun.spawnSync to ensure correct working directory

This allows running "bun run /path/to/scripts/dev.ts" from any directory.

Summary by CodeRabbit

  • Chores
    • Improved development script robustness by enhancing project root path resolution and working directory handling during development builds.

The dev script previously used a relative path "src/entrypoints/cli.tsx" which would fail when executed from outside the project root directory.

Changes:
- Add path resolution using import.meta.url to locate project root
- Use absolute path for cli.tsx entry point
- Set cwd option in Bun.spawnSync to ensure correct working directory

This allows running "bun run /path/to/scripts/dev.ts" from any directory.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 5, 2026

📝 Walkthrough

Walkthrough

The dev script now computes the project root using the current module's file path, constructs an absolute path to the CLI entry point, and passes it to the Bun subprocess with the working directory explicitly set to the project root instead of relying on relative paths.

Changes

Cohort / File(s) Summary
Dev Script Path Resolution
scripts/dev.ts
Modified to derive project root from the current module's location using fileURLToPath(import.meta.url) and dirname. Constructs absolute path to src/entrypoints/cli.tsx and sets cwd: projectRoot on the Bun.spawnSync call, while preserving macro defines, feature flags, and stdio configuration.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~4 minutes

Poem

🐰 Absolute paths, no more guessing games,
The root is now clear in dev's steady frames,
A hop to the true ground where processes run,
Working directories aligned—dev builds are done! 🌱

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and accurately describes the main change: resolving an absolute path in dev.ts to enable cross-directory execution, which directly addresses the core issue.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@scripts/dev.ts`:
- Line 44: Remove the forced working directory in the spawn options so the CLI
runs from the user's current directory: locate where Bun.spawn (or child process
spawn) is called in scripts/dev.ts (the call that passes { stdio:
["inherit","inherit","inherit"], cwd: projectRoot }), and delete the cwd:
projectRoot property (leave the stdio array only) so the spawned process uses
the caller's process.cwd(); ensure cliPath remains an absolute path and no other
logic depends on projectRoot being applied to the child process.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 7fdd4ed6-cee1-451c-b0d4-67f64c415f5a

📥 Commits

Reviewing files that changed from the base of the PR and between 918defa and 714ef13.

📒 Files selected for processing (1)
  • scripts/dev.ts

["bun", ...inspectArgs, "run", ...defineArgs, ...featureArgs, "src/entrypoints/cli.tsx", ...process.argv.slice(2)],
{ stdio: ["inherit", "inherit", "inherit"] },
["bun", ...inspectArgs, "run", ...defineArgs, ...featureArgs, cliPath, ...process.argv.slice(2)],
{ stdio: ["inherit", "inherit", "inherit"], cwd: projectRoot },
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check if there are any relative path references in cli.tsx that would require cwd to be set
rg -n 'process\.cwd\(\)|__dirname|import\.meta\.url' src/entrypoints/cli.tsx

Repository: claude-code-best/claude-code

Length of output: 54


🏁 Script executed:

# First, let's check the actual context around line 44 in scripts/dev.ts
sed -n '35,55p' scripts/dev.ts

Repository: claude-code-best/claude-code

Length of output: 558


🏁 Script executed:

# Check the setOriginalCwd() implementation in src/bootstrap/state.ts
rg -A 10 'setOriginalCwd' src/bootstrap/state.ts

Repository: claude-code-best/claude-code

Length of output: 431


🏁 Script executed:

# Search for all process.cwd() usages across the codebase to understand the actual impact
rg -n 'process\.cwd\(\)' --type ts --type tsx

Repository: claude-code-best/claude-code

Length of output: 99


🏁 Script executed:

# Search for where setOriginalCwd is called
rg -n 'setOriginalCwd' --type ts --type tsx -A 2 -B 2

Repository: claude-code-best/claude-code

Length of output: 99


🏁 Script executed:

# Check the CLI entry point (cli.tsx) to see if it calls setOriginalCwd and how
head -50 src/entrypoints/cli.tsx

Repository: claude-code-best/claude-code

Length of output: 2312


🏁 Script executed:

# Search for process.cwd() usage with a simpler pattern
rg -n 'process\.cwd\(\)' -A 2 -B 2

Repository: claude-code-best/claude-code

Length of output: 6595


🏁 Script executed:

# Verify what cliPath resolves to - check lines before line 44 in scripts/dev.ts
sed -n '1,43p' scripts/dev.ts

Repository: claude-code-best/claude-code

Length of output: 1726


🏁 Script executed:

# Search for calls to setOriginalCwd in all files
rg -n 'setOriginalCwd' --no-binary -A 2 -B 2

Repository: claude-code-best/claude-code

Length of output: 6950


🏁 Script executed:

# Check if cli.tsx imports or uses setOriginalCwd or the bootstrap/state module
rg -n 'setOriginalCwd|bootstrap/state' src/entrypoints/cli.tsx

Repository: claude-code-best/claude-code

Length of output: 54


🏁 Script executed:

# Look for where the bootstrap happens - check for imports in cli.tsx related to initialization
head -100 src/entrypoints/cli.tsx | grep -n 'import\|setOriginalCwd'

Repository: claude-code-best/claude-code

Length of output: 799


Remove cwd: projectRoot to preserve the user's working directory context.

Setting cwd: projectRoot causes the spawned CLI process to see the project root as its current directory, not where the user actually invoked the command. This breaks the intended behavior of allowing invocation "from any directory," since code relying on process.cwd() will always resolve against the project root instead of the user's actual directory.

Since cliPath is an absolute path, the cwd option is unnecessary—Bun can execute the script from any working directory:

Proposed fix: remove cwd option
 const result = Bun.spawnSync(
     ["bun", ...inspectArgs, "run", ...defineArgs, ...featureArgs, cliPath, ...process.argv.slice(2)],
-    { stdio: ["inherit", "inherit", "inherit"], cwd: projectRoot },
+    { stdio: ["inherit", "inherit", "inherit"] },
 );
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
{ stdio: ["inherit", "inherit", "inherit"], cwd: projectRoot },
{ stdio: ["inherit", "inherit", "inherit"] },
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@scripts/dev.ts` at line 44, Remove the forced working directory in the spawn
options so the CLI runs from the user's current directory: locate where
Bun.spawn (or child process spawn) is called in scripts/dev.ts (the call that
passes { stdio: ["inherit","inherit","inherit"], cwd: projectRoot }), and delete
the cwd: projectRoot property (leave the stdio array only) so the spawned
process uses the caller's process.cwd(); ensure cliPath remains an absolute path
and no other logic depends on projectRoot being applied to the child process.

@claude-code-best claude-code-best merged commit ba97889 into claude-code-best:main Apr 5, 2026
2 checks passed
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.

2 participants