Skip to content

fix: prevent corruption of native Claude Code binary on macOS#6

Merged
itz4blitz merged 1 commit intoitz4blitz:mainfrom
LarsenClose:fix/native-binary-corruption
Jan 28, 2026
Merged

fix: prevent corruption of native Claude Code binary on macOS#6
itz4blitz merged 1 commit intoitz4blitz:mainfrom
LarsenClose:fix/native-binary-corruption

Conversation

@LarsenClose
Copy link

Problem

The parallel-execution.js module corrupts native Claude Code binaries on macOS when running npx @itz4blitz/agentful init.

The code reads the Claude Code binary as UTF-8 text (fs.readFileSync(claudePath, 'utf8')), which replaces invalid byte sequences with U+FFFD replacement characters (ef bf bd). When written back, the binary becomes corrupted and fails with exec format error.

This affects users who install Claude Code via the official bash installer (curl -fsSL https://claude.ai/install.sh | bash), which produces a native Mach-O binary rather than the npm-installed JavaScript version.

Solution

Added isNativeBinary() helper that checks file magic bytes before any read operations:

  • cffaedfe - Mach-O 64-bit (macOS arm64/x64)
  • cafebabe - Mach-O universal binary
  • 7f454c46 - ELF (Linux)

Both detectTeammateTool() and enableTeammateTool() now check for native binaries and skip patching with an appropriate message.

Testing

  • Added 2 new tests for native binary detection and rejection
  • All 636 tests pass

Reproduction

# Install native Claude Code
curl -fsSL https://claude.ai/install.sh | bash

# Run agentful init (corrupts binary)
npx @itz4blitz/agentful init

# Binary is now corrupted
claude --version
# zsh: exec format error: claude

The parallel-execution module was reading the Claude Code binary as UTF-8
text and writing it back, which corrupts native Mach-O binaries. Invalid
byte sequences get replaced with U+FFFD replacement characters.

This fix adds isNativeBinary() detection that checks Mach-O magic bytes
(cffaedfe, cafebabe) and ELF header (7f454c46) before attempting any
read/patch operations. Native binaries are now skipped with an appropriate
error message.

Fixes binary corruption when running 'npx @itz4blitz/agentful init' on
systems with native Claude Code installed via the bash installer.

- Add isNativeBinary() helper to detect compiled executables
- Guard detectTeammateTool() against native binary reads
- Guard enableTeammateTool() against native binary patching
- Add tests for native binary detection and rejection
@itz4blitz itz4blitz merged commit 742d343 into itz4blitz:main Jan 28, 2026
9 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.

3 participants