Files
omarchycn/bin/omarchy-theme-set-claude
19144983e5 Sync Omarchy themes to Claude Code (#6480)
* Sync Omarchy themes to Claude Code

Claude Code 2.1.118 added custom themes as JSON files in
~/.claude/themes, watched and hot-reloaded, so this follows the same
shape as the Pi integration (da53c0ff, bin/omarchy-theme-set-pi).

A claude.json template renders from each theme's colors.toml — no
per-theme files, so every stock and community theme is covered — and
omarchy-theme-set-claude copies the result into
~/.claude/themes/omarchy.json on theme switch, retinting running
sessions without a restart.

The theme just appears as "Omarchy" in the /theme picker, and picking
it once (or running omarchy-theme-set-claude --activate) makes every
future theme switch carry Claude Code along. No ~/.claude directory,
no-op.

* Respect custom Claude config directory

---------

Co-authored-by: David Heinemeier Hansson <david@hey.com>
2026-08-01 13:06:19 -05:00

75 lines
1.6 KiB
Bash
Executable File

#!/bin/bash
# omarchy:summary=Sync the generated Omarchy theme to Claude Code
# omarchy:args=[--activate]
# omarchy:hidden=true
set -euo pipefail
CLAUDE_SOURCE_PATH="$HOME/.local/state/omarchy/current/theme/claude.json"
CLAUDE_CONFIG_DIR="${CLAUDE_CONFIG_DIR:-$HOME/.claude}"
CLAUDE_THEME_PATH="$CLAUDE_CONFIG_DIR/themes/omarchy.json"
CLAUDE_SETTINGS_PATH="$CLAUDE_CONFIG_DIR/settings.json"
CLAUDE_ACTIVATE=0
usage() {
echo "Usage: omarchy-theme-set-claude [--activate]"
}
for arg in "$@"; do
case "$arg" in
--activate)
CLAUDE_ACTIVATE=1
;;
-h | --help)
usage
exit 0
;;
*)
usage >&2
exit 1
;;
esac
done
if [[ ! -f $CLAUDE_SOURCE_PATH ]]; then
if (( CLAUDE_ACTIVATE == 1 )); then
echo "Claude Code theme source missing: $CLAUDE_SOURCE_PATH" >&2
echo "Run omarchy-theme-refresh after selecting an Omarchy theme." >&2
exit 1
fi
exit 0
fi
if (( CLAUDE_ACTIVATE == 0 )) && [[ ! -d $CLAUDE_CONFIG_DIR ]]; then
exit 0
fi
write_setting_theme() {
local tmp
if [[ -f $CLAUDE_SETTINGS_PATH ]]; then
tmp=$(mktemp "$CLAUDE_SETTINGS_PATH.XXXXXX")
jq '.theme = "custom:omarchy"' "$CLAUDE_SETTINGS_PATH" >"$tmp"
mv "$tmp" "$CLAUDE_SETTINGS_PATH"
else
cat >"$CLAUDE_SETTINGS_PATH" <<EOF
{
"theme": "custom:omarchy"
}
EOF
fi
}
# Claude Code watches ~/.claude/themes and hot-reloads the file on change,
# so running sessions retint without a restart.
mkdir -p "$(dirname "$CLAUDE_THEME_PATH")"
tmp=$(mktemp "$CLAUDE_THEME_PATH.XXXXXX")
cp "$CLAUDE_SOURCE_PATH" "$tmp"
mv "$tmp" "$CLAUDE_THEME_PATH"
if (( CLAUDE_ACTIVATE == 1 )); then
write_setting_theme
fi