fix(tools): replace hardcoded claude CLI with opencode in pai.ts#99
fix(tools): replace hardcoded claude CLI with opencode in pai.ts#99eddovandenboom wants to merge 1 commit intoSteffen025:mainfrom
Conversation
pai.ts was written for Anthropic's claude CLI but PAI-OpenCode ships with OpenCode. This caused an ENOENT crash on launch for all users who installed via install.sh. Fixes: - cmdLaunch: spawn opencode instead of claude - cmdLaunch: --resume → --continue (OpenCode flag) - cmdPrompt: claude -p → opencode run - getCurrentVersion: claude --version → opencode --version - cmdUpdate: replaced Homebrew/curl claude install with opencode upgrade - getLatestVersion: replaced Claude GCS URL with opencode-ai npm registry - Help text: updated all Claude Code references to OpenCode Fixes Steffen025#98
📝 WalkthroughWalkthroughThe pai.ts file migrates all operational references from Claude Code to OpenCode. Version checking now fetches from NPM registry and parses JSON responses. The launch command spawns Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
.opencode/PAI/Tools/pai.ts (1)
2-19: Nitpick: Header comments still reference "Claude Code".The file header documentation (lines 5, 9, 14) still mentions "Claude Code" and "Claude" while the implementation has migrated to OpenCode. Consider updating these comments for consistency:
-* Comprehensive CLI for managing Claude Code with dynamic MCP loading, +* Comprehensive CLI for managing OpenCode with dynamic MCP loading, ... -* pai Launch Claude (default profile) +* pai Launch OpenCode (default profile) ... -* pai update Update Claude Code +* pai update Update OpenCode🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In @.opencode/PAI/Tools/pai.ts around lines 2 - 19, Update the top-of-file header comment to remove references to "Claude Code" and "Claude" and replace them with the current product name (e.g., "OpenCode" or "PAI") so the usage examples and description are consistent; specifically change occurrences of the strings "Claude Code" and "Claude" in the header and usage lines (the lines showing "pai", "pai -m", "pai update", etc.) to the correct project name and adjust any wording (e.g., "Launch OpenCode (default profile)") to match current terminology.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In @.opencode/PAI/Tools/pai.ts:
- Around line 533-535: algorithm.ts still spawns the hardcoded "claude" binary
in three places (Bun.spawn(["claude", ...]) in the parallel agent loop,
spawnSync("claude", [...]) in the sequential loop, and spawn("claude", [...]) in
the interactive session), which will cause ENOENT for users without that CLI;
update those three call sites to invoke the unified opencode entrypoint (e.g.,
"opencode" with args ["run", prompt, ...]) or call a new/shared wrapper (create
or reuse a helper similar to cmdPrompt) that constructs and spawns the correct
command, preserves existing flags/args and I/O handling, and surfaces spawn
errors cleanly instead of assuming "claude" exists.
---
Nitpick comments:
In @.opencode/PAI/Tools/pai.ts:
- Around line 2-19: Update the top-of-file header comment to remove references
to "Claude Code" and "Claude" and replace them with the current product name
(e.g., "OpenCode" or "PAI") so the usage examples and description are
consistent; specifically change occurrences of the strings "Claude Code" and
"Claude" in the header and usage lines (the lines showing "pai", "pai -m", "pai
update", etc.) to the correct project name and adjust any wording (e.g., "Launch
OpenCode (default profile)") to match current terminology.
🪄 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: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 122fefaf-4520-47d2-b400-f427ced3fb66
📒 Files selected for processing (1)
.opencode/PAI/Tools/pai.ts
| async function cmdPrompt(prompt: string) { | ||
| // One-shot prompt execution | ||
| // NOTE: No --dangerously-skip-permissions - rely on settings.json permissions | ||
| const args = ["claude", "-p", prompt]; | ||
| // One-shot prompt execution via `opencode run <message>` | ||
| const args = ["opencode", "run", prompt]; |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Verify hardcoded claude references in algorithm.ts
rg -n '"claude"' --type ts -C2Repository: Steffen025/pai-opencode
Length of output: 49
🏁 Script executed:
# Find algorithm.ts file
fd -t f "algorithm\.ts" --type fRepository: Steffen025/pai-opencode
Length of output: 49
🏁 Script executed:
# Search for spawn patterns and claude references more broadly
rg -i "spawn|claude" --type ts -n | head -50Repository: Steffen025/pai-opencode
Length of output: 5184
🏁 Script executed:
# Check if algorithm.ts exists and its size
ls -la .opencode/PAI/Tools/ 2>/dev/null || find . -name "algorithm.ts" -type fRepository: Steffen025/pai-opencode
Length of output: 3395
🏁 Script executed:
# Check lines around 665
sed -n '660,680p' .opencode/PAI/Tools/algorithm.ts | cat -nRepository: Steffen025/pai-opencode
Length of output: 1000
🏁 Script executed:
# Check lines around 1121
sed -n '1115,1140p' .opencode/PAI/Tools/algorithm.ts | cat -nRepository: Steffen025/pai-opencode
Length of output: 1190
🏁 Script executed:
# Check lines around 1231
sed -n '1225,1255p' .opencode/PAI/Tools/algorithm.ts | cat -nRepository: Steffen025/pai-opencode
Length of output: 1373
🏁 Script executed:
# Search for any spawn calls in algorithm.ts
rg -n "spawn|Bun\." .opencode/PAI/Tools/algorithm.tsRepository: Steffen025/pai-opencode
Length of output: 322
🏁 Script executed:
# Check pai.ts around lines 533-535 to see what's being changed
sed -n '525,545p' .opencode/PAI/Tools/pai.ts | cat -nRepository: Steffen025/pai-opencode
Length of output: 794
🏁 Script executed:
# Check imports in algorithm.ts to understand spawn vs Bun.spawn
head -50 .opencode/PAI/Tools/algorithm.ts | cat -nRepository: Steffen025/pai-opencode
Length of output: 2858
🏁 Script executed:
# Search for any issue `#98` references or related comments
rg -i "issue.*98|#98|ENOENT|opencode run" .opencode/PAI/Tools/Repository: Steffen025/pai-opencode
Length of output: 234
🏁 Script executed:
# Check context around the 3 spawn calls - what functions do they belong to?
rg -B10 'spawn.*"claude"' .opencode/PAI/Tools/algorithm.ts | head -60Repository: Steffen025/pai-opencode
Length of output: 1208
🏁 Script executed:
# Search for TODO/FIXME about migration in algorithm.ts
rg -i "todo|fixme|migration|issue|claude.*opencode|opencode.*claude" .opencode/PAI/Tools/algorithm.tsRepository: Steffen025/pai-opencode
Length of output: 49
🏁 Script executed:
# Check the pai.ts spawn call more carefully - verify it matches child_process API
sed -n '533,545p' .opencode/PAI/Tools/pai.tsRepository: Steffen025/pai-opencode
Length of output: 421
🏁 Script executed:
# Get more context - what are the function names containing these spawns?
rg -B20 'Bun.spawn\(\["claude"' .opencode/PAI/Tools/algorithm.ts | grep -E "^[0-9]+.*function|^[0-9]+.*async function"Repository: Steffen025/pai-opencode
Length of output: 49
🏁 Script executed:
# Verify pai.ts imports to understand the spawn API being used
head -20 .opencode/PAI/Tools/pai.tsRepository: Steffen025/pai-opencode
Length of output: 783
🏁 Script executed:
# Check the actual spawn signature used in pai.ts - is it child_process.spawn?
rg -B5 "spawn.*args" .opencode/PAI/Tools/pai.ts | head -20Repository: Steffen025/pai-opencode
Length of output: 413
🏁 Script executed:
# Check pai.ts imports to see which spawn is being used
grep -n "import.*spawn\|from.*bun" .opencode/PAI/Tools/pai.ts | head -10Repository: Steffen025/pai-opencode
Length of output: 109
🏁 Script executed:
# Look at the full context of pai.ts spawn usage to understand the API
sed -n '1,100p' .opencode/PAI/Tools/pai.ts | grep -A3 "import"Repository: Steffen025/pai-opencode
Length of output: 453
Critical: algorithm.ts still hardcodes claude binary—will cause ENOENT crashes after merge.
The pai.ts change correctly migrates to opencode run for one-shot prompts, but algorithm.ts still spawns the claude binary directly in three active code paths:
- Line 669:
Bun.spawn(["claude", "-p", prompt, ...])—parallel agent iteration - Line 1122:
spawnSync("claude", [...])—sequential loop iteration - Line 1235:
spawn("claude", [...])—interactive session launch
Users without the claude CLI installed will encounter ENOENT errors when using algorithm features after this PR merges. Either extend this PR to update algorithm.ts or create a follow-up issue to track the migration.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In @.opencode/PAI/Tools/pai.ts around lines 533 - 535, algorithm.ts still spawns
the hardcoded "claude" binary in three places (Bun.spawn(["claude", ...]) in the
parallel agent loop, spawnSync("claude", [...]) in the sequential loop, and
spawn("claude", [...]) in the interactive session), which will cause ENOENT for
users without that CLI; update those three call sites to invoke the unified
opencode entrypoint (e.g., "opencode" with args ["run", prompt, ...]) or call a
new/shared wrapper (create or reuse a helper similar to cmdPrompt) that
constructs and spawns the correct command, preserves existing flags/args and I/O
handling, and surfaces spawn errors cleanly instead of assuming "claude" exists.
pai.ts was written for Anthropic's claude CLI but PAI-OpenCode ships with OpenCode. This caused an ENOENT crash on launch when installed via install.sh.
Fixes:
Fixes #98
Summary by CodeRabbit
Updates
opencode runinstead of previous syntax--continueflagopencode upgradecommand for installations