-
Notifications
You must be signed in to change notification settings - Fork 206
Add OAuth token support for PR metadata generation #216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
@joedanz is attempting to deploy a commit to the Superagent Team on Vercel. A member of the Team first needs to authorize it. |
packages/sdk/package.json
Outdated
| "@ai-sdk/anthropic": "^1.2.12", | ||
| "@ai-sdk/openai": "^1.3.22", | ||
| "@ai-sdk/openai-compatible": "^0.2.14", | ||
| "@anthropic-ai/claude-code": "^1.0.85", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't want to add to much bloat to the dependencies here, why is this needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the Claude Code SDK, which is what allows us to utilize the oAuth token for the messages API. Right now we can only call Claude itself, as it sees that token, but to make general API requests for whatever you need to utilize Claude Code SDK, which can then see the oAuth token.
https://docs.anthropic.com/en/docs/claude-code/sdk
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use vibe-kit/auth here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code is not doing the actual auth, and vibe-kit/auth can still be used for that. This is utilizing Claude Code via SDK for the requests instead of the messaging API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok got it
OAuth Token Support JustificationBusiness ProblemUsers who authenticate with Claude Code using OAuth tokens ( Technical Root CauseOAuth tokens from Claude Code are not compatible with the standard Anthropic API SDK. These tokens are specifically designed for Claude Code CLI/SDK authentication and cannot be used directly with The technical incompatibility stems from:
Solution RequirementsTo support OAuth users, we needed to:
Implementation ChallengeThe Claude Code SDK presents a significant dependency burden:
Problem: Adding this as a regular dependency would force all users to install 90MB, even those who never use OAuth functionality. Elegant Solution: Optional Peer DependenciesWe implemented OAuth support using npm's optional peer dependency system: For Non-OAuth Users (Majority)
For OAuth Users (Minority)
Technical Implementation// Dynamic imports with error handling
const { isOAuthToken } = await import('./oauth-utils');
if (isOAuthToken(modelConfig)) {
// Loads Claude Code SDK only when needed
const { generatePRMetadataWithOAuth } = await import('./oauth-utils');
return await generatePRMetadataWithOAuth(patch, modelConfig, prompt);
}Key BenefitsUser Impact
Technical Excellence
Business Value
ConclusionThis implementation solves a real user problem (OAuth token incompatibility) while respecting the needs of all user types. Instead of forcing a 90MB dependency on everyone, we created a truly optional feature that provides full functionality for those who need it, with zero cost for those who don't. The solution demonstrates effective dependency management and user-centric design, enabling OAuth functionality without compromising the experience for existing users. |
Summary
Implements OAuth token support for PR metadata generation using the
@anthropic-ai/claude-codeSDK. This enables users with OAuth tokens (sk-ant-oat*) to create pull requests without requiring a separate Anthropic API key, while ensuring zero installation overhead for non-OAuth users through optional peer dependencies.Changes Made
Core Implementation
@anthropic-ai/claude-code@^1.0.96marked as optional peer dependencyoauth-utils.tswith graceful error handling for missing dependenciesgeneratePRMetadata: Added OAuth detection with dynamic imports and dependency checkinggenerateCommitMessage: Added OAuth support with runtime dependency validationZero Installation Impact Optimization
Technical Details
OAuth Detection & Loading
sk-ant-oatprefixawait import('./oauth-utils')for code splittingMessage Stream Handling
message.type === 'result'outputFormat: 'text'for cleaner responsesJSON Parsing Optimization
Installation Impact Analysis
Bundle Analysis
Benefits
Performance & Size
Functionality
Code Quality
Files Modified
packages/sdk/package.json@anthropic-ai/claude-code@^1.0.96as optional peer dependencypeerDependenciesMetafor graceful handlingpackages/sdk/src/agents/utils.tsgeneratePRMetadata()with dynamic OAuth importsgenerateCommitMessage()with lazy loadingpackages/sdk/src/agents/oauth-utils.ts(NEW)Migration Impact
@anthropic-ai/claude-codeonly when neededUsage Instructions
For API Key Users (No Action Required)
# Nothing to install - works as before npm install @vibe-kit/sdkFor OAuth Users (Install Peer Dependency)
Achievement
This implementation provides:
Instead of forcing all users to pay the 90MB installation cost, we've created an optional feature that respects user choice and minimizes impact. This demonstrates effective optional dependency management.