Skip to content

fix(tools): replace hardcoded claude CLI with opencode in pai.ts#99

Open
eddovandenboom wants to merge 1 commit intoSteffen025:mainfrom
eddovandenboom:fix/pai-uses-opencode-not-claude
Open

fix(tools): replace hardcoded claude CLI with opencode in pai.ts#99
eddovandenboom wants to merge 1 commit intoSteffen025:mainfrom
eddovandenboom:fix/pai-uses-opencode-not-claude

Conversation

@eddovandenboom
Copy link
Copy Markdown

@eddovandenboom eddovandenboom commented Mar 29, 2026

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:

  • 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 #98

Summary by CodeRabbit

Updates

  • Tool rebranding: All CLI operational references updated to use "opencode" instead of "claude"
  • Version checking mechanism changed to npm registry lookup for latest releases
  • Command syntax updates: prompt execution now uses opencode run instead of previous syntax
  • Session management improved: resume behavior now uses --continue flag
  • Simplified update flow with new opencode upgrade command for installations

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
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 29, 2026

📝 Walkthrough

Walkthrough

The 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 opencode instead of claude. Resume behavior uses --continue instead of --resume. The update flow simplifies to run opencode upgrade directly. One-shot prompt execution changes from claude -p to opencode run.

Changes

Cohort / File(s) Summary
Tool Migration: Claude to OpenCode
.opencode/PAI/Tools/pai.ts
Replaced all claude CLI references with opencode. Updated getCurrentVersion() to run opencode --version. Changed version lookup from plain-text bucket fetch to NPM registry JSON parsing (https://registry.npmjs.org/opencode-ai/latest). Modified cmdLaunch() to spawn opencode with --continue flag instead of --resume. Simplified cmdUpdate() to call opencode upgrade directly, removing version comparison and Bun update logic. Changed one-shot execution from claude -p <prompt> to opencode run <prompt>. Updated help/usage strings accordingly.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 Hop, hop, hooray! The claude calls fade,
OpenCode's bright commands now cascade,
NPM registries fetch versions clean,
Upgrades simplified, the best we've seen!
A smoother path from start to end, bon voyage, my friend! 🚀

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 12.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely describes the main change: replacing hardcoded claude CLI references with opencode in pai.ts.
Linked Issues check ✅ Passed All code changes directly address issue #98 requirements: spawn 'opencode' instead of 'claude', update command flags, point to opencode npm registry, and replace install methods.
Out of Scope Changes check ✅ Passed All changes in pai.ts are directly scoped to replacing claude CLI with opencode CLI as specified in issue #98; no unrelated modifications detected.

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

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

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.

❤️ Share

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

Copy link
Copy Markdown
Contributor

@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

🧹 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

📥 Commits

Reviewing files that changed from the base of the PR and between c6d9ada and a612320.

📒 Files selected for processing (1)
  • .opencode/PAI/Tools/pai.ts

Comment on lines 533 to +535
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];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify hardcoded claude references in algorithm.ts
rg -n '"claude"' --type ts -C2

Repository: Steffen025/pai-opencode

Length of output: 49


🏁 Script executed:

# Find algorithm.ts file
fd -t f "algorithm\.ts" --type f

Repository: 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 -50

Repository: 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 f

Repository: Steffen025/pai-opencode

Length of output: 3395


🏁 Script executed:

# Check lines around 665
sed -n '660,680p' .opencode/PAI/Tools/algorithm.ts | cat -n

Repository: Steffen025/pai-opencode

Length of output: 1000


🏁 Script executed:

# Check lines around 1121
sed -n '1115,1140p' .opencode/PAI/Tools/algorithm.ts | cat -n

Repository: Steffen025/pai-opencode

Length of output: 1190


🏁 Script executed:

# Check lines around 1231
sed -n '1225,1255p' .opencode/PAI/Tools/algorithm.ts | cat -n

Repository: 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.ts

Repository: 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 -n

Repository: 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 -n

Repository: 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 -60

Repository: 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.ts

Repository: 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.ts

Repository: 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.ts

Repository: 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 -20

Repository: 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 -10

Repository: 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.

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.

Installation issue

1 participant