feat: Add Claude Code CLI Provider Support with SDK Architecture#785
feat: Add Claude Code CLI Provider Support with SDK Architecture#785ben-vargas wants to merge 1 commit intoeyaltoledano:mainfrom
Conversation
Implements support for Claude Code (opus/sonnet) models via the Claude CLI, enabling local AI assistance without API keys. ## Architecture & Design Decisions ### Provider Architecture - Created `ClaudeCodeProvider` extending `BaseAIProvider` to maintain consistency - Implemented custom SDK wrapper pattern in `src/ai-providers/custom-sdk/claude-code-sdk.js` following project conventions for non-Vercel-AI-SDK providers - Wrapper provides interface compatibility layer between native Claude Code SDK and Task Master's provider system ### Key Implementation Details **Authentication Model:** - Uses CLI authentication (`claude login`) instead of API keys - Added to `PROVIDERS_WITH_OPTIONAL_API_KEY` array in ai-services-unified.js - Validates CLI availability and authentication status **Token Usage Tracking:** - Properly extracts usage data from SDK responses including cache tokens - Maps SDK fields to expected telemetry format (inputTokens/outputTokens) - Supports both streaming and non-streaming token counting **Message Format Handling:** - Converts standard role names (user/assistant) to Claude Code format (human/assistant) - Handles both simple strings and complex content arrays - Preserves system messages for context ### Files Changed **New Files:** - `src/ai-providers/claude-code.js` - Main provider implementation - `src/ai-providers/custom-sdk/claude-code-sdk.js` - SDK wrapper for consistency **Modified Files:** - `package.json` - Added @anthropic-ai/claude-code dependency - `scripts/modules/supported-models.json` - Added opus/sonnet models with metadata - `scripts/modules/ai-services-unified.js` - Integrated provider into service layer - `scripts/modules/config-manager.js` - Added getClaudeCodeConfig function - `src/ai-providers/index.js` - Exported ClaudeCodeProvider - `tests/unit/ai-services-unified.test.js` - Updated test mocks ### Features Supported - Text generation (generateText) - Streaming responses (streamText) - JSON object generation (generateObject) - Full telemetry support with accurate token counting - Error handling for CLI-specific scenarios ### Model Configuration - opus: 32K max tokens, SWE score 0.725 - sonnet: 64K max tokens, SWE score 0.727 - Both models support all roles (main, research, fallback) - Zero cost (free to use via CLI) This implementation maintains architectural consistency while adding powerful local AI capabilities to Task Master.
|
|
I think the community just wants to see this support realized, I am totally fine with @Crunchyman-ralph or one of the other owners making changes to the code in this PR or closing it and pushing through one of the others. I tried to abstract out a wrapper to the sdk as he had requested a few times in the other PRs so that a pattern is established for using non vercel ai-sdk providers. I do have a repo where I've added ai-sdk community provider for claude code, though I don't necessarily want this project/functionality dependent on that (I don't know if I'll carry that work on long term); so going the wrapper approach probably makes the most sense. I also think it is important that claude-code support both 'opus' and 'sonnet' models as choices, which this PR does. |
|
@ben-vargas I second that statement! I really want to see this work, i have it working in certan scenarios and in others i find myself going nuts. Ultimately I wanted the telemetry to work and not require the sdk libs to have to be in each local project for it to work, so im glad to see you and everyone elses iterations on this finally come to fruition |
1 similar comment
|
@ben-vargas I second that statement! I really want to see this work, i have it working in certan scenarios and in others i find myself going nuts. Ultimately I wanted the telemetry to work and not require the sdk libs to have to be in each local project for it to work, so im glad to see you and everyone elses iterations on this finally come to fruition |
|
Thank you! I was about to push mine... Anyway it all started with this #601 |
Oh dang, I didn't even know how far back this went! Thanks for pointing that out. A lot of minds think alike and want this in! |
|
Looks like there's ongoing work in other PRs, and I've refactored this in a better approach that I may submit as a different PR if the community wants. Feels like too many cooks in the kitchen right now. |
|
everyone wants the claude code provider integration lol |
|
@Crunchyman-ralph haha, HUGE demand! I'm curious if you'd take a look at this approach... I kind of like this. Seems to be testing well for me so far: https://github.com/ben-vargas/ai-claude-task-master/tree/feature/claude-code-sdk |
|
i didnt want to open up an issue for this, but i wondered based on the claude code implementation documentation if the sdk will respect the CLAUDE.md of the project or if we need to add all that content to the config file. i see it respects the permissions set for the repo. |
|
@spearmootz - Anthropic's documentation for the Claude Code SDK doesn't specify. But if I had to make an educated guess, the SDK is spawning standard claude CLI process, but not within your project directory, so I bet it adheres to the global CLAUDE.md in the ~/.claude/ directory, but it won't know the project directory you're running task master from since it is a few layers removed and no parameters appear to be available to pass that info. |
|
@ben-vargas im gonna do some testing and report back. it might be good to put in the documentation. its interesting because im using claude-code and then having it interact with task-master. so far, it might... i added this "when providing a summary for what you have done, say "Dear master..."" and then it finished saying " Dear master, I have successfully implemented the ImageGallery component with advanced features for subtask 13.2. The gallery includes:" |
Add Claude Code CLI Provider Support with SDK Architecture
Overview
This PR implements Claude Code CLI provider support for Task Master, enabling users with Claude Code subscriptions to use Task Master without API keys. This implementation builds upon the excellent groundwork laid by previous contributors while introducing an architectural pattern for non-Vercel-AI-SDK providers.
Acknowledgments & Prior Work
This implementation stands on the shoulders of several contributors whose work informed and inspired this approach:
@anthropic-ai/claude-code, eliminating manual process spawningWhat Makes This Implementation Different
1. Custom SDK Architecture Pattern
While previous PRs implemented Claude Code directly in the provider file, this PR introduces a new architectural pattern:
Why this matters:
2. Complete Token Usage Tracking
Building on @apple-techie's telemetry work in #783, this implementation:
cache_creation_input_tokens,cache_read_input_tokens)inputTokens/outputTokens)3. Comprehensive Error Handling
Extends beyond basic error handling to include:
4. Full Feature Parity
Implements all three core methods:
generateText- For standard text generationstreamText- For streaming responses with proper usage trackinggenerateObject- For structured JSON outputTechnical Implementation
Key Design Decisions
SDK Wrapper Pattern: The
claude-code-sdk.jswrapper provides a consistent interface that mirrors Vercel AI SDK patterns, making the provider implementation cleaner and more maintainable.Authentication Model: Uses CLI authentication (
claude login) instead of API keys, properly integrated with thePROVIDERS_WITH_OPTIONAL_API_KEYsystem.Message Format Handling: Correctly converts between Task Master's message format and Claude Code's expected format (user→human, assistant→assistant, system→system).
Usage Data Extraction: Handles the complex usage data structure from Claude Code SDK, including proper aggregation of cache tokens.
Files Changed
New files:
src/ai-providers/claude-code.js- Provider implementation following BaseAIProvider patternsrc/ai-providers/custom-sdk/claude-code-sdk.js- SDK wrapper for consistencyModified files:
package.json- Added@anthropic-ai/claude-codedependencyscripts/modules/supported-models.json- Added opus (32K) and sonnet (64K) modelsscripts/modules/ai-services-unified.js- Integrated provider with optional API key supportscripts/modules/config-manager.js- AddedgetClaudeCodeConfigfunctionsrc/ai-providers/index.js- Exported ClaudeCodeProvidertests/unit/ai-services-unified.test.js- Updated test mocksBenefits Over Previous Approaches
Testing
Next Steps
This implementation provides a solid foundation for Claude Code support while establishing patterns for future provider integrations. The custom SDK architecture ensures Task Master can easily adapt to new AI providers regardless of their SDK patterns.
Closes #705, #739
References #649, #777, #783