claudish 7.19.0 → 7.19.1

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/dist/index.js +52 -19
  2. package/package.json +5 -5
package/dist/index.js CHANGED
@@ -651,7 +651,7 @@ var init_onepassword_config = __esm(() => {
651
651
  });
652
652
 
653
653
  // src/version.ts
654
- var VERSION = "7.19.0";
654
+ var VERSION = "7.19.1";
655
655
 
656
656
  // src/logger.ts
657
657
  var exports_logger = {};
@@ -31745,6 +31745,14 @@ var init_web_search_detector = __esm(() => {
31745
31745
  WEB_SEARCH_NAMES = new Set(["web_search", "brave_web_search", "tavily_search"]);
31746
31746
  });
31747
31747
 
31748
+ // src/handlers/shared/stream-parsers/message-start-usage.ts
31749
+ function messageStartUsage(priorInputTokens) {
31750
+ return {
31751
+ input_tokens: priorInputTokens && priorInputTokens > 0 ? priorInputTokens : 100,
31752
+ output_tokens: 1
31753
+ };
31754
+ }
31755
+
31748
31756
  // src/handlers/shared/stream-parsers/openai-sse.ts
31749
31757
  function validateToolArguments(toolName, argsStr, toolSchemas, textContent) {
31750
31758
  const result = validateAndRepairToolCall(toolName, argsStr, toolSchemas, textContent);
@@ -31774,7 +31782,7 @@ function createStreamingState() {
31774
31782
  accumulatedText: ""
31775
31783
  };
31776
31784
  }
31777
- function createStreamingResponseHandler(c, response, adapter, target, middlewareManager, onTokenUpdate, toolSchemas, toolNameMap) {
31785
+ function createStreamingResponseHandler(c, response, adapter, target, middlewareManager, onTokenUpdate, toolSchemas, toolNameMap, priorInputTokens) {
31778
31786
  log(`[Streaming] ===== HANDLER STARTED for ${target} =====`);
31779
31787
  let isClosed = false;
31780
31788
  let ping = null;
@@ -31803,7 +31811,7 @@ data: ${JSON.stringify(d)}
31803
31811
  model: target,
31804
31812
  stop_reason: null,
31805
31813
  stop_sequence: null,
31806
- usage: { input_tokens: 100, output_tokens: 1 }
31814
+ usage: messageStartUsage(priorInputTokens)
31807
31815
  }
31808
31816
  });
31809
31817
  send("ping", { type: "ping" });
@@ -31916,7 +31924,10 @@ data: ${JSON.stringify(d)}
31916
31924
  send("message_delta", {
31917
31925
  type: "message_delta",
31918
31926
  delta: { stop_reason: stopReason, stop_sequence: null },
31919
- usage: { output_tokens: state.usage?.completion_tokens || 0 }
31927
+ usage: {
31928
+ ...state.usage?.prompt_tokens ? { input_tokens: state.usage.prompt_tokens } : {},
31929
+ output_tokens: state.usage?.completion_tokens || 0
31930
+ }
31920
31931
  });
31921
31932
  send("message_stop", { type: "message_stop" });
31922
31933
  }
@@ -31927,7 +31938,7 @@ data: ${JSON.stringify(d)}
31927
31938
  } else {
31928
31939
  const estimatedOutputTokens = Math.ceil(state.accumulatedText.length / 4);
31929
31940
  log(`[Streaming] No usage data from provider, estimating: ~${estimatedOutputTokens} output tokens`);
31930
- onTokenUpdate(100, estimatedOutputTokens);
31941
+ onTokenUpdate(priorInputTokens || 100, estimatedOutputTokens);
31931
31942
  }
31932
31943
  }
31933
31944
  if (!isClosed) {
@@ -37545,7 +37556,7 @@ data: ${JSON.stringify(data)}
37545
37556
  model: opts.modelName,
37546
37557
  stop_reason: null,
37547
37558
  stop_sequence: null,
37548
- usage: { input_tokens: 100, output_tokens: 1 }
37559
+ usage: messageStartUsage(opts.priorInputTokens)
37549
37560
  }
37550
37561
  });
37551
37562
  send("ping", { type: "ping" });
@@ -37589,7 +37600,10 @@ data: ${JSON.stringify(data)}
37589
37600
  send("message_delta", {
37590
37601
  type: "message_delta",
37591
37602
  delta: { stop_reason: hasToolCalls ? "tool_use" : "end_turn", stop_sequence: null },
37592
- usage: { output_tokens: outputTokens }
37603
+ usage: {
37604
+ ...inputTokens > 0 ? { input_tokens: inputTokens } : {},
37605
+ output_tokens: outputTokens
37606
+ }
37593
37607
  });
37594
37608
  send("message_stop", { type: "message_stop" });
37595
37609
  }
@@ -37792,7 +37806,7 @@ data: ${JSON.stringify(data)}
37792
37806
  model: opts.modelName,
37793
37807
  stop_reason: null,
37794
37808
  stop_sequence: null,
37795
- usage: { input_tokens: 100, output_tokens: 1 }
37809
+ usage: messageStartUsage(opts.priorInputTokens)
37796
37810
  }
37797
37811
  });
37798
37812
  send("ping", { type: "ping" });
@@ -37813,7 +37827,10 @@ data: ${JSON.stringify(data)}
37813
37827
  send("message_delta", {
37814
37828
  type: "message_delta",
37815
37829
  delta: { stop_reason: "end_turn", stop_sequence: null },
37816
- usage: { output_tokens: completionTokens }
37830
+ usage: {
37831
+ ...promptTokens > 0 ? { input_tokens: promptTokens } : {},
37832
+ output_tokens: completionTokens
37833
+ }
37817
37834
  });
37818
37835
  send("message_stop", { type: "message_stop" });
37819
37836
  }
@@ -37965,7 +37982,7 @@ data: ${JSON.stringify(data)}
37965
37982
  model: opts.modelName,
37966
37983
  stop_reason: null,
37967
37984
  stop_sequence: null,
37968
- usage: { input_tokens: 100, output_tokens: 1 }
37985
+ usage: messageStartUsage(opts.priorInputTokens)
37969
37986
  }
37970
37987
  });
37971
37988
  send("ping", { type: "ping" });
@@ -38255,6 +38272,7 @@ class TokenTracker {
38255
38272
  sessionTotalCost = 0;
38256
38273
  sessionInputTokens = 0;
38257
38274
  sessionOutputTokens = 0;
38275
+ lastInputTokens = 0;
38258
38276
  modelNameOverride;
38259
38277
  quotaRemaining;
38260
38278
  constructor(port, config2) {
@@ -38271,10 +38289,11 @@ class TokenTracker {
38271
38289
  this.quotaRemaining = fraction;
38272
38290
  }
38273
38291
  rewrite() {
38274
- this.writeFile(this.sessionInputTokens, this.sessionOutputTokens);
38292
+ this.writeFile(this.getLastInputTokens(), this.sessionOutputTokens);
38275
38293
  }
38276
38294
  update(inputTokens, outputTokens) {
38277
38295
  this.sessionInputTokens = inputTokens;
38296
+ this.lastInputTokens = inputTokens;
38278
38297
  this.sessionOutputTokens += outputTokens;
38279
38298
  const pricing = this.getPricing();
38280
38299
  const cost = inputTokens / 1e6 * pricing.inputCostPer1M + outputTokens / 1e6 * pricing.outputCostPer1M;
@@ -38283,6 +38302,7 @@ class TokenTracker {
38283
38302
  }
38284
38303
  accumulateBoth(inputTokens, outputTokens) {
38285
38304
  this.sessionInputTokens += inputTokens;
38305
+ this.lastInputTokens = this.sessionInputTokens;
38286
38306
  this.sessionOutputTokens += outputTokens;
38287
38307
  const pricing = this.getPricing();
38288
38308
  const cost = this.sessionInputTokens / 1e6 * pricing.inputCostPer1M + this.sessionOutputTokens / 1e6 * pricing.outputCostPer1M;
@@ -38291,6 +38311,7 @@ class TokenTracker {
38291
38311
  }
38292
38312
  updateWithDelta(inputTokens, outputTokens) {
38293
38313
  let incrementalInputTokens;
38314
+ this.lastInputTokens = inputTokens;
38294
38315
  if (inputTokens >= this.sessionInputTokens) {
38295
38316
  incrementalInputTokens = inputTokens - this.sessionInputTokens;
38296
38317
  this.sessionInputTokens = inputTokens;
@@ -38306,10 +38327,11 @@ class TokenTracker {
38306
38327
  const pricing = this.getPricing();
38307
38328
  const cost = incrementalInputTokens / 1e6 * pricing.inputCostPer1M + outputTokens / 1e6 * pricing.outputCostPer1M;
38308
38329
  this.sessionTotalCost += cost;
38309
- this.writeFile(Math.max(inputTokens, this.sessionInputTokens), this.sessionOutputTokens, pricing.isEstimate);
38330
+ this.writeFile(inputTokens, this.sessionOutputTokens, pricing.isEstimate);
38310
38331
  }
38311
38332
  updateWithActualCost(inputTokens, outputTokens, actualCost) {
38312
38333
  this.sessionInputTokens = inputTokens;
38334
+ this.lastInputTokens = inputTokens;
38313
38335
  this.sessionOutputTokens += outputTokens;
38314
38336
  if (typeof actualCost === "number" && actualCost > 0) {
38315
38337
  this.sessionTotalCost += actualCost;
@@ -38325,6 +38347,7 @@ class TokenTracker {
38325
38347
  updateLocal(inputTokens, outputTokens) {
38326
38348
  if (inputTokens > 0) {
38327
38349
  this.sessionInputTokens = inputTokens;
38350
+ this.lastInputTokens = inputTokens;
38328
38351
  }
38329
38352
  this.sessionOutputTokens += outputTokens;
38330
38353
  this.writeFile(this.sessionInputTokens, this.sessionOutputTokens);
@@ -38338,6 +38361,9 @@ class TokenTracker {
38338
38361
  getInputTokens() {
38339
38362
  return this.sessionInputTokens;
38340
38363
  }
38364
+ getLastInputTokens() {
38365
+ return this.lastInputTokens || this.sessionInputTokens;
38366
+ }
38341
38367
  getOutputTokens() {
38342
38368
  return this.sessionOutputTokens;
38343
38369
  }
@@ -38879,16 +38905,18 @@ class ComposedHandler {
38879
38905
  }
38880
38906
  };
38881
38907
  const streamFormat = this.provider.overrideStreamFormat?.() ?? this.explicitAdapter?.getStreamFormat() ?? this.modelAdapter?.getStreamFormat() ?? this.getAdapter().getStreamFormat();
38908
+ const priorInputTokens = this.tokenTracker.getLastInputTokens();
38882
38909
  switch (streamFormat) {
38883
38910
  case "openai-sse":
38884
- return createStreamingResponseHandler(c, response, adapter, this.bareModelName, this.middlewareManager, onTokenUpdate, claudeRequest.tools, toolNameMap);
38911
+ return createStreamingResponseHandler(c, response, adapter, this.bareModelName, this.middlewareManager, onTokenUpdate, claudeRequest.tools, toolNameMap, priorInputTokens);
38885
38912
  case "openai-responses-sse":
38886
38913
  return createResponsesStreamHandler(c, response, {
38887
38914
  modelName: this.bareModelName,
38888
38915
  onTokenUpdate,
38889
38916
  toolNameMap: adapter.getToolNameMap(),
38890
38917
  contextWindow: lookupModelForProvider(this.bareModelName, this.provider.name),
38891
- onApiError
38918
+ onApiError,
38919
+ priorInputTokens
38892
38920
  });
38893
38921
  case "anthropic-sse":
38894
38922
  return createAnthropicPassthroughStream(c, response, {
@@ -38908,13 +38936,15 @@ class ComposedHandler {
38908
38936
  middlewareManager: this.middlewareManager,
38909
38937
  onTokenUpdate,
38910
38938
  onToolCall,
38911
- unwrapResponse: this.options.unwrapGeminiResponse
38939
+ unwrapResponse: this.options.unwrapGeminiResponse,
38940
+ priorInputTokens
38912
38941
  });
38913
38942
  }
38914
38943
  case "ollama-jsonl":
38915
38944
  return createOllamaJsonlStream(c, response, {
38916
38945
  modelName: this.bareModelName,
38917
- onTokenUpdate
38946
+ onTokenUpdate,
38947
+ priorInputTokens
38918
38948
  });
38919
38949
  default:
38920
38950
  throw new Error(`Unknown stream format: ${streamFormat}`);
@@ -71147,7 +71177,8 @@ __export(exports_claude_runner, {
71147
71177
  isProxyAuthMode: () => isProxyAuthMode,
71148
71178
  computeMainThreadContextWindow: () => computeMainThreadContextWindow,
71149
71179
  checkClaudeInstalled: () => checkClaudeInstalled,
71150
- buildClaudishSettingsOverlay: () => buildClaudishSettingsOverlay
71180
+ buildClaudishSettingsOverlay: () => buildClaudishSettingsOverlay,
71181
+ MIN_AUTO_COMPACT_WINDOW: () => MIN_AUTO_COMPACT_WINDOW
71151
71182
  });
71152
71183
  import { spawn as spawn4 } from "child_process";
71153
71184
  import {
@@ -71477,11 +71508,13 @@ async function runClaudeWithProxy(config3, proxyUrl, onCleanup) {
71477
71508
  env.ANTHROPIC_AUTH_TOKEN = "placeholder-token-not-used-proxy-handles-auth";
71478
71509
  if (!process.env[ENV.CLAUDE_CODE_AUTO_COMPACT_WINDOW]) {
71479
71510
  const autoCompactWindow = await computeMainThreadContextWindow(config3);
71480
- if (autoCompactWindow > 0) {
71511
+ if (autoCompactWindow >= MIN_AUTO_COMPACT_WINDOW) {
71481
71512
  env[ENV.CLAUDE_CODE_AUTO_COMPACT_WINDOW] = String(autoCompactWindow);
71482
71513
  if (!config3.quiet) {
71483
71514
  console.error(`[claudish] Auto-compact window: ${autoCompactWindow.toLocaleString()} tokens ` + "(Claude Code compacts before the backend's real limit)");
71484
71515
  }
71516
+ } else if (autoCompactWindow > 0 && !config3.quiet) {
71517
+ console.error(`[claudish] Model's real context window (${autoCompactWindow.toLocaleString()}) is below ` + `Claude Code's ${MIN_AUTO_COMPACT_WINDOW.toLocaleString()}-token auto-compact floor \u2014 ` + "leaving CLAUDE_CODE_AUTO_COMPACT_WINDOW unset so native auto-compaction stays on.");
71485
71518
  }
71486
71519
  }
71487
71520
  }
@@ -71666,7 +71699,7 @@ async function checkClaudeInstalled() {
71666
71699
  const binary = await findClaudeBinary();
71667
71700
  return binary !== null;
71668
71701
  }
71669
- var restoreTerminal = null;
71702
+ var restoreTerminal = null, MIN_AUTO_COMPACT_WINDOW = 200000;
71670
71703
  var init_claude_runner = __esm(() => {
71671
71704
  init_model_catalog();
71672
71705
  init_config();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claudish",
3
- "version": "7.19.0",
3
+ "version": "7.19.1",
4
4
  "description": "Run Claude Code with any model - OpenRouter, Ollama, LM Studio & local models",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -60,10 +60,10 @@
60
60
  "ai"
61
61
  ],
62
62
  "optionalDependencies": {
63
- "@claudish/magmux-darwin-arm64": "7.19.0",
64
- "@claudish/magmux-darwin-x64": "7.19.0",
65
- "@claudish/magmux-linux-arm64": "7.19.0",
66
- "@claudish/magmux-linux-x64": "7.19.0"
63
+ "@claudish/magmux-darwin-arm64": "7.19.1",
64
+ "@claudish/magmux-darwin-x64": "7.19.1",
65
+ "@claudish/magmux-linux-arm64": "7.19.1",
66
+ "@claudish/magmux-linux-x64": "7.19.1"
67
67
  },
68
68
  "author": "Jack Rudenko <i@madappgang.com>",
69
69
  "license": "MIT",