@adithya-13/cc-switch 1.0.4 → 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.
- package/bin/cclaude.js +18 -10
- package/package.json +1 -1
package/bin/cclaude.js
CHANGED
|
@@ -56,11 +56,13 @@ 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", "pipe", "pipe"], //
|
|
63
|
+
stdio: ["inherit", isOAuthMode ? "pipe" : "inherit", "pipe"], // always pipe stderr
|
|
61
64
|
});
|
|
62
65
|
|
|
63
|
-
let combinedBuffer = "";
|
|
64
66
|
let notified = false;
|
|
65
67
|
|
|
66
68
|
function checkRateLimit(text) {
|
|
@@ -73,18 +75,24 @@ function checkRateLimit(text) {
|
|
|
73
75
|
}
|
|
74
76
|
}
|
|
75
77
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
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
|
+
}
|
|
82
88
|
|
|
89
|
+
// Always capture stderr for API providers' rate limit errors
|
|
90
|
+
let stderrBuffer = "";
|
|
83
91
|
child.stderr.on("data", (data) => {
|
|
84
92
|
const text = data.toString();
|
|
85
|
-
|
|
93
|
+
stderrBuffer += text;
|
|
86
94
|
process.stderr.write(data); // forward to user
|
|
87
|
-
checkRateLimit(
|
|
95
|
+
checkRateLimit(stderrBuffer);
|
|
88
96
|
});
|
|
89
97
|
|
|
90
98
|
child.on("exit", (code) => process.exit(code ?? 0));
|