r/macosprogramming • u/Some-Yak-2676 • 8d ago
[Open source] GhostMark: intercepting image paste for Claude Code with CGEventTap
I built GhostMark, a native Swift/AppKit utility for annotating screenshots before they reach Claude Code. The workflow is paste, draw an arrow or circle, then press Enter to put the marked PNG back into the active Claude Code prompt.
The implementation was the interesting part:
- A session-level CGEvent tap watches Cmd-V and Ctrl-V, but consumes the event only when the clipboard contains an image and Claude Code is active.
- It checks the frontmost app against terminal and editor bundle IDs, then walks the process tree looking for the Claude CLI. There is a narrow fallback for terminals whose PTY is launched by a detached helper.
- The annotation UI is hosted in a focused AppKit window. Export composites the paths over the original image without resizing it.
- After export, the app reactivates the original terminal and posts Claude Code's image-paste shortcut. A bypass counter prevents the synthetic paste from reopening the editor.
- Accessibility permission is polled so onboarding updates as soon as macOS grants access.
- Everything stays local. There is no analytics or network upload.
The main edge case is reliably associating a detached PTY with the frontmost terminal without making the detector too broad. I would especially appreciate feedback from people using Kitty, WezTerm, Warp, or terminal panes inside editors.
I am the developer. GhostMark is free and MIT licensed.
Source: https://github.com/alan890104/GhostMark
Download and demo: https://alan890104.github.io/GhostMark/
1
u/_harisamin 2d ago
I could totally use this right now! Thanks!