Skip to content

fix(agent): run native Claude executable directly - #2552

Merged
charlesvien merged 4 commits into
PostHog:mainfrom
K3N4Y:posthog-code/fix-claude-native-executable
Jun 10, 2026
Merged

fix(agent): run native Claude executable directly#2552
charlesvien merged 4 commits into
PostHog:mainfrom
K3N4Y:posthog-code/fix-claude-native-executable

Conversation

@K3N4Y

@K3N4Y K3N4Y commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Problem

Packaged PostHog Code builds now bundle Claude as a platform-specific native executable via @anthropic-ai/claude-agent-sdk optional dependencies.

On Linux, for example Fedora, CLAUDE_CODE_EXECUTABLE points 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.

@greptile-apps

greptile-apps Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor
Prompt To Fix All With AI
Fix 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

Comment thread packages/agent/src/adapters/claude/session/options.test.ts Outdated
@charlesvien charlesvien self-assigned this Jun 10, 2026
@K3N4Y

K3N4Y commented Jun 10, 2026

Copy link
Copy Markdown
Contributor Author

The branch was outdated, you can try again. @charlesvien

@charlesvien
charlesvien force-pushed the posthog-code/fix-claude-native-executable branch from 581e068 to eecc600 Compare June 10, 2026 06:16
@charlesvien
charlesvien enabled auto-merge (squash) June 10, 2026 06:25
@charlesvien
charlesvien merged commit dbf6b51 into PostHog:main Jun 10, 2026
19 checks passed
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.

2 participants