-
Notifications
You must be signed in to change notification settings - Fork 2.4k
feat: Add Claude Code Provider Support with SDK Integration #805
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
Conversation
Implements Claude Code as a new AI provider that uses the Claude Code CLI without requiring API keys. This enables users to leverage Claude models through their local Claude Code installation. Key changes: - Add complete AI SDK v1 implementation for Claude Code provider - Custom SDK with streaming/non-streaming support - Session management for conversation continuity - JSON extraction for object generation mode - Support for advanced settings (maxTurns, allowedTools, etc.) - Integrate Claude Code into Task Master's provider system - Update ai-services-unified.js to handle keyless authentication - Add provider to supported-models.json with opus/sonnet models - Ensure correct maxTokens values are applied (opus: 32000, sonnet: 64000) - Fix maxTokens configuration issue - Add max_tokens property to getAvailableModels() output - Update setModel() to properly handle claude-code models - Create update-config-tokens.js utility for init process - Add comprehensive documentation - User guide with configuration examples - Advanced settings explanation and future integration options The implementation maintains full backward compatibility with existing providers while adding seamless Claude Code support to all Task Master commands.
- Remove non-existent 'do', 'estimate', and 'analyze' commands - Replace with actual Task Master commands: next, show, set-status - Use correct syntax for parse-prd and analyze-complexity
This change makes the Claude Code SDK package optional, preventing installation failures for users who don't need Claude Code functionality. Changes: - Added @anthropic-ai/claude-code to optionalDependencies in package.json - Implemented lazy loading in language-model.js to only import the SDK when actually used - Updated documentation to explain the optional installation requirement - Applied formatting fixes to ensure code consistency Benefits: - Users without Claude Code subscriptions don't need to install the dependency - Reduces package size for users who don't use Claude Code - Prevents installation failures if the package is unavailable - Provides clear error messages when the package is needed but not installed The implementation uses dynamic imports to load the SDK only when doGenerate() or doStream() is called, ensuring the provider can be instantiated without the package present.
Addresses code review feedback about missing automated tests for the ClaudeCodeProvider. ## Changes - Added unit tests for ClaudeCodeProvider class covering constructor, validateAuth, and getClient methods - Added unit tests for ClaudeCodeLanguageModel testing lazy loading behavior and error handling - Added integration tests verifying optional dependency behavior when @anthropic-ai/claude-code is not installed ## Test Coverage 1. **Unit Tests**: - ClaudeCodeProvider: Basic functionality, no API key requirement, client creation - ClaudeCodeLanguageModel: Model initialization, lazy loading, error messages, warning generation 2. **Integration Tests**: - Optional dependency behavior when package is not installed - Clear error messages for users about missing package - Provider instantiation works but usage fails gracefully All tests pass and provide comprehensive coverage for the claude-code provider implementation.
This functionality was out of scope for the Claude Code provider PR. The automatic updating of maxTokens values in config.json during initialization is a general improvement that should be in a separate PR. Additionally, Claude Code ignores maxTokens and temperature parameters anyway, making this change irrelevant for the Claude Code integration. Removed: - scripts/modules/update-config-tokens.js - Import and usage in scripts/init.js
- Added Claude Code to the list of supported providers in Requirements section - Noted that Claude Code requires no API key but needs Claude Code CLI - Added example of configuring claude-code/sonnet model - Created dedicated Claude Code Support section with key information - Added link to detailed Claude Code setup documentation This ensures users are aware of the Claude Code option as a no-API-key alternative for using Claude models.
🦋 Changeset detectedLatest commit: 1ae56c3 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
The models command was missing the --claude-code provider flag, preventing users from setting Claude Code models via CLI. While the backend already supported claude-code as a provider hint, there was no command-line flag to trigger it. Changes: - Added --claude-code option to models command alongside existing provider flags - Updated provider flags validation to include claudeCode option - Added claude-code to providerHint logic for all three model roles (main, research, fallback) - Updated error message to include --claude-code in list of mutually exclusive flags - Added example usage in help text This allows users to properly set Claude Code models using commands like: task-master models --set-main sonnet --claude-code task-master models --set-main opus --claude-code Without this flag, users would get "Model ID not found" errors when trying to set claude-code models, as the system couldn't determine the correct provider for generic model names like "sonnet" or "opus".
|
Any timeline for this being released? Thank you very much. |
694412e to
1ae56c3
Compare
|
@ben-vargas how can we use it as MCP is there any guide? |
|
@fahimanwer - I only use it from the command line, haven't tried it in an IDE like Cursor. Maybe someone more familiar with using task master via MCP can checkout the branch and test/guide? I'm kind of wondering if this PR should just be closed, lack of PR review/input tells me the project owners are possibly (probably?) working on their own implementation approach. |
Crunchyman-ralph
left a comment
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.
lgtm, with small nitpicks, but lets merge this.
Testing this asap
| if (providerName === 'claude-code') { | ||
| return 'claude-code-no-key-required'; | ||
| } |
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 doesn't go here, please refer to how we doing it with ollama that doesn't require an api key either
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 interesting, can we leverage a package for this, or are there no packages that exist to do this ? I didn't find anything in vercel's provider utils, but wondering if we can find something ?
Something like this for example:
https://www.npmjs.com/package/extract-json-from-string
|
seems to be working pretty well and fast, lets resolve conflicts cuz I merged a bunch of things and lets merge this! |
|
@ben-vargas thanks a lot for your contribution, super sick PR, taking it over to resolve conflicts so that you don't have to on #829 Thanks again for your contribution <3 |
Add Claude Code Provider Support with SDK Integration
Overview
This PR introduces native support for Claude models through the Claude Code CLI using an SDK-based approach. This implementation allows users to leverage Claude's powerful models (Opus and Sonnet) without requiring an API key, making it accessible to users who have Claude Code installed on their system.
The approach is based on the ai-sdk-provider-claude-code project but has been implemented internally as a custom SDK to avoid external dependencies and maintain full control over the integration.
Key Features
@anthropic-ai/claude-codeSDK@anthropic-ai/claude-codepackage is optional - users without it can still use other providersTechnical Implementation
Architecture
src/ai-providers/custom-sdk/claude-code/src/ai-providers/claude-code.jsai-services-unified.jsto handle optional dependencyKey Components
language-model.js): Handles text generation and streaming with lazy loading of the SDKmessage-converter.js): Converts between Task Master and Claude Code message formatserrors.js): Provides clear error messages for missing dependenciesjson-extractor.js): Handles structured output extractionChanges by Commit
1. feat: add Claude Code provider support (426aaf2)
2. fix(docs): correct invalid commands in claude-code usage examples (3416cfa)
3. feat: make @anthropic-ai/claude-code an optional dependency (0e84bd1)
@anthropic-ai/claude-codeto optionalDependencies4. test: add comprehensive tests for ClaudeCodeProvider (e6e39e2)
5. revert: remove maxTokens update functionality from init (cca76c1)
6. docs: add Claude Code support information to README (e04a861)
7. style: apply biome formatting to test files (ee6f458)
8. fix(models): add missing --claude-code flag to models command (b1aa058)
--claude-codeoption to models command alongside existing provider flagsConfiguration
Add to
.taskmaster/config.json:{ "models": { "main": { "provider": "claude-code", "modelId": "sonnet", "maxTokens": 64000, "temperature": 0.2 } } }Usage Examples
Testing
All tests pass:
Run tests:
Breaking Changes
None. This is a purely additive change that doesn't affect existing functionality.
Files Changed
New Files
src/ai-providers/claude-code.js- Main provider classsrc/ai-providers/custom-sdk/claude-code/- SDK implementation (6 files):index.js- Entry point for Claude Code SDKlanguage-model.js- Core model implementation with lazy loadingmessage-converter.js- Message format conversionerrors.js- Error handling and custom error typesjson-extractor.js- JSON extraction from responsestypes.js- TypeScript-style type definitionsdocs/examples/claude-code-usage.md- Comprehensive usage documentationtests/unit/ai-providers/claude-code.test.js- Provider unit teststests/unit/ai-providers/custom-sdk/claude-code/language-model.test.js- Language model teststests/integration/claude-code-optional.test.js- Optional dependency testsModified Files
package.json- Added @anthropic-ai/claude-code as optional dependencyscripts/modules/ai-services-unified.js- Implemented lazy loading for Claude Codescripts/modules/config-manager.js- Added claude-code to valid providers listscripts/modules/supported-models.json- Added claude-code models configurationscripts/modules/task-manager/models.js- Added claude-code to provider listscripts/modules/commands.js- Added --claude-code flag to models commandsrc/ai-providers/index.js- Added ClaudeCodeProvider exporttests/unit/ai-services-unified.test.js- Updated tests for new providerREADME.md- Added Claude Code documentation and examplesAcknowledgments
This implementation builds upon the excellent work of the community in bringing Claude Code support to Task Master:
This PR represents the culmination of these efforts, providing a robust implementation that makes Claude models accessible to all Task Master users.