@adithya-13/cc-switch 1.0.3 → 1.0.4

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 +21 -9
  2. package/package.json +1 -1
package/bin/cclaude.js CHANGED
@@ -57,22 +57,34 @@ const settings = readSettings();
57
57
  const current = getCurrentProvider(settings);
58
58
 
59
59
  const child = spawn("claude", process.argv.slice(2), {
60
- stdio: ["inherit", "inherit", "pipe"], // intercept stderr
60
+ stdio: ["inherit", "pipe", "pipe"], // intercept both stdout and stderr
61
61
  });
62
62
 
63
- let stderrBuffer = "";
63
+ let combinedBuffer = "";
64
+ let notified = false;
64
65
 
65
- child.stderr.on("data", (data) => {
66
- const text = data.toString();
67
- stderrBuffer += text;
68
- process.stderr.write(data); // still show to user
69
-
70
- const isRateLimit = RATE_LIMIT_PATTERNS.some((p) => p.test(stderrBuffer));
66
+ function checkRateLimit(text) {
67
+ if (notified) return;
68
+ const isRateLimit = RATE_LIMIT_PATTERNS.some((p) => p.test(text));
71
69
  if (isRateLimit) {
72
70
  const fallbacks = getAvailableFallbacks(current);
73
71
  notifyRateLimit(current, fallbacks);
74
- stderrBuffer = ""; // reset to avoid re-triggering
72
+ notified = true; // only notify once
75
73
  }
74
+ }
75
+
76
+ child.stdout.on("data", (data) => {
77
+ const text = data.toString();
78
+ combinedBuffer += text;
79
+ process.stdout.write(data); // forward to user
80
+ checkRateLimit(combinedBuffer);
81
+ });
82
+
83
+ child.stderr.on("data", (data) => {
84
+ const text = data.toString();
85
+ combinedBuffer += text;
86
+ process.stderr.write(data); // forward to user
87
+ checkRateLimit(combinedBuffer);
76
88
  });
77
89
 
78
90
  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.4",
4
4
  "description": "Switch Claude Code between providers (Claude Pro, z.ai, Kimi, OpenRouter, DeepSeek, and more)",
5
5
  "keywords": [
6
6
  "claude",