#!/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")