diff --git a/dotfiles/commonfunc b/dotfiles/commonfunc index e8ee8d3..20765ff 100644 --- a/dotfiles/commonfunc +++ b/dotfiles/commonfunc @@ -101,6 +101,60 @@ fabric() { fabric-ai ${@:-} } +####################################### +# Run Claude Code through the local Codex gateway with an interactively selected model. +# Globals: +# CLAUDE_CODEX_BASE_URL +# Arguments: +# Arguments to pass to claude +# Outputs: +# Model picker and output from claude +# Returns: +# Exit code from fzf, the model picker, or claude +####################################### +claude-codex() { + local gateway_url="${CLAUDE_CODEX_BASE_URL:-http://localhost:18765}" + local model + local -a models=() + local -a fallback_models=( + gpt-5.6-sol + gpt-5.6-terra + gpt-5.6-luna + ) + + if (( ${+commands[curl]} && ${+commands[jq]} )); then + models=(${(f)"$( + curl -fsS --max-time 2 "${gateway_url}/v1/models" 2>/dev/null | + jq -r '.data[] | select((.display_name // "") | endswith(" (codex)")) | .id' | + sort -u + )"}) + fi + + (( ${#models[@]} )) || models=("${fallback_models[@]}") + + if (( ${+commands[fzf]} )); then + model=$( + printf '%s\n' "${models[@]}" | + fzf --height=60% --reverse --prompt='Claude Codex model> ' + ) || return $? + else + local PS3='Claude Codex model: ' + select model in "${models[@]}"; do + [[ -n "${model}" ]] && break + print -u2 -- "Invalid selection." + done + fi + + ANTHROPIC_BASE_URL="${gateway_url}" \ + ANTHROPIC_AUTH_TOKEN=unused \ + ANTHROPIC_MODEL="${model}[1m]" \ + ANTHROPIC_SMALL_FAST_MODEL=gpt-5.6-luna[1m] \ + CLAUDE_CODE_AUTO_COMPACT_WINDOW=272000 \ + CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1 \ + CLAUDE_CODE_DISABLE_NONSTREAMING_FALLBACK=1 \ + command claude "$@" +} + ####################################### # wttr - show the weather forecast in Terminal. # Globals: diff --git a/dotfiles/zshrc b/dotfiles/zshrc index 89a97d3..a681b8f 100644 --- a/dotfiles/zshrc +++ b/dotfiles/zshrc @@ -202,14 +202,6 @@ alias yeet="git push" alias trust="yeet --force" alias zotify="uvx git+https://github.com/Googolplexed0/zotify.git" alias hosts="uvx git+https://git.s1q.dev/phg/hosts.git" -alias claude-codex='ANTHROPIC_BASE_URL=http://localhost:18765 - ANTHROPIC_AUTH_TOKEN=unused - ANTHROPIC_MODEL=gpt-5.6-sol[1m] - ANTHROPIC_SMALL_FAST_MODEL=gpt-5.6-luna[1m] - CLAUDE_CODE_AUTO_COMPACT_WINDOW=272000 - CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1 - CLAUDE_CODE_DISABLE_NONSTREAMING_FALLBACK=1 - claude' # Include $(go env GOPATH) to PATH [[ $(command -v go) ]] && [[ -d "$(go env GOPATH)/bin" ]] && export PATH="$(go env GOPATH)/bin:${PATH}"