fix(agent): run native Claude executable directly#2552
Conversation
Prompt To Fix All With AIFix the following 1 code review issue. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 1
packages/agent/src/adapters/claude/session/options.test.ts:85-101
**Non-parameterised tests for same function under different inputs**
These two tests exercise the same function (`buildSessionOptions`) with different `CLAUDE_CODE_EXECUTABLE` values and expected `executable` outputs — a classic parameterisation candidate. The team convention is to always prefer `it.each` for this pattern. Writing them as a single `it.each` table also makes it easier to add future cases (e.g. `.mjs`, `.cjs`, `claude.exe`) without duplicating the setup/teardown boilerplate.
Reviews (1): Last reviewed commit: "fix(agent): run native Claude executable..." | Re-trigger Greptile |
| it("does not force node when Claude executable is a native binary", () => { | ||
| process.env.CLAUDE_CODE_EXECUTABLE = "/tmp/claude"; | ||
|
|
||
| const options = buildSessionOptions(makeParams()); | ||
|
|
||
| expect(options.pathToClaudeCodeExecutable).toBe("/tmp/claude"); | ||
| expect(options.executable).toBeUndefined(); | ||
| }); | ||
|
|
||
| it("uses node when Claude executable is the legacy JavaScript CLI", () => { | ||
| process.env.CLAUDE_CODE_EXECUTABLE = "/tmp/cli.js"; | ||
|
|
||
| const options = buildSessionOptions(makeParams()); | ||
|
|
||
| expect(options.pathToClaudeCodeExecutable).toBe("/tmp/cli.js"); | ||
| expect(options.executable).toBe("node"); | ||
| }); |
There was a problem hiding this comment.
Non-parameterised tests for same function under different inputs
These two tests exercise the same function (buildSessionOptions) with different CLAUDE_CODE_EXECUTABLE values and expected executable outputs — a classic parameterisation candidate. The team convention is to always prefer it.each for this pattern. Writing them as a single it.each table also makes it easier to add future cases (e.g. .mjs, .cjs, claude.exe) without duplicating the setup/teardown boilerplate.
Context Used: Do not attempt to comment on incorrect alphabetica... (source)
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/agent/src/adapters/claude/session/options.test.ts
Line: 85-101
Comment:
**Non-parameterised tests for same function under different inputs**
These two tests exercise the same function (`buildSessionOptions`) with different `CLAUDE_CODE_EXECUTABLE` values and expected `executable` outputs — a classic parameterisation candidate. The team convention is to always prefer `it.each` for this pattern. Writing them as a single `it.each` table also makes it easier to add future cases (e.g. `.mjs`, `.cjs`, `claude.exe`) without duplicating the setup/teardown boilerplate.
**Context Used:** Do not attempt to comment on incorrect alphabetica... ([source](https://app.greptile.com/review/custom-context?memory=instruction-0))
How can I resolve this? If you propose a fix, please make it concise.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Problem
Packaged PostHog Code builds now bundle Claude as a platform-specific native executable via
@anthropic-ai/claude-agent-sdkoptional dependencies.On Linux, for example Fedora,
CLAUDE_CODE_EXECUTABLEpoints to the bundled native binary:text
.vite/build/claude-cli/claude
However, the Claude session options still forced:
executable: "node"
This can cause the SDK to try to run the native binary through Node, effectively:
node /path/to/claude
instead of executing it directly:
/path/to/claude
That breaks because the native Claude binary is not JavaScript.
Changes
Make executable: "node" conditional in Claude session options.
Keep using Node only when CLAUDE_CODE_EXECUTABLE points to the legacy JavaScript CLI, e.g. cli.js.
For native Claude executables like claude or claude.exe, leave executable unset so the SDK can execute the binary directly.
Added tests covering both cases:
native binary path does not force Node
legacy .js CLI path still uses Node
How did you test this?
Automated tests run:
PATH=/home/kenayperez/code/node_modules/.bin:/usr/bin:/usr/local/bin:/home/kenayperez/.local/bin /usr/bin/node /usr/lib/node_modules/pnpm/bin/pnpm.cjs -C packages/agent exec vitest run src/adapters/claude/session/options.test.ts --reporter=verbose
Result:
Test Files 1 passed (1)
Tests 8 passed (8)
Also ran:
PATH=/home/kenayperez/code/node_modules/.bin:/usr/bin:/usr/local/bin:/home/kenayperez/.local/bin /usr/bin/node /usr/lib/node_modules/pnpm/bin/pnpm.cjs --filter @posthog/agent typecheck
Result: exited with code 0.