34 lines
1.0 KiB
Python
Executable File
34 lines
1.0 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""Git's clean filter for settings.json: drop "model" and sort every key.
|
|
|
|
Claude Code rewrites settings.json, in its own key order, whenever a model is
|
|
picked or a plugin installed. Each machine owns its model, so neither the
|
|
model nor Claude Code's key order reaches a commit.
|
|
"""
|
|
import json
|
|
import sys
|
|
|
|
|
|
def cleaned(settings: dict[str, object]) -> str:
|
|
"""settings.json as git stores it: without "model", every key sorted."""
|
|
kept = {key: value for key, value in settings.items() if key != "model"}
|
|
return json.dumps(kept, ensure_ascii=False, indent=2, sort_keys=True) + "\n"
|
|
|
|
|
|
def main() -> int:
|
|
# On a non-zero exit git warns and stores the file as written.
|
|
try:
|
|
settings = json.loads(sys.stdin.read())
|
|
except ValueError as error:
|
|
print(f"settings_filter.py: {error}", file=sys.stderr)
|
|
return 1
|
|
if not isinstance(settings, dict):
|
|
print("settings_filter.py: settings.json holds no JSON object", file=sys.stderr)
|
|
return 1
|
|
sys.stdout.write(cleaned(settings))
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|