@adithya-13/cc-switch 1.0.3 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/bin/cclaude.js +29 -9
  2. package/package.json +1 -1
package/bin/cclaude.js CHANGED
@@ -56,23 +56,43 @@ function notifyRateLimit(current, fallbacks) {
56
56
  const settings = readSettings();
57
57
  const current = getCurrentProvider(settings);
58
58
 
59
+ // OAuth mode (pro/claude) sends rate limit to stdout, API providers to stderr
60
+ const isOAuthMode = current === "pro" || current === "claude";
61
+
59
62
  const child = spawn("claude", process.argv.slice(2), {
60
- stdio: ["inherit", "inherit", "pipe"], // intercept stderr
63
+ stdio: ["inherit", isOAuthMode ? "pipe" : "inherit", "pipe"], // always pipe stderr
61
64
  });
62
65
 
63
- let stderrBuffer = "";
64
-
65
- child.stderr.on("data", (data) => {
66
- const text = data.toString();
67
- stderrBuffer += text;
68
- process.stderr.write(data); // still show to user
66
+ let notified = false;
69
67
 
70
- const isRateLimit = RATE_LIMIT_PATTERNS.some((p) => p.test(stderrBuffer));
68
+ function checkRateLimit(text) {
69
+ if (notified) return;
70
+ const isRateLimit = RATE_LIMIT_PATTERNS.some((p) => p.test(text));
71
71
  if (isRateLimit) {
72
72
  const fallbacks = getAvailableFallbacks(current);
73
73
  notifyRateLimit(current, fallbacks);
74
- stderrBuffer = ""; // reset to avoid re-triggering
74
+ notified = true; // only notify once
75
75
  }
76
+ }
77
+
78
+ // Only capture stdout for OAuth mode (pro/claude)
79
+ if (isOAuthMode) {
80
+ let buffer = "";
81
+ child.stdout.on("data", (data) => {
82
+ const text = data.toString();
83
+ buffer += text;
84
+ process.stdout.write(data); // forward to user
85
+ checkRateLimit(buffer);
86
+ });
87
+ }
88
+
89
+ // Always capture stderr for API providers' rate limit errors
90
+ let stderrBuffer = "";
91
+ child.stderr.on("data", (data) => {
92
+ const text = data.toString();
93
+ stderrBuffer += text;
94
+ process.stderr.write(data); // forward to user
95
+ checkRateLimit(stderrBuffer);
76
96
  });
77
97
 
78
98
  child.on("exit", (code) => process.exit(code ?? 0));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adithya-13/cc-switch",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "Switch Claude Code between providers (Claude Pro, z.ai, Kimi, OpenRouter, DeepSeek, and more)",
5
5
  "keywords": [
6
6
  "claude",