fix: apply iTerm2 terminal colors via AppleScript from Claude Code hook subprocesses - #2
Open
herrsergio wants to merge 3 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
osascript) for iTerm2 color themingSessionEnd— now only cleared on explicit/skin reset--resetflag fromskin-command-hook.shtodeactivate.shto distinguish the two casesProblem
Claude Code hook subprocesses run without a TTY attached, breaking two standard approaches:
/dev/tty— not available in hook subprocesses (Device not configured)ESCbyte before output reaches the terminal emulator, so sequences arrive as plain text and are ignoredSolution
osascriptcommunicates with iTerm2 via Apple Events, bypassing the PTY entirely. It works from any subprocess regardless of TTY availability and applies full color control: background, foreground, cursor, and the complete ANSI 0–7 palette.iTerm2's AppleScript API uses 16-bit color values (0–65535). Hex colors convert as
channel × 257.On non-iTerm2 terminals all
osascriptcalls fail silently (2>/dev/null || true) — no errors, no color changes.Files changed
engine/activate.sh— replace OSC block withhex_to_16bit+iterm_set_colorhelpers using AppleScriptengine/deactivate.sh— replace OSC reset block with AppleScript; only writedefaulttocurrentwhen--resetflag is passedengine/skin-command-hook.sh— pass--resettodeactivate.shon/skin resetTesting
/skin mythos— background should shift to deep navy (#0D1B3D) immediately/skin retro86— background should shift to deep purple (#40318D)/skin reset— background should restore to blackTo test the no-TTY path directly:
osascript -e 'tell application "iTerm2" to tell current session of current window to set background color to {13107, 27499, 61166}'Known limitations