Skip to content

Instantly share code, notes, and snippets.

@LeslieLeung
Created August 6, 2025 02:23
Show Gist options
  • Save LeslieLeung/46838a2009d35916392aab04613ed7a6 to your computer and use it in GitHub Desktop.
Save LeslieLeung/46838a2009d35916392aab04613ed7a6 to your computer and use it in GitHub Desktop.
function claude() {
# 定义不同服务的配置
local base_url=""
local auth_token=""
local api_key=""
local model=""
local small_fast_model=""
case "$1" in
"kimi")
base_url="https://api.moonshot.cn/anthropic"
auth_token="YOUR_AUTH_TOKEN"
model="kimi-k2-turbo-preview"
small_fast_model="kimi-k2-turbo-preview"
shift
;;
"aihubmix")
base_url="https://aihubmix.com"
api_key="YOUR_API_KEY"
shift
;;
"anthropic"|"")
# 默认或显式指定 anthropic
base_url="https://api.anthropic.com"
auth_token="YOUR_ANTHROPIC_API_TOKEN"
if [[ "$1" == "anthropic" ]]; then
shift
fi
;;
*)
# 如果第一个参数不在case里,那就是它原本的参数,照样运行
# 不设置任何环境变量,直接传递所有参数给claude命令
command claude "$@"
return 0
;;
esac
# 构建环境变量字符串
local env_vars=""
# 设置基础URL
if [[ -n "$base_url" ]]; then
env_vars="$env_vars ANTHROPIC_BASE_URL=\"$base_url\""
fi
# 设置认证token
if [[ -n "$auth_token" ]]; then
env_vars="$env_vars ANTHROPIC_AUTH_TOKEN=\"$auth_token\""
fi
# 设置API key
if [[ -n "$api_key" ]]; then
env_vars="$env_vars ANTHROPIC_API_KEY=\"$api_key\""
fi
# 设置model环境变量
if [[ -n "$model" ]]; then
env_vars="$env_vars ANTHROPIC_MODEL=\"$model\""
fi
# 设置small_fast_model环境变量
if [[ -n "$small_fast_model" ]]; then
env_vars="$env_vars ANTHROPIC_SMALL_FAST_MODEL=\"$small_fast_model\""
fi
# 设置环境变量并调用实际的 claude 命令
if [[ -n "$env_vars" ]]; then
eval "$env_vars command claude \"\$@\""
else
command claude "$@"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment