Skip to content

Commit 3f8411d

Browse files
committed
Release 2.0.8
1 parent a401d22 commit 3f8411d

File tree

9 files changed

+151
-23
lines changed

9 files changed

+151
-23
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 2.0.8
4+
- GLM setup now installs direct z.ai `glm` wrapper by default and keeps `glm-ccr` for router usage.
5+
- Safer `.env` loading in `ccc` (ignores comments/invalid lines) and updated setup docs.
6+
37
## 2.0.7
48
- Security: qs arrayLimit bypass fix (force qs 6.14.1).
59

NPM_README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,17 @@ CCR_CONFIG_OVERWRITE=1 ccr-setup
2626
ccr-setup --overwrite
2727
```
2828

29-
### One-shot GLM setup (Claude login + GLM API)
29+
### One-shot GLM setup (z.ai GLM API)
3030

3131
```bash
3232
npx -y -p @halilertekin/claude-code-router-config ccr-glm-setup --key "YOUR_GLM_API_KEY"
3333
source ~/.zshrc
3434
glm
3535
```
36+
Direct z.ai is the default. If you want the router version:
37+
```bash
38+
glm-ccr
39+
```
3640

3741
## Features
3842

@@ -82,8 +86,10 @@ After installation:
8286

8387
2. **Add to shell** (`~/.zshrc` or `~/.bashrc`):
8488
```bash
85-
# Load .env variables
86-
export $(cat ~/.env | xargs)
89+
# Load .env variables (safe with comments)
90+
set -a
91+
source ~/.env
92+
set +a
8793

8894
# Router connection
8995
export ANTHROPIC_BASE_URL="http://127.0.0.1:3456"

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
# Claude Code Router Config - Advanced Multi-Provider Setup
22

3-
🚀 **v2.0.7** - Unified router + config package with z.ai (GLM 4.7) support, advanced CLI tools, analytics, smart routing, and configuration templates!
3+
🚀 **v2.0.8** - Unified router + config package with z.ai (GLM 4.7) support, advanced CLI tools, analytics, smart routing, and configuration templates!
44

55
Use Claude Code as a single interface to access multiple AI providers with intelligent routing for optimal performance, cost, and quality.
66

7-
## ✨ New in v2.0.7
7+
## ✨ New in v2.0.8
88
- UI üzerinden `.env` anahtarları ekleme/güncelleme (TR/NL).
99
- `~/.env` otomatik yükleme ile API anahtarlarının bulunması (CLI + health monitor).
1010
- **z.ai Support**: Native integration for GLM-4.7 via z.ai (PPInfra).
1111
- **Lightweight Mode**: New `ccc` function for zero-dependency routing.
12-
- **Direct GLM Alias**: Type `glm` to launch Claude Code with GLM-4.7 immediately.
12+
- **Direct GLM Alias**: `glm` now launches GLM-4.7 directly via z.ai; `glm-ccr` keeps router mode.
1313
- **Non-interactive install**: CI-friendly installer flags and env controls.
1414
- **Unified router**: Built-in router service, no external dependency required.
1515
- **UI refresh**: Daha sade ve responsive tasarım, TR/NL dil desteği.
@@ -40,7 +40,8 @@ If you just want to use the `ccc` command (Claude Code Commander) and `glm` alia
4040
4. **Reload & Run:**
4141
```bash
4242
source ~/.zshrc
43-
glm # Launches GLM-4.7 via z.ai
43+
glm # Launches GLM-4.7 via z.ai (direct)
44+
glm-ccr # Launches GLM-4.7 via local router
4445
ccc ds # Launches DeepSeek
4546
ccc claude # Launches Official Claude (Pro)
4647
```

cli/ccc.zsh

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,41 @@ ccc() {
88
shift 1 2>/dev/null
99
local extra_args=("$@")
1010

11-
# Load keys from multiple sources for redundancy
12-
[[ -f ~/.ccm_config ]] && source ~/.ccm_config 2>/dev/null
13-
[[ -f ~/.env ]] && source ~/.env 2>/dev/null
11+
load_env_file() {
12+
local env_file="$1"
13+
[[ -f "$env_file" ]] || return 0
14+
local line key val
15+
while IFS= read -r line || [[ -n "$line" ]]; do
16+
line="${line%$'\r'}"
17+
line="${line%%#*}"
18+
line="${line#"${line%%[![:space:]]*}"}"
19+
line="${line%"${line##*[![:space:]]}"}"
20+
[[ -z "$line" ]] && continue
21+
line="${line#export }"
22+
[[ "$line" == *"="* ]] || continue
23+
key="${line%%=*}"
24+
val="${line#*=}"
25+
key="${key#"${key%%[![:space:]]*}"}"
26+
key="${key%"${key##*[![:space:]]}"}"
27+
val="${val#"${val%%[![:space:]]*}"}"
28+
val="${val%"${val##*[![:space:]]}"}"
29+
if [[ ${#val} -ge 2 ]]; then
30+
if [[ "$val" == \"*\" && "$val" == *\" ]]; then
31+
val="${val:1:-1}"
32+
elif [[ "$val" == \'*\' && "$val" == *\' ]]; then
33+
val="${val:1:-1}"
34+
fi
35+
fi
36+
if [[ "$key" == [A-Za-z_][A-Za-z0-9_]* ]]; then
37+
export "$key=$val"
38+
fi
39+
done < "$env_file"
40+
}
41+
42+
# Load keys from multiple sources for redundancy (safe parser)
43+
load_env_file "$HOME/.ccm_config"
44+
load_env_file "$HOME/.env"
45+
load_env_file "$HOME/.claude-code-router/keys.env"
1446

1547
# 1. CLEANUP: Remove all env vars that might interfere with Claude Pro
1648
unset ANTHROPIC_BASE_URL ANTHROPIC_API_KEY ANTHROPIC_MODEL ANTHROPIC_AUTH_TOKEN API_TIMEOUT_MS
@@ -31,6 +63,13 @@ ccc() {
3163
export ANTHROPIC_DEFAULT_SONNET_MODEL="glm-4.7"
3264
export ANTHROPIC_DEFAULT_OPUS_MODEL="glm-4.7"
3365
export ANTHROPIC_DEFAULT_HAIKU_MODEL="glm-4.5-air"
66+
export ANTHROPIC_SMALL_FAST_MODEL="glm-4.5-air"
67+
export CLAUDE_CODE_SUBAGENT_MODEL="glm-4.7"
68+
69+
if [[ -z "$ANTHROPIC_API_KEY" ]]; then
70+
echo "GLM_API_KEY not set. Add it to ~/.env or ~/.claude-code-router/keys.env" >&2
71+
return 1
72+
fi
3473

3574
echo "🔄 Provider: z.ai (GLM 4.7)"
3675
;;

docs/HOMEBREW_SETUP.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,10 @@ The installer automatically creates configuration files and an `.env.example` fi
5757

5858
3. **Add to shell configuration:**
5959
```bash
60-
# Add to ~/.zshrc or ~/.bashrc
61-
export $(cat ~/.env | xargs)
60+
# Add to ~/.zshrc or ~/.bashrc (safe .env load)
61+
set -a
62+
source ~/.env
63+
set +a
6264
export ANTHROPIC_BASE_URL="http://127.0.0.1:3456"
6365
export NO_PROXY="127.0.0.1"
6466
```
@@ -139,7 +141,9 @@ The router automatically routes requests to the most appropriate provider based
139141
ls -la ~/.env
140142

141143
# Manually source environment
142-
export $(cat ~/.env | xargs)
144+
set -a
145+
source ~/.env
146+
set +a
143147
```
144148

145149
4. **Router Fails to Start**

docs/README_EN.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ chmod +x install.sh
3535
```bash
3636
./setup-glm.sh --key "YOUR_GLM_API_KEY"
3737
```
38+
Then run:
39+
```bash
40+
glm # direct z.ai
41+
glm-ccr # via local router
42+
```
3843

3944
## Manual Setup
4045

install.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,10 @@ async function showNextSteps() {
113113

114114
console.log('\n2. Add environment variables to your shell (~/.zshrc or ~/.bashrc):');
115115
console.log(chalk.cyan(`
116-
# Claude Code Router
117-
export $(cat ~/.env | xargs)
116+
# Claude Code Router (safe .env load)
117+
set -a
118+
source ~/.env
119+
set +a
118120
export ANTHROPIC_BASE_URL="http://127.0.0.1:3456"
119121
export NO_PROXY="127.0.0.1"
120122
`));

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@halilertekin/claude-code-router-config",
3-
"version": "2.0.7",
3+
"version": "2.0.8",
44
"description": "Multi-provider configuration for Claude Code Router with intent-based routing, advanced CLI tools, analytics, and smart routing. Setup OpenAI, Anthropic, Gemini, Qwen, GLM, OpenRouter, and GitHub Copilot with intelligent routing.",
55
"main": "install.js",
66
"bin": {

setup-glm.sh

Lines changed: 74 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ usage() {
2020
Usage: ./setup-glm.sh [--key <GLM_API_KEY>] [--skip-install] [--non-interactive]
2121
2222
Installs/updates CCR (if missing), writes GLM-only config,
23-
creates ~/.claude-code-router/keys.env, and installs a single
24-
command: glm (plus aliases ccc and claude-glm).
23+
creates ~/.claude-code-router/keys.env, and installs commands:
24+
glm (direct z.ai) + glm-ccr (router) + aliases ccc and claude-glm.
2525
2626
Options:
2727
--key <GLM_API_KEY> Provide GLM key non-interactively
@@ -221,10 +221,76 @@ fi
221221
222222
"$CLAUDE_BIN" "$@"
223223
EOS
224-
chmod +x "$BIN_DIR/ccr-glm"
225-
ln -sf "$BIN_DIR/ccr-glm" "$BIN_DIR/glm"
226-
ln -sf "$BIN_DIR/ccr-glm" "$BIN_DIR/ccc"
227-
ln -sf "$BIN_DIR/ccr-glm" "$BIN_DIR/claude-glm"
224+
cat > "$BIN_DIR/glm-zai" <<'EOS'
225+
#!/usr/bin/env bash
226+
set -euo pipefail
227+
228+
ROUTER_DIR="$HOME/.claude-code-router"
229+
KEYS_FILE="$ROUTER_DIR/keys.env"
230+
231+
load_keys() {
232+
if [[ -f "$KEYS_FILE" ]]; then
233+
while IFS= read -r line || [[ -n "$line" ]]; do
234+
line="${line%$'\r'}"
235+
line="${line%%#*}"
236+
line="$(echo "$line" | sed -E 's/^[[:space:]]*//; s/[[:space:]]*$//')"
237+
[[ -z "$line" ]] && continue
238+
if [[ "$line" =~ ^(export[[:space:]]+)?([A-Za-z_][A-Za-z0-9_]*)=(.*)$ ]]; then
239+
key="${BASH_REMATCH[2]}"
240+
val="${BASH_REMATCH[3]}"
241+
val="$(echo "$val" | sed -E 's/^[[:space:]]*//; s/[[:space:]]*$//')"
242+
if [[ ${#val} -ge 2 ]]; then
243+
if [[ "${val:0:1}" == "\"" && "${val: -1}" == "\"" ]]; then
244+
val="${val:1:-1}"
245+
elif [[ "${val:0:1}" == "'" && "${val: -1}" == "'" ]]; then
246+
val="${val:1:-1}"
247+
fi
248+
fi
249+
val="${val%$'\r'}"
250+
if [[ -n "$val" ]]; then
251+
export "$key=$val"
252+
fi
253+
fi
254+
done < "$KEYS_FILE"
255+
fi
256+
}
257+
258+
load_keys
259+
260+
if [[ -z "${GLM_API_KEY:-}" ]]; then
261+
echo "GLM_API_KEY not set. Add it to ~/.claude-code-router/keys.env" >&2
262+
exit 1
263+
fi
264+
265+
# Direct z.ai (Anthropic-compatible) - no router required.
266+
export ANTHROPIC_AUTH_TOKEN="${GLM_API_KEY}"
267+
export ANTHROPIC_API_KEY="${GLM_API_KEY}"
268+
export ANTHROPIC_BASE_URL="https://api.z.ai/api/anthropic"
269+
export API_TIMEOUT_MS="${API_TIMEOUT_MS:-3000000}"
270+
271+
export ANTHROPIC_MODEL="${ANTHROPIC_MODEL:-glm-4.7}"
272+
export ANTHROPIC_DEFAULT_OPUS_MODEL="${ANTHROPIC_DEFAULT_OPUS_MODEL:-glm-4.7}"
273+
export ANTHROPIC_DEFAULT_SONNET_MODEL="${ANTHROPIC_DEFAULT_SONNET_MODEL:-glm-4.7}"
274+
export ANTHROPIC_DEFAULT_HAIKU_MODEL="${ANTHROPIC_DEFAULT_HAIKU_MODEL:-glm-4.5-air}"
275+
export ANTHROPIC_SMALL_FAST_MODEL="${ANTHROPIC_SMALL_FAST_MODEL:-glm-4.5-air}"
276+
export CLAUDE_CODE_SUBAGENT_MODEL="${CLAUDE_CODE_SUBAGENT_MODEL:-glm-4.7}"
277+
278+
CLAUDE_BIN="$HOME/.claude/local/claude"
279+
if [[ ! -x "$CLAUDE_BIN" ]]; then
280+
CLAUDE_BIN="$(command -v claude || true)"
281+
fi
282+
if [[ -z "${CLAUDE_BIN:-}" ]]; then
283+
echo "claude binary not found. Install Claude Code first." >&2
284+
exit 1
285+
fi
286+
287+
"$CLAUDE_BIN" "$@"
288+
EOS
289+
chmod +x "$BIN_DIR/ccr-glm" "$BIN_DIR/glm-zai"
290+
ln -sf "$BIN_DIR/glm-zai" "$BIN_DIR/glm"
291+
ln -sf "$BIN_DIR/glm-zai" "$BIN_DIR/ccc"
292+
ln -sf "$BIN_DIR/glm-zai" "$BIN_DIR/claude-glm"
293+
ln -sf "$BIN_DIR/ccr-glm" "$BIN_DIR/glm-ccr"
228294
}
229295

230296
ensure_path() {
@@ -266,4 +332,5 @@ ensure_path
266332
echo ""
267333
echo "GLM setup complete."
268334
echo "Run: source ~/.zshrc"
269-
echo "Then: glm"
335+
echo "Then: glm # direct z.ai (recommended)"
336+
echo "Or: glm-ccr # via local router"

0 commit comments

Comments
 (0)