feat: Add Claude Code Provider Support with SDK Integration #829
feat: Add Claude Code Provider Support with SDK Integration #829Crunchyman-ralph merged 9 commits intonextfrom
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.
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".
🦋 Changeset detectedLatest commit: 8df2d50 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 |
|
When can we expect the release waiting for this one eagerly. |
|
@Crunchyman-ralph if you didn't want as much code bloat, and some improved efficiencies, in exchange for a dependency - this version exists too: https://github.com/ben-vargas/ai-claude-task-master/tree/feature/claude-code-sdk-simple Let me know if you'd prefer a PR from that branch. |
|
If you were interested in going that route, I'd just pin it to the current version you accept/release with as it is alpha. But I am thinking I'll submit a PR to verve to have that listed as a community built provider in vercels ai-sdk. |
|
@ben-vargas such a great idea, it would be such a great package if you were to submit it to vercel! |
|
@ben-vargas just saw you made a package, as soon as it passes vercel's net, lets definitely add it! |
|
@Crunchyman-ralph sounds good! |
|
This is rad. thanks for adding this. |
|
Great feature |
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.