scripts/set_autocompact.sh (1096 bytes)
1 #!/bin/sh 2 # Set a 500k-token auto-compact threshold for Claude Code and Codex on this computer. 3 # Needs jq. Copilot CLI (hardcoded 95%) and Antigravity have no setting for it. 4 set -eu 5 TOKENS=500000 6 7 # Back up $1, replace it with $2, then commit and push it in its config repo. 8 save() { 9 if [ -f "$1" ]; then cp "$1" "$1.bak-autocompact"; fi 10 mv "$2" "$1" 11 dir=$(dirname "$1") 12 if [ -d "$dir/.git" ]; then 13 git -C "$dir" commit -qm "Set auto-compact threshold to $TOKENS tokens" -- "$(basename "$1")" || true 14 git -C "$dir" push -q || true 15 fi 16 echo "set: $1" 17 } 18 19 mkdir -p ~/.claude ~/.codex 20 21 f=~/.claude/settings.json 22 if [ ! -f "$f" ]; then echo '{}' > "$f"; fi 23 jq --indent 2 ".autoCompactWindow = $TOKENS" "$f" > "$f.tmp" 24 save "$f" "$f.tmp" 25 26 # Drop any old value, then put the key first so it stays out of every [table]. 27 f=~/.codex/config.toml 28 { 29 echo "model_auto_compact_token_limit = $TOKENS" 30 if [ -f "$f" ]; then grep -v '^model_auto_compact_token_limit[[:space:]]*=' "$f" || true; fi 31 } > "$f.tmp" 32 save "$f" "$f.tmp" 33 34 echo "blocked: Copilot CLI and Antigravity have no setting"