dotfiles/home/dot_claude/modify_settings.json.tmpl
Felipe M. 6eed7af69f
Manage Claude Code settings and status line
The status line script was already in the repo but inert: chezmoi ignores source
paths beginning with a dot, so home/.claude/ was never part of the source state.
Moved to home/dot_claude/ with the executable_ attribute, since the statusLine
command is invoked directly and a 0644 file cannot run.

Settings are merged rather than replaced. Claude Code writes to settings.json
itself -- autoMode.environment is regenerated per machine and /config edits land
there -- so a managed file would revert its work on every apply. The keys we
assert live in .chezmoitemplates/claude-settings.json as plain JSON; the
modify_ script folds them in with jq's recursive merge, leaving unmanaged keys
intact at any depth.

Fixed a locale bug in the status line: under LC_NUMERIC=es_ES, printf rendered
the cost as "1,23" and rejected the rate-limit percentage outright with
"invalid number" on stderr. It now forces LC_NUMERIC=C.

jq is a hard dependency of both the status line and the settings merge, so it
joins the common group.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-18 14:36:44 +02:00

24 lines
871 B
Go Template
Executable file

#!/usr/bin/env bash
#
# chezmoi `modify_` script: the current ~/.claude/settings.json arrives on stdin
# and whatever this prints becomes the new file.
#
# The settings we assert live in .chezmoitemplates/claude-settings.json as plain
# JSON -- edit that file, not this one.
#
# They are MERGED into the existing file rather than replacing it, because
# Claude Code writes here too: autoMode.environment is regenerated per machine
# and /config edits land in this file. jq's `*` operator merges recursively, so
# nested objects survive; only the keys named in claude-settings.json are
# overwritten.
set -euo pipefail
managed=$(cat <<'MANAGED_SETTINGS_JSON'
{{ includeTemplate "claude-settings.json" . }}
MANAGED_SETTINGS_JSON
)
current="$(cat)"
[ -z "${current//[[:space:]]/}" ] && current='{}'
jq -s '.[0] * .[1]' <(printf '%s' "$current") <(printf '%s' "$managed")