Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 108 additions & 0 deletions plugins/project-theme/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# Project Theme Plugin

Applies per-project theme settings from `.claude/settings.json` on session start.

## Problem

When working on multiple projects simultaneously, all Claude Code sessions look identical. You have to manually run `/theme` each time you switch projects.

## Solution

This plugin reads theme settings from your project's `.claude/settings.json` and automatically applies them when the session starts.

## Installation

```bash
/plugin install project-theme
```

Or for development:

```bash
claude --plugin-dir /path/to/project-theme
```

## Usage

Add a `theme` or `color` key to your project's `.claude/settings.json`:

```json
{
"theme": "pink"
}
```

Or use `.claude/settings.local.json` for local overrides:

```json
{
"theme": "dark"
}
```

## Supported Values

Any theme name supported by Claude Code's `/theme` command:

- `dark` (default)
- `light`
- `light-ansi`
- `dark-ansi`
- `pink`
- `blue`
- `green`
- `orange`
- `purple`
- `red`
- `yellow`
- Custom theme names from `~/.claude/themes/`

## Priority

Settings are loaded in this order (last wins):

1. `.claude/settings.json` (project)
2. `.claude/settings.local.json` (local override)

## Example Workflow

1. Create a project:
```bash
mkdir my-project && cd my-project
mkdir -p .claude
echo '{"theme": "pink"}' > .claude/settings.json
```

2. Start Claude Code:
```bash
claude
```

3. The pink theme is automatically applied!

## How It Works

The plugin uses a `SessionStart` hook that:

1. Reads `.claude/settings.json` or `.claude/settings.local.json`
2. Extracts the `theme` or `color` value
3. Outputs a theme command that Claude Code processes

## Limitations

- Requires Claude Code 2.1.119+ (when `/config` settings persistence was added)
- Theme is applied at session start; changing the file requires restarting
- The hook reads files using basic grep; complex JSON with nested objects may not parse correctly

## Contributing

Contributions welcome! Areas for improvement:

- Support JSON parsing for complex settings files
- Add OSC terminal background color support
- Watch for file changes and hot-reload themes
- Support theme inheritance from parent directories

## License

MIT
3 changes: 3 additions & 0 deletions plugins/project-theme/examples/.claude/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"theme": "pink"
}
43 changes: 43 additions & 0 deletions plugins/project-theme/hooks/apply-theme.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env bash
set -euo pipefail

# Apply per-project theme from .claude/settings.json
# Usage: Add "theme": "pink" or "color": "blue" to your project's .claude/settings.json

SETTINGS_FILE=".claude/settings.json"
SETTINGS_LOCAL_FILE=".claude/settings.local.json"

# Extract theme from JSON file using jq if available, else fallback to grep
extract_theme() {
local file="$1"
if [[ ! -f "$file" ]]; then
return
fi

if command -v jq &>/dev/null; then
# Use jq for proper JSON parsing
jq -r '.theme // .color // empty' "$file" 2>/dev/null || true
else
# Fallback to grep for simple cases
grep -o '"\(theme\|color\)"\s*:\s*"[^"]*"' "$file" 2>/dev/null | head -1 | sed 's/.*"\([^"]*\)"$/\1/' || true
fi
}

# Check for theme in settings files (local takes precedence)
THEME=""

if [[ -f "$SETTINGS_LOCAL_FILE" ]]; then
THEME=$(extract_theme "$SETTINGS_LOCAL_FILE")
fi

if [[ -z "$THEME" && -f "$SETTINGS_FILE" ]]; then
THEME=$(extract_theme "$SETTINGS_FILE")
fi

if [[ -n "$THEME" ]]; then
echo "Applying project theme: $THEME"
# Output JSON command for Claude Code to process
echo "{\"type\": \"theme\", \"theme\": \"$THEME\"}"
fi

exit 0
13 changes: 13 additions & 0 deletions plugins/project-theme/plugin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "project-theme",
"version": "0.1.0",
"description": "Applies per-project theme settings from .claude/settings.json",
"author": "12britz",
"hooks": [
{
"event": "SessionStart",
"script": "hooks/apply-theme.sh",
"description": "Apply project-specific theme on session start"
}
]
}