33 lines
1012 B
Python
Executable File
33 lines
1012 B
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 git stores the
|
|
file without it, and neither write reaches a commit.
|
|
"""
|
|
import json
|
|
import sys
|
|
|
|
|
|
def cleaned(written: str) -> str:
|
|
"""settings.json as git stores it: without "model", every key sorted. ValueError where it holds no JSON object."""
|
|
settings = json.loads(written)
|
|
if not isinstance(settings, dict):
|
|
raise ValueError("settings.json holds no JSON object")
|
|
settings.pop("model", None)
|
|
return json.dumps(settings, 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:
|
|
sys.stdout.write(cleaned(sys.stdin.read()))
|
|
except ValueError as error:
|
|
print(f"settings_filter.py: {error}", file=sys.stderr)
|
|
return 1
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|