Skip to content

Instantly share code, notes, and snippets.

@charlesteh
Created October 13, 2025 07:19
Show Gist options
  • Save charlesteh/bbb9cca4823963ee34876cc3d4a38047 to your computer and use it in GitHub Desktop.
Save charlesteh/bbb9cca4823963ee34876cc3d4a38047 to your computer and use it in GitHub Desktop.
z.ai script
#!/usr/bin/env bash
# zai.sh — load Anthropic API vars and run Claude if ready
# Usage: $ source zai.sh
# Note: sh zai.sh or ./zai.sh doesn't work, only source inherits PATH
# Installation: ensure your .env is set with:
# ANTHROPIC_BASE_URL=https://api.z.ai/api/anthropic
# ANTHROPIC_AUTH_TOKEN=(get your api token from z.ai)
# --- Load from .env if it exists ---
if [[ -f .env ]]; then
while IFS='=' read -r key value; do
# Skip empty lines and comments
[[ -z "$key" || "$key" =~ ^# ]] && continue
# Trim quotes
value="${value%\"}"
value="${value#\"}"
case "$key" in
ANTHROPIC_BASE_URL)
[[ -n "$value" ]] && export ANTHROPIC_BASE_URL="$value"
;;
ANTHROPIC_AUTH_TOKEN)
[[ -n "$value" ]] && export ANTHROPIC_AUTH_TOKEN="$value"
;;
esac
done < .env
else
echo "⚠️ No .env file found"
fi
# --- Validate required environment variables ---
if [[ -n "${ANTHROPIC_BASE_URL:-}" && -n "${ANTHROPIC_AUTH_TOKEN:-}" ]]; then
echo "✅ Environment found. Running Claude..."
claude
else
echo "❌ Missing required environment variables."
echo "👉 Make sure .env is set with:"
echo " ANTHROPIC_BASE_URL and ANTHROPIC_AUTH_TOKEN"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment