feat(install): merge user settings and turn off bundled skills

Copying the repo's settings.json over ~/.claude/settings.json would delete
most of the operator's settings, so the installer now merges it. The merge
and the new settings land together, so no overwriting installer ever
deploys them.

The merge runs before any other file is deployed, so an invalid settings
file stops the install with nothing changed. It writes a complete temporary
file and renames it, so a failure cannot truncate the user's settings.

Impact: removing a setting from the repo no longer removes it from a
machine that already has it.

ADR: 0035
Refs: #280
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014uGZTNugst7K9Bd2FTR4Mi
This commit is contained in:
Defame1297andClaude Opus 5.5 committed 2026-12-04 19:48:53 +00:00
1 parent 0f2d9ede68
commit aa8319a1db
8 files changed
+191 -5

No files matched your search

+1
View File
@@ -36,6 +36,7 @@ git -C "$TEMP_REPO" init -q
cat > "$TEMP_REPO/scripts/deploy-manifest.sh" << 'EOF'
# shellcheck disable=SC2034
DEPLOY_FILES=()
DEPLOY_JSON_MERGES=()
DEPLOY_EXECUTABLES=()
DEPLOY_DIRS=()
EOF
+105
View File
@@ -74,6 +74,111 @@ else
fail "idempotent: ~/.agents/AGENTS.md corrupted after second install"
fi
SETTINGS_SRC="$REPO_ROOT/providers/claude-code/settings.json"
if cmp -s "$SETTINGS_SRC" "$TEMP_HOME/.claude/settings.json"; then
pass "idempotent: settings.json still identical to source after second install"
else
fail "idempotent: settings.json changed by second install"
fi
echo ""
echo "--- settings.json is merged into an existing file (ADR-0035) ---"
new_home() {
local home
home="$(mktemp -d "$TEMP_HOME/merge.XXXXXX")"
mkdir -p "$home/.claude"
echo "$home"
}
install_into() {
HOME="$1" bash "$REPO_ROOT/scripts/install.sh" 2>&1
}
# Asserts a Python expression over the parsed JSON file, bound to `s`.
check_json() {
local file="$1" expr="$2" name="$3"
if python3 -c 'import json, sys; s = json.load(open(sys.argv[1], encoding="utf-8")); sys.exit(not eval(sys.argv[2]))' "$file" "$expr" 2> /dev/null; then
pass "$name"
else
fail "$name"
fi
}
check_json "$SETTINGS_SRC" \
's["disableBundledSkills"] is True and s["syncClaudeAiSkills"] is False and s["env"]["CLAUDE_CODE_DISABLE_SHIP"] == "1" and s["skillOverrides"]["init"] == "off"' \
"repo settings turn off bundled and synced skills"
MERGE_HOME="$(new_home)"
MERGED="$MERGE_HOME/.claude/settings.json"
cat > "$MERGED" << 'EOF'
{
"model": "opus",
"theme": "light",
"permissions": {"allow": ["Bash(ls:*)"]},
"env": {"MY_VAR": "kept", "CLAUDE_CODE_DISABLE_SHIP": "0"},
"skillOverrides": {"other": "off", "init": "on"}
}
EOF
chmod 640 "$MERGED"
install_into "$MERGE_HOME" > /dev/null || fail "install over existing settings exited non-zero"
check_json "$MERGED" 's["model"] == "opus" and s["permissions"] == {"allow": ["Bash(ls:*)"]}' \
"top-level settings the repo does not set are kept"
check_json "$MERGED" 's["env"]["MY_VAR"] == "kept" and s["skillOverrides"]["other"] == "off"' \
"nested entries the repo does not set are kept"
check_json "$MERGED" 's["theme"] == "dark" and s["env"]["CLAUDE_CODE_DISABLE_SHIP"] == "1" and s["skillOverrides"]["init"] == "off"' \
"the repo's value wins where both set one"
check_json "$MERGED" 's["disableBundledSkills"] is True and s["syncClaudeAiSkills"] is False' \
"settings only the repo has are added"
if [[ "$(find "$MERGED" -perm 640)" == "$MERGED" ]]; then
pass "the existing file's permissions are kept"
else
fail "the existing file's permissions changed"
fi
cp "$MERGED" "$MERGE_HOME/first-run.json"
install_into "$MERGE_HOME" > /dev/null || fail "second install exited non-zero"
if cmp -s "$MERGE_HOME/first-run.json" "$MERGED"; then
pass "a second run leaves the merged settings unchanged"
else
fail "a second run changed the merged settings"
fi
for invalid in '{"model": "opus",' '["not an object"]' ''; do
BAD_HOME="$(new_home)"
BAD="$BAD_HOME/.claude/settings.json"
printf '%s' "$invalid" > "$BAD"
printf '%s' "$invalid" > "$BAD_HOME/before"
if output="$(install_into "$BAD_HOME")"; then
fail "install accepted invalid settings: '$invalid'"
elif [[ "$output" == *"$BAD"* && "$output" != *Traceback* ]]; then
pass "invalid settings exit non-zero with an error naming the file: '$invalid'"
else
fail "invalid settings gave no clear error: '$invalid'"
fi
if cmp -s "$BAD_HOME/before" "$BAD"; then
pass "invalid settings are left untouched: '$invalid'"
else
fail "invalid settings were changed: '$invalid'"
fi
done
LINK_HOME="$(new_home)"
mkdir "$LINK_HOME/dotfiles"
echo '{"model": "opus"}' > "$LINK_HOME/dotfiles/settings.json"
ln -s ../dotfiles/settings.json "$LINK_HOME/.claude/settings.json"
install_into "$LINK_HOME" > /dev/null || fail "install through a symlink exited non-zero"
if [[ -L "$LINK_HOME/.claude/settings.json" ]]; then
pass "a symlinked settings file stays a symlink"
else
fail "a symlinked settings file was replaced by a regular file"
fi
check_json "$LINK_HOME/dotfiles/settings.json" 's["model"] == "opus" and s["theme"] == "dark"' \
"the symlink's target receives the merge"
echo ""
echo "Results: $PASS passed, $FAIL failed"
[[ $FAIL -eq 0 ]]