diff --git a/bin/ultracode b/bin/ultracode index 858445d..dc83190 100755 --- a/bin/ultracode +++ b/bin/ultracode @@ -52,11 +52,37 @@ PORT="${UC_LISTEN_PORT:-$("$PY" -c 'import json,sys;c=json.load(open(sys.argv[1] UPSTREAM="${UC_UPSTREAM:-$("$PY" -c 'import json,sys;c=json.load(open(sys.argv[1]));print((c.get("proxy") or {}).get("anthropic_upstream") or "https://api.anthropic.com")' "$CONFIG" 2>/dev/null || echo https://api.anthropic.com)}" BASE_URL="http://127.0.0.1:${PORT}" +# 1M context window enablement ------------------------------------------------ +# Claude Code only switches its context meter AND auto-compaction to the 1M +# window (and sends the context-1m beta) when the model id carries the [1m] +# suffix. The selector and config advertise bare ids (e.g. claude-opus-4-8), so +# without this the client sizes context at 200k -- the meter fills ~5x too fast +# and pins at 100% -- even though Opus 4.8 / Sonnet 4.6 serve 1M natively. We +# append [1m] to 1M-capable Claude base ids before launch. Disable with +# UC_FORCE_1M=0; override the capable set with UC_1M_MODELS (comma-separated). +UC_FORCE_1M="${UC_FORCE_1M:-1}" +UC_1M_MODELS="${UC_1M_MODELS:-claude-opus-4-8,claude-opus-4-7,claude-opus-4-6,claude-sonnet-4-6}" +uc_add_1m() { + # Echo $1 with a [1m] suffix iff it is a bare, 1M-capable Claude id. Anything + # else (Auto Router, Gemini/GPT/Composer, Haiku, already-suffixed, empty) is + # passed through untouched. + local m="$1" id + if [[ "$UC_FORCE_1M" == "0" || -z "$m" || "$m" == *"[1m]"* ]]; then + printf '%s' "$m"; return + fi + IFS=',' read -ra _uc_1m_ids <<< "$UC_1M_MODELS" + for id in "${_uc_1m_ids[@]}"; do + if [[ "$m" == "$id" ]]; then printf '%s[1m]' "$m"; return; fi + done + printf '%s' "$m" +} +DEFAULT_MODEL="$(uc_add_1m "claude-opus-4-8")" + # Session settings (ultracode + discovery env). cat > "$SETTINGS" <