Skip to content

Commit 155b650

Browse files
committed
fix(claude-config): update config and sync script
1 parent 2453543 commit 155b650

File tree

2 files changed

+34
-10
lines changed

2 files changed

+34
-10
lines changed

scripts/config/claude_code_config.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@
3232
],
3333
"Router": {
3434
"default": "openrouter,qwen/qwen3-coder",
35-
"background": "openrouter,qwen/qwen3-coder",
36-
"think": "openrouter,kimi/kimi-k2",
37-
"longContext": "openrouter,google/gemini-2.5-flash",
35+
"background": "openrouter,google/gemini-2.5-flash",
36+
"think": "openrouter,deepseek/deepseek-r1",
37+
"longContext": "openrouter,kimi/kimi-k2",
3838
"longContextThreshold": 60000,
3939
"webSearch": "openrouter,mistralai/mistral-medium-3.1"
4040
}

scripts/sync/reverse_claude_config.py

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
def reverse_sync_config():
55
print("Starting reverse config sync...")
66

7-
# Source: the sanitized config in your project
7+
# Source: sanitized config in your project
88
project_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
99
source_path = os.path.join(project_dir, "config", "claude_code_config.json")
1010
print(f"Source config path: {source_path}")
1111

12-
# Target: the original config location on macOS
12+
# Target: original config location on macOS
1313
target_dir = os.path.expanduser("~/.claude-code-router")
1414
target_path = os.path.join(target_dir, "config.json")
1515
print(f"Target config path: {target_path}")
@@ -22,15 +22,39 @@ def reverse_sync_config():
2222
os.makedirs(target_dir, exist_ok=True)
2323

2424
# Read the sanitized config
25-
with open(source_path) as f:
25+
with open(source_path, 'r') as f:
2626
config = json.load(f)
2727

28-
# Write config back to original location
28+
# Restore API keys from environment variables
29+
openrouter_api_key = os.getenv("OPENROUTER_API_KEY")
30+
if not openrouter_api_key:
31+
print("Warning: OPENROUTER_API_KEY environment variable not set.")
32+
# Optionally fail fast if key is required
33+
# raise EnvironmentError("Missing OPENROUTER_API_KEY environment variable")
34+
35+
# Replace empty or placeholder API keys
36+
if "Providers" in config:
37+
restored = False
38+
for provider in config["Providers"]:
39+
if (
40+
"api_key" in provider
41+
and (not provider["api_key"] or provider["api_key"] == "REPLACE_WITH_OPENROUTER_API_KEY")
42+
):
43+
provider["api_key"] = openrouter_api_key
44+
if openrouter_api_key:
45+
print("Restored API key for provider.")
46+
restored = True
47+
else:
48+
print("No valid API key to restore.")
49+
if not restored:
50+
print("No API key needed restoration (already set or no match).")
51+
52+
# Write the restored config back to the original location
2953
print("Writing config back to original location...")
30-
with open(target_path, "w") as f:
54+
with open(target_path, 'w') as f:
3155
json.dump(config, f, indent=2)
3256

33-
print("Reverse config sync completed successfully")
57+
print("Reverse config sync completed successfully.")
3458

3559
if __name__ == "__main__":
36-
reverse_sync_config()
60+
reverse_sync_config()

0 commit comments

Comments
 (0)