Skip to content

Commit ee9caf6

Browse files
authored
Show every model in the /model picker via gateway discovery (#9)
Background research (docs/research/2026-08-20-model-picker.md) found Claude Code's supported mechanism: CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1 fetches {base}/v1/models at startup and adds rows labeled "From gateway" — keeping only ids containing claude|anthropic. So: - Each GPT model gets a second alias, anthropic-compat/<id>, which passes the filter with a readable name; the alias IS the inference mapping, so picking the row just works. - The launcher exports the discovery flag on the proxy route. - claude-code.disable-cloaking-model-list: true in the proxy config — without it CLIProxyAPI serves the picker REVERSED pseudo-claude ids (claude-fable-5-dd-los-6.5-tpg), which is its own filter workaround and reads as gibberish. - That option needs a recent CLIProxyAPI, so the installer feature-detects it on the binary (strings | grep) and upgrades/downloads when absent. The feature gate initially failed on success: grep -q exits at first match, strings dies of SIGPIPE, pipefail turns that into failure — the same class as the json extractors. Guarded the same way, with a regression test. Verified live on a fresh reinstall: 12 picker rows cached (4 claude + 8 anthropic-compat/gpt), inference on plain and prefixed ids, claude direct.
1 parent bab94b0 commit ee9caf6

5 files changed

Lines changed: 75 additions & 13 deletions

File tree

‎install.ps1‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,10 @@ if ($ProxyBin) {
386386
$yaml += ' allow-remote: false'
387387
$yaml += ' disable-control-panel: true'
388388
$yaml += 'debug: false'
389+
$yaml += '# Model-list cloaking would rewrite ids into reversed pseudo-claude names;'
390+
$yaml += '# our anthropic-compat/ aliases pass the picker filter with readable names.'
391+
$yaml += 'claude-code:'
392+
$yaml += ' disable-cloaking-model-list: true'
389393
$yaml += 'claude-api-key:'
390394
$yaml += " - api-key: `"$ApiKey`""
391395
$yaml += " base-url: `"$GatewayUrl`""
@@ -401,8 +405,12 @@ if ($ProxyBin) {
401405
$yaml += " - api-key: `"$ApiKey`""
402406
$yaml += ' models:'
403407
foreach ($gm in $gptModels) {
408+
# Plain alias for the command line, prefixed alias so the /model
409+
# picker's discovery filter (claude|anthropic substring) shows it.
404410
$yaml += " - name: `"$gm`""
405411
$yaml += " alias: `"$gm`""
412+
$yaml += " - name: `"$gm`""
413+
$yaml += " alias: `"anthropic-compat/$gm`""
406414
}
407415
Write-RawText (Join-Path $HomeDir 'proxy-config.yaml') (($yaml -join "`n") + "`n")
408416
New-Item -ItemType Directory -Force -Path (Join-Path $HomeDir 'proxy-auth') | Out-Null

‎install.sh‎

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -443,17 +443,38 @@ ok "statusline installed to $HOME_DIR/statusline.sh"
443443
# Non-fatal throughout: Claude models work without any of this. If a step
444444
# fails, the install continues and `qbraid-code --model gpt-*` explains itself.
445445
say "GPT models"
446+
447+
# The /model picker integration needs `claude-code.disable-cloaking-model-list`
448+
# (CLIProxyAPI >= 7.2.135-ish); an older binary would show the picker reversed
449+
# pseudo-model gibberish. Feature-detect on the binary itself, not a version
450+
# number.
451+
proxy_supports_picker() {
452+
# grep -q exits at the first match, strings then dies of SIGPIPE, and
453+
# pipefail would turn that into failure-on-success. Same class of bug as
454+
# the json extractors; same cure.
455+
(
456+
set +o pipefail
457+
strings "$1" 2>/dev/null | grep -q "disable-cloaking-model-list"
458+
)
459+
}
460+
446461
PROXY_BIN=""
447-
if command -v cliproxyapi >/dev/null 2>&1; then
448-
PROXY_BIN="$(command -v cliproxyapi)"
449-
ok "using existing $PROXY_BIN"
450-
elif [ -x "$HOME_DIR/cliproxyapi" ]; then
451-
PROXY_BIN="$HOME_DIR/cliproxyapi"
452-
ok "using existing $PROXY_BIN"
453-
elif [ "$OS" = darwin ] && command -v brew >/dev/null 2>&1; then
454-
if brew install cliproxyapi >/dev/null 2>&1; then
455-
PROXY_BIN="$(command -v cliproxyapi)"
456-
ok "proxy installed via Homebrew"
462+
for cand in "$(command -v cliproxyapi 2>/dev/null || true)" "$HOME_DIR/cliproxyapi"; do
463+
[ -n "$cand" ] && [ -x "$cand" ] || continue
464+
if proxy_supports_picker "$cand"; then
465+
PROXY_BIN="$cand"
466+
ok "using existing $PROXY_BIN"
467+
break
468+
fi
469+
warn "$cand is too old for the /model picker — upgrading"
470+
done
471+
if [ -z "$PROXY_BIN" ] && [ "$OS" = darwin ] && command -v brew >/dev/null 2>&1; then
472+
if brew install cliproxyapi >/dev/null 2>&1 || brew upgrade cliproxyapi >/dev/null 2>&1; then
473+
CAND="$(command -v cliproxyapi 2>/dev/null || true)"
474+
if [ -n "$CAND" ] && proxy_supports_picker "$CAND"; then
475+
PROXY_BIN="$CAND"
476+
ok "proxy installed via Homebrew"
477+
fi
457478
fi
458479
fi
459480
if [ -z "$PROXY_BIN" ]; then
@@ -465,7 +486,8 @@ if [ -z "$PROXY_BIN" ]; then
465486
PROXY_URL="https://github.com/$PROXY_REPO/releases/download/$TAG/CLIProxyAPI_${VER}_${OS}_${PROXY_ARCH}.tar.gz"
466487
PROXY_TMP=$(mktemp -d)
467488
if curl -fsSL -m 120 -o "$PROXY_TMP/cpa.tar.gz" "$PROXY_URL" 2>/dev/null \
468-
&& tar xzf "$PROXY_TMP/cpa.tar.gz" -C "$PROXY_TMP" cli-proxy-api 2>/dev/null; then
489+
&& tar xzf "$PROXY_TMP/cpa.tar.gz" -C "$PROXY_TMP" cli-proxy-api 2>/dev/null \
490+
&& proxy_supports_picker "$PROXY_TMP/cli-proxy-api"; then
469491
install -m 0755 "$PROXY_TMP/cli-proxy-api" "$HOME_DIR/cliproxyapi"
470492
PROXY_BIN="$HOME_DIR/cliproxyapi"
471493
ok "proxy installed to $PROXY_BIN"
@@ -510,6 +532,11 @@ remote-management:
510532
allow-remote: false
511533
disable-control-panel: true
512534
debug: false
535+
# Model-list cloaking rewrites ids into reversed pseudo-claude names so they
536+
# pass Claude Code's discovery filter — the picker then shows gibberish. Our
537+
# anthropic-compat/ aliases pass the filter with readable names instead.
538+
claude-code:
539+
disable-cloaking-model-list: true
513540
claude-api-key:
514541
- api-key: "$API_KEY"
515542
base-url: "$GATEWAY_URL"
@@ -529,7 +556,13 @@ openai-compatibility:
529556
PEOF
530557
printf '%s\n' "$GPT_MODELS" | while IFS= read -r gm; do
531558
[ -n "$gm" ] || continue
559+
# Two aliases per GPT model: the plain id for the command line, and a
560+
# prefixed one containing "anthropic" so Claude Code's /model picker
561+
# discovery filter (which keeps only ids containing claude|anthropic)
562+
# shows it. The alias IS the inference mapping — selecting the
563+
# prefixed row routes to the same upstream model.
532564
printf ' - name: "%s"\n alias: "%s"\n' "$gm" "$gm"
565+
printf ' - name: "%s"\n alias: "anthropic-compat/%s"\n' "$gm" "$gm"
533566
done
534567
} > "$HOME_DIR/proxy-config.yaml"
535568
chmod 600 "$HOME_DIR/proxy-config.yaml"

‎qbraid-code‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,15 +204,19 @@ if [ -n "$PROXY_BIN" ] && [ -x "$PROXY_BIN" ] && [ -s "$HOME_DIR/proxy-config.ya
204204
if start_proxy; then
205205
RUN_BASE="$PROXY_URL"
206206
RUN_TOKEN=$(cat "$HOME_DIR/proxy.key")
207+
# Populate the /model picker from the proxy's model list. Claude Code
208+
# fetches {base}/v1/models at startup and shows rows labeled "From
209+
# gateway"; GPT models appear via their anthropic-compat/ aliases.
210+
export CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1
207211
else
208212
case "$RUN_MODEL" in
209-
gpt-*) exit 1 ;; # start_proxy already explained
213+
gpt-*|*/gpt-*) exit 1 ;; # start_proxy already explained
210214
*) echo "qbraid-code: proxy unavailable — using the gateway directly (Claude models only)." >&2 ;;
211215
esac
212216
fi
213217
else
214218
case "$RUN_MODEL" in
215-
gpt-*)
219+
gpt-*|*/gpt-*)
216220
echo "qbraid-code: GPT models need the local proxy, which is not installed." >&2
217221
echo "Re-run the installer: curl -fsSL https://qbraid.com/code.sh | bash" >&2
218222
exit 1 ;;

‎qbraid-code.cmd‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ powershell -NoProfile -ExecutionPolicy Bypass -File "%QC_HOME%\qbraid-proxy.ps1"
6363
if errorlevel 1 goto :noproxy
6464
set /p RUNTOKEN=<"%QC_HOME%\proxy.key"
6565
set "RUNBASE=http://127.0.0.1:8320"
66+
rem Populate the /model picker from the proxy's model list at startup.
67+
set "CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1"
6668
goto :routed
6769
:noproxy
6870
if /i "%RUNMODEL:~0,4%"=="gpt-" (

‎tests/extractors.sh‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,20 @@ check "json_num still extracts a present number" \
5252
check "json_str on an empty body survives set -e" \
5353
"x=\$(json_str '' name); [ -z \"\$x\" ]"
5454

55+
# proxy_supports_picker: grep -q + pipefail must not fail on success.
56+
FN2=$(awk '/^proxy_supports_picker\(\) \{/{f=1} f{print} f&&/^\}$/{exit}' install.sh)
57+
if [ -n "$FN2" ] && bash -c "set -euo pipefail; $FN2; proxy_supports_picker /bin/ls || true; exit 0"; then
58+
# positive case: a file that certainly contains the marker
59+
tmpbin=$(mktemp); printf 'xx disable-cloaking-model-list yy' > "$tmpbin"
60+
if bash -c "set -euo pipefail; $FN2; proxy_supports_picker '$tmpbin'"; then
61+
pass=$((pass + 1)); printf ' ok proxy_supports_picker survives pipefail\n'
62+
else
63+
fail=$((fail + 1)); printf ' FAIL proxy_supports_picker false-negative under pipefail\n'
64+
fi
65+
rm -f "$tmpbin"
66+
else
67+
fail=$((fail + 1)); printf ' FAIL proxy_supports_picker extraction or negative case\n'
68+
fi
69+
5570
printf '\n%d passed, %d failed\n' "$pass" "$fail"
5671
[ "$fail" -eq 0 ]

0 commit comments

Comments
 (0)