diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..eff19af --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +claude/.claude/settings.json filter=claude-settings diff --git a/CLAUDE.md b/CLAUDE.md index 1535aea..3ebfcb8 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -19,6 +19,18 @@ Personal dotfiles managed with GNU stow. Full details: README.md. `doctor.sh` detect it's missing. - The repo must stay cloned at `~/Development/dotfiles`; stow's symlinks are relative to that path. +- `claude/.claude/settings.json` is owned by Claude Code, which rewrites it on + every `/model` switch, so it's handled in two halves. `.gitattributes` runs it + through `claude-settings-clean.py` (drops the volatile keys, sorts the rest) + so commits only ever carry durable config; a new key Claude Code writes back + as state goes in that script's `VOLATILE`. The file is also marked + `skip-worktree`, because a clean filter alone doesn't quiet `git status` — + git's refresh path hashes the file raw. Both halves are per-clone index and + config state: `bootstrap.sh` sets them, `doctor.sh` checks them. +- To commit a deliberate change to that settings file, unhide it first: + `git update-index --no-skip-worktree claude/.claude/settings.json`, commit, + then re-hide with `--skip-worktree`. While it's hidden, git ignores every + local edit to it, including one you meant to keep. - Shell scripts: keep `shellcheck`-clean (`shellcheck bootstrap.sh doctor.sh lib.sh macos/*.sh`). diff --git a/bootstrap.sh b/bootstrap.sh index f9fcb63..5cb65c8 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -119,6 +119,14 @@ else sudo apt-get install -y git curl stow zsh tmux neovim xclip ripgrep fd-find fi +# ---- Register the Claude settings clean filter ---- +# .gitattributes names the filter; git only ever runs one it has been given a +# command for, so an unregistered clone silently commits the volatile keys. +echo ">>> Registering the Claude settings clean filter..." +cd "$DOTFILES_DIR" +git config "$CLAUDE_SETTINGS_FILTER" "$CLAUDE_SETTINGS_FILTER_CMD" +git update-index --skip-worktree "$CLAUDE_SETTINGS_FILE" + # ---- Init git submodules ---- echo ">>> Initializing git submodules..." cd "$DOTFILES_DIR" diff --git a/claude-settings-clean.py b/claude-settings-clean.py new file mode 100755 index 0000000..38fb3e6 --- /dev/null +++ b/claude-settings-clean.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 +"""Git clean filter for claude/.claude/settings.json. + +Claude Code owns that file: it rewrites the whole thing whenever a runtime +option changes (/model, the theme picker, sandbox toggles), so a stowed, +tracked copy is dirty again the moment you switch models. This strips the keys +Claude Code writes back as machine state and sorts what's left, leaving git to +see only the durable config — hooks, permissions, statusLine, plugins. + +Reads the working-tree file on stdin, writes the committed form on stdout. +Wired up by `git config filter.claude-settings.clean` in bootstrap.sh and +pointed at this file by .gitattributes. +""" + +import json +import sys + +# Written back by Claude Code itself; per-machine, never worth a commit. +VOLATILE = ("model", "theme", "sandbox", "modelSettings") + + +def main() -> None: + raw = sys.stdin.read() + try: + settings = json.loads(raw) + except ValueError: + # A half-written or hand-broken file still has to round-trip: a filter + # that errors here wedges every git command touching the file. + sys.stdout.write(raw) + return + + for key in VOLATILE: + settings.pop(key, None) + + # sort_keys because Claude Code's own key order isn't stable across + # versions — without it a rewrite alone shows up as a diff. + json.dump(settings, sys.stdout, indent=2, sort_keys=True) + sys.stdout.write("\n") + + +if __name__ == "__main__": + main() diff --git a/claude/.claude/settings.json b/claude/.claude/settings.json index f3a3973..730cd9e 100644 --- a/claude/.claude/settings.json +++ b/claude/.claude/settings.json @@ -1,45 +1,44 @@ { - "model": "sonnet", + "enabledPlugins": { + "claude-md-management@claude-plugins-official": true, + "code-review@claude-plugins-official": true, + "code-simplifier@claude-plugins-official": true, + "frontend-design@claude-plugins-official": true, + "ponytail@ponytail": true, + "security-guidance@claude-plugins-official": true, + "superpowers@claude-plugins-official": false, + "swift-lsp@claude-plugins-official": true + }, + "extraKnownMarketplaces": { + "ponytail": { + "source": { + "repo": "DietrichGebert/ponytail", + "source": "github" + } + } + }, "hooks": { "Notification": [ { - "matcher": "permission_prompt|agent_needs_input", "hooks": [ { - "type": "command", - "command": "command -v afplay >/dev/null && afplay /System/Library/Sounds/Glass.aiff || true" + "command": "command -v afplay >/dev/null && afplay /System/Library/Sounds/Glass.aiff || true", + "type": "command" } - ] + ], + "matcher": "permission_prompt|agent_needs_input" }, { - "matcher": "idle_prompt|agent_completed", "hooks": [ { - "type": "command", - "command": "command -v afplay >/dev/null && afplay /System/Library/Sounds/Pop.aiff || true" + "command": "command -v afplay >/dev/null && afplay /System/Library/Sounds/Pop.aiff || true", + "type": "command" } - ] + ], + "matcher": "idle_prompt|agent_completed" } ] }, - "enabledPlugins": { - "frontend-design@claude-plugins-official": true, - "superpowers@claude-plugins-official": false, - "code-review@claude-plugins-official": true, - "code-simplifier@claude-plugins-official": true, - "claude-md-management@claude-plugins-official": true, - "security-guidance@claude-plugins-official": true, - "swift-lsp@claude-plugins-official": true, - "ponytail@ponytail": true - }, - "extraKnownMarketplaces": { - "ponytail": { - "source": { - "source": "github", - "repo": "DietrichGebert/ponytail" - } - } - }, "permissions": { "deny": [ "Bash(rm -rf /)", @@ -56,8 +55,7 @@ ] }, "statusLine": { - "type": "command", - "command": "~/.claude/statusline.sh" - }, - "theme": "auto" + "command": "~/.claude/statusline.sh", + "type": "command" + } } diff --git a/doctor.sh b/doctor.sh index 0c7f768..4c5159c 100755 --- a/doctor.sh +++ b/doctor.sh @@ -134,6 +134,21 @@ else ok "submodules at recorded commits" fi +configured_filter="$(cd "$DOTFILES_DIR" && git config --get "$CLAUDE_SETTINGS_FILTER" 2>/dev/null)" +if [[ "$configured_filter" == "$CLAUDE_SETTINGS_FILTER_CMD" ]]; then + ok "Claude settings clean filter registered" +else + bad "Claude settings clean filter not registered" + hint "git -C $DOTFILES_DIR config $CLAUDE_SETTINGS_FILTER $CLAUDE_SETTINGS_FILTER_CMD" +fi + +if [[ "$(cd "$DOTFILES_DIR" && git ls-files -v "$CLAUDE_SETTINGS_FILE" 2>/dev/null)" == S* ]]; then + ok "Claude settings marked skip-worktree" +else + bad "Claude settings not marked skip-worktree" + hint "git -C $DOTFILES_DIR update-index --skip-worktree $CLAUDE_SETTINGS_FILE" +fi + if [[ -n "$(cd "$DOTFILES_DIR" && git status --porcelain 2>/dev/null)" ]]; then bad "working tree is dirty" hint "git -C $DOTFILES_DIR status" diff --git a/git/.gitignore b/git/.gitignore index 63465e3..4dd65e0 100644 --- a/git/.gitignore +++ b/git/.gitignore @@ -1,2 +1,4 @@ .DS_Store **/.claude/settings.local.json + +**/.claude/.cc-writes/ diff --git a/lib.sh b/lib.sh index 2fc1798..9ea9cb8 100644 --- a/lib.sh +++ b/lib.sh @@ -15,6 +15,18 @@ MACHINE_FILE="$DOTFILES_DIR/.machine" # Stow packages carrying no special options. STOW_PACKAGES=(zsh git tmux ghostty nvim base16 claude) +# Claude Code rewrites ~/.claude/settings.json whenever a runtime option +# changes, which dirties the stowed copy on every /model switch. .gitattributes +# routes the file through this clean filter so git only sees the durable config; +# the filter command itself lives in each clone's git config, set by bootstrap. +# The filter keeps volatile keys out of commits; git still reports the file as +# modified though, because its refresh path hashes the file raw and only the +# diff machinery applies the filter. skip-worktree is what actually silences +# that — see CLAUDE.md for how to commit a deliberate change to the file. +CLAUDE_SETTINGS_FILE="claude/.claude/settings.json" +CLAUDE_SETTINGS_FILTER="filter.claude-settings.clean" +CLAUDE_SETTINGS_FILTER_CMD="$DOTFILES_DIR/claude-settings-clean.py" + # ssh is stowed on its own: --no-folding keeps ~/.ssh a real directory holding a # symlinked config. Folded, ~/.ssh would itself be a symlink into this repo, and # every key or known_hosts file written there would land in the working tree.