Last active
August 17, 2025 12:37
-
-
Save christiangenco/042f26297ce2650d4c5b3ea4d3f6c7ac to your computer and use it in GitHub Desktop.
Claude code automatic dark/light mode theme switching
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
#!/bin/bash | |
# Check if macOS is in dark mode | |
# Returns "Dark" if dark mode is on, nothing if light mode | |
DARK_MODE=$(defaults read -g AppleInterfaceStyle 2>/dev/null) | |
# Path to the active color config file | |
COLOR_FILE="$HOME/.config/alacritty/color.toml" | |
if [ "$DARK_MODE" = "Dark" ]; then | |
# Copy dark theme | |
cat > "$COLOR_FILE" << 'EOF' | |
# Active theme: Solarized Dark | |
[colors.primary] | |
background = "#002b36" | |
foreground = "#839496" | |
[colors.normal] | |
black = "#073642" | |
red = "#dc322f" | |
green = "#859900" | |
yellow = "#b58900" | |
blue = "#268bd2" | |
magenta = "#d33682" | |
cyan = "#2aa198" | |
white = "#eee8d5" | |
[colors.bright] | |
black = "#002b36" | |
red = "#cb4b16" | |
green = "#586e75" | |
yellow = "#657b83" | |
blue = "#839496" | |
magenta = "#6c71c4" | |
cyan = "#93a1a1" | |
white = "#fdf6e3" | |
EOF | |
echo "Switched to dark theme" | |
# Update tmux theme for dark mode | |
tmux set-option -g status-style "fg=colour15,bg=colour0" 2>/dev/null || true | |
else | |
# Copy light theme | |
cat > "$COLOR_FILE" << 'EOF' | |
# Active theme: Solarized Light | |
[colors.primary] | |
background = "#fdf6e3" | |
foreground = "#657b83" | |
[colors.normal] | |
black = "#073642" | |
red = "#dc322f" | |
green = "#859900" | |
yellow = "#b58900" | |
blue = "#268bd2" | |
magenta = "#d33682" | |
cyan = "#2aa198" | |
white = "#eee8d5" | |
[colors.bright] | |
black = "#002b36" | |
red = "#cb4b16" | |
green = "#586e75" | |
yellow = "#657b83" | |
blue = "#839496" | |
magenta = "#6c71c4" | |
cyan = "#93a1a1" | |
white = "#fdf6e3" | |
EOF | |
echo "Switched to light theme" | |
# Update tmux theme for light mode | |
tmux set-option -g status-style "fg=colour0,bg=colour7" 2>/dev/null || true | |
fi | |
# Touch the main config to trigger reload | |
touch "$HOME/.config/alacritty/alacritty.toml" | |
# include this in your alacrity.toml: | |
# [general] | |
# import = [ | |
# "~/.config/alacritty/color.toml" | |
# ] |
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
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
<plist version="1.0"> | |
<dict> | |
<key>Label</key> | |
<string>com.dark-mode-theme-switcher</string> | |
<key>ProgramArguments</key> | |
<array> | |
<string>/Users/cgenco/.config/alacritty/theme-watcher.swift</string> | |
</array> | |
<key>KeepAlive</key> | |
<true/> | |
<key>RunAtLoad</key> | |
<true/> | |
<key>StandardErrorPath</key> | |
<string>/tmp/dark-mode-theme-switcher.err</string> | |
<key>StandardOutPath</key> | |
<string>/tmp/dark-mode-theme-switcher.out</string> | |
</dict> | |
</plist> |
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
#!/usr/bin/swift | |
import Foundation | |
let scriptPath = "/Users/cgenco/.config/alacritty/dark-mode-theme-switcher.sh" | |
// Run the script once on start | |
Process.launchedProcess(launchPath: "/bin/bash", arguments: [scriptPath]) | |
// Listen for appearance changes | |
DistributedNotificationCenter.default.addObserver( | |
forName: NSNotification.Name("AppleInterfaceThemeChangedNotification"), | |
object: nil, | |
queue: nil | |
) { _ in | |
Process.launchedProcess(launchPath: "/bin/bash", arguments: [scriptPath]) | |
} | |
// Keep the script running | |
RunLoop.main.run() |
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
#!/bin/bash | |
# Get the current macOS appearance | |
APPEARANCE=$(defaults read -g AppleInterfaceStyle 2>/dev/null) | |
CLAUDE_SETTINGS="$HOME/.claude/settings.json" | |
# Determine which theme to use | |
if [[ "$APPEARANCE" == "Dark" ]]; then | |
CLAUDE_THEME="dark" | |
else | |
# Light mode (or if AppleInterfaceStyle is not set) | |
CLAUDE_THEME="light" | |
fi | |
# Update Claude Code theme | |
if [ -f "$CLAUDE_SETTINGS" ]; then | |
# Use jq to update the theme | |
if command -v jq &> /dev/null; then | |
jq --arg theme "$CLAUDE_THEME" '. + {theme: $theme}' "$CLAUDE_SETTINGS" > "$CLAUDE_SETTINGS.tmp" && \ | |
mv "$CLAUDE_SETTINGS.tmp" "$CLAUDE_SETTINGS" | |
echo "Claude Code switched to $CLAUDE_THEME mode" | |
else | |
echo "Error: jq is required but not installed. Install with: brew install jq" | |
exit 1 | |
fi | |
else | |
# Create settings file with theme if it doesn't exist | |
echo "{\"theme\": \"$CLAUDE_THEME\"}" > "$CLAUDE_SETTINGS" | |
echo "Created Claude settings with $CLAUDE_THEME mode" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment