fix: resolve absolute path in dev.ts for cross-directory execution#135
Conversation
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>
📝 WalkthroughWalkthroughThe 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
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~4 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
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
| ["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 }, |
There was a problem hiding this comment.
🧩 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.tsxRepository: 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.tsRepository: 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.tsRepository: 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 tsxRepository: 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 2Repository: 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.tsxRepository: 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 2Repository: 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.tsRepository: 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 2Repository: 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.tsxRepository: 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.
| { 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.
The dev script previously used a relative path "src/entrypoints/cli.tsx" which would fail when executed from outside the project root directory.
Changes:
This allows running "bun run /path/to/scripts/dev.ts" from any directory.
Summary by CodeRabbit