chore: upgrade @anthropic-ai/claude-agent-sdk to version 0.2.59 and add model usage logging#446
Conversation
…dd model usage logging
📝 WalkthroughWalkthroughThe pull request updates the Changes
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@package.json`:
- Line 48: Update PR to verify and document the SDK upgrade: ensure your
environment uses Node.js >= 18 and that the project has a compatible Zod version
(peer dependency, e.g., zod ^4.x) before keeping
"@anthropic-ai/claude-agent-sdk": "^0.2.59" in package.json, run and commit the
results of npm run build and the test suite (npm test or the repo's test
script), and add a short note in the PR description confirming build/tests
passed and any Claude Code CLI compatibility checks performed (include the exact
Node and zod versions used and test output/log snippets).
In `@server/claude-sdk.js`:
- Around line 596-598: Remove the unconditional console.log that prints
Object.keys(message.modelUsage || {}) inside the streaming loop; instead, check
whether message.modelUsage is present before logging (matching the pattern used
later around the existing conditional at line 611). Locate the log by searching
for the console.log call that mentions "Model was sent using:" and wrap it in a
guard like if (message.modelUsage) { ... } so empty arrays are not logged when
modelUsage is absent.
ℹ️ Review info
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (2)
package.jsonserver/claude-sdk.js
| "license": "GPL-3.0", | ||
| "dependencies": { | ||
| "@anthropic-ai/claude-agent-sdk": "^0.1.71", | ||
| "@anthropic-ai/claude-agent-sdk": "^0.2.59", |
There was a problem hiding this comment.
🧩 Analysis chain
🌐 Web query:
@anthropic-ai/claude-agent-sdk 0.2.59 release notes changelog breaking changes
💡 Result:
@anthropic-ai/claude-agent-sdk v0.2.59 (TypeScript) changelog:
- Added:
getSessionMessages()to read a session’s conversation history from its transcript file, including pagination vialimitandoffset. [1]
Breaking changes: None are mentioned for v0.2.59 in the official TypeScript SDK changelog entry. [1]
Note (Python): The Python SDK uses a different version line; its latest changelog entry references bundling Claude CLI v2.1.59 under SDK v0.1.44. [2]
Sources: [1] [2]
🌐 Web query:
@anthropic-ai/claude-agent-sdk message.modelUsage support version
💡 Result:
message.modelUsage is supported on SDKResultMessage (both subtype: "success" and error subtypes) in the TypeScript Claude Agent SDK; it’s a per-model breakdown shaped like { [modelName: string]: ModelUsage }. [1]
To have this field available, use a current SDK version—v0.2.59 is the latest published as of Feb 26, 2026. [2]
Sources
[1] Claude API Docs – Agent SDK reference (TypeScript) (SDKResultMessage includes modelUsage) (platform.claude.com)
[2] GitHub Releases – @anthropic-ai/claude-agent-sdk v0.2.59 (github.com)
Citations:
- 1: https://platform.claude.com/docs/en/agent-sdk/typescript?utm_source=openai
- 2: https://github.com/anthropics/claude-agent-sdk-typescript/releases
🌐 Web query:
@anthropic-ai/claude-agent-sdk 0.1.71 0.2.59 upgrade compatibility
💡 Result:
Upgrading @anthropic-ai/claude-agent-sdk from 0.1.71 → 0.2.59 is generally a minor-version bump (0.1 → 0.2), but there are a few practical compatibility constraints to check:
- Node runtime:
0.2.59requires Node >= 18. [1] - Zod peer dependency:
0.2.59declareszodas a peerDependency^4.0.0, so projects still on Zod v3 will need to upgrade (or you’ll get peer-dep warnings / possible type/runtime mismatches). [1] - Claude Code CLI coupling:
0.2.59is built against Claude Code CLI2.1.59(fieldclaudeCodeVersion: "2.1.59"). In practice, you should ensure your environment is running a compatible/new-enough Claude Code CLI (often installed separately vianpm install -g@anthropic-ai/claude-code``). [1][2] - API surface changes vs earlier generations: if your code still relies on older “Claude Code SDK” defaults (auto-loading filesystem settings / default system prompt), those were breaking changes introduced earlier in the Agent SDK line—double-check your
query({ options: ... })configuration if behavior changes after upgrading. [3]
Recommended upgrade steps
- Upgrade CLI (if you use it separately):
npm i -g@anthropic-ai/claude-code`` (aim for compatibility with 2.1.59). [1][2] - Upgrade SDK:
npm i@anthropic-ai/claude-agent-sdk@0.2.59. [1] - Ensure
zod@^4is installed in your app. [1]
Sources: [1] (0.2.59 package metadata), [2] (Agent SDK hosting/system requirements mentioning Claude Code CLI), [3] (Agent SDK migration guide on behavior-breaking defaults).
Provide build/test verification and confirm dependency compatibility for this SDK upgrade.
The @anthropic-ai/claude-agent-sdk v0.2.59 upgrade has no documented breaking changes and properly supports message.modelUsage on SDKResultMessage. However, ensure the following practical dependencies are satisfied:
- Node.js >= 18 (required by v0.2.59)
- Zod ^4.0.0 (peer dependency; confirm your app has this version)
- Claude Code CLI 2.1.59 compatibility (if used in this environment)
Per Contributing.md guidelines, add evidence to the PR that npm run build and tests pass with this upgrade.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@package.json` at line 48, Update PR to verify and document the SDK upgrade:
ensure your environment uses Node.js >= 18 and that the project has a compatible
Zod version (peer dependency, e.g., zod ^4.x) before keeping
"@anthropic-ai/claude-agent-sdk": "^0.2.59" in package.json, run and commit the
results of npm run build and the test suite (npm test or the repo's test
script), and add a short note in the PR description confirming build/tests
passed and any Claude Code CLI compatibility checks performed (include the exact
Node and zod versions used and test output/log snippets).
| // logs which model was used in the message | ||
| console.log("---> Model was sent using:", Object.keys(message.modelUsage || {})); | ||
|
|
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
# First, let's look at the actual code context around lines 596-598
cat -n server/claude-sdk.js | sed -n '580,620p'Repository: siteboon/claudecodeui
Length of output: 1793
🏁 Script executed:
# Let's also check the broader context to understand the loop structure
cat -n server/claude-sdk.js | sed -n '560,600p'Repository: siteboon/claudecodeui
Length of output: 1985
🏁 Script executed:
# Search for where message.modelUsage is used or set
rg "modelUsage" server/claude-sdk.js -B 2 -A 2Repository: siteboon/claudecodeui
Length of output: 783
🏁 Script executed:
# Check if there are any other uses of console.log in streaming loops
rg "console\.(log|debug)" server/claude-sdk.js -B 3 -A 1Repository: siteboon/claudecodeui
Length of output: 3392
Remove unconditional logging of empty model-usage keys from streaming loop.
This logs on every streamed message and produces empty arrays when modelUsage is absent, adding noise without value. Gate it by checking if modelUsage exists, matching the existing conditional pattern in the file (line 611).
- // logs which model was used in the message
- console.log("---> Model was sent using:", Object.keys(message.modelUsage || {}));
+ // logs which model was used in the message
+ if (message.modelUsage) {
+ console.log("---> Model was sent using:", Object.keys(message.modelUsage));
+ }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@server/claude-sdk.js` around lines 596 - 598, Remove the unconditional
console.log that prints Object.keys(message.modelUsage || {}) inside the
streaming loop; instead, check whether message.modelUsage is present before
logging (matching the pattern used later around the existing conditional at line
611). Locate the log by searching for the console.log call that mentions "Model
was sent using:" and wrap it in a guard like if (message.modelUsage) { ... } so
empty arrays are not logged when modelUsage is absent.
this upgrades the claude-agent-sdk to the latest version to support opus 4.6 and sonnet 4.6.
We can verify which model we are using by observing the server side console logs.
Summary by CodeRabbit