Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions scripts/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,16 @@
* via Bun's -d flag (bunfig.toml [define] doesn't propagate to
* dynamically imported modules at runtime).
*/
import { join, dirname } from "node:path";
import { fileURLToPath } from "node:url";
import { getMacroDefines } from "./defines.ts";

// Resolve project root from this script's location
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const projectRoot = join(__dirname, "..");
const cliPath = join(projectRoot, "src/entrypoints/cli.tsx");

const defines = getMacroDefines();

const defineArgs = Object.entries(defines).flatMap(([k, v]) => [
Expand All @@ -32,8 +40,8 @@ const inspectArgs = process.env.BUN_INSPECT
: [];

const result = Bun.spawnSync(
["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.

);

process.exit(result.exitCode ?? 0);