Skip to content

Add macOS ad-hoc code signing after binary patching#3

Merged
cpaczek merged 1 commit into
cpaczek:mainfrom
aaronepinto:macos-codesign
Apr 1, 2026
Merged

Add macOS ad-hoc code signing after binary patching#3
cpaczek merged 1 commit into
cpaczek:mainfrom
aaronepinto:macos-codesign

Conversation

@aaronepinto

Copy link
Copy Markdown
Contributor

Summary

  • Adds automatic ad-hoc re-signing (codesign --force --sign -) after every binary patch on macOS
  • Fixes the issue where patching the Mach-O binary invalidates its code signature, causing the kernel to kill the process on launch
  • Works in all code paths: interactive patching, silent apply (SessionStart hook), and restore-via-repatch
  • Surfaces codesign status to the user — shows success in interactive mode, prints manual fallback command if codesign fails
  • Updates the macOS preflight warning from "experimental" to informational
  • Fixes ELF-only terminology in README to be platform-accurate

Changes

File What changed
lib/patcher.mjs New codesignBinary() helper called at end of patchBinary()
lib/tui.mjs New warnCodesign() helper; codesign feedback at all 5 patchBinary call sites
lib/preflight.mjs Updated macOS warning text
README.md Fixed "ELF binary" refs; added codesign step to patch docs; updated limitations

Design decisions

  • Codesign inside patchBinary() — single point of change, all callers get it automatically
  • Never throws — codesign failure is reported but doesn't block the patch result
  • No-op on non-Mac — zero overhead on Linux/Windows
  • restoreBinary() untouched — it restores the original backup with its intact signature

Test plan

  • On macOS: run interactive flow — binary should be patched AND signed
  • Verify with codesign -v <binary-path>
  • Launch claude — should not be killed
  • Test apply --silent — should re-patch and re-sign after update
  • Test restore — should restore original binary
  • On Linux: verify no behavioral change (codesign is a no-op)

On macOS, patching the Claude Code binary invalidates its Mach-O code
signature, causing the kernel to kill the process on launch. This adds
automatic ad-hoc re-signing (codesign --force --sign -) after every
patch, including the silent apply path used by the SessionStart hook.
@cpaczek cpaczek merged commit 641f3ae into cpaczek:main Apr 1, 2026
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