feat: Add Claude Code SDK patterns as provider for API-Key-Free Usage#777
feat: Add Claude Code SDK patterns as provider for API-Key-Free Usage#777neno-is-ooo wants to merge 17 commits intoeyaltoledano:nextfrom
Conversation
🦋 Changeset detectedLatest commit: 9770c72 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 |
Crunchyman-ralph
left a comment
There was a problem hiding this comment.
lgtm, just want a better provider, but I think this is really close!
|
No ability to specify opus vs sonnet models? |
|
Yeah I would prefer to see it work this way too, ideally.... |
|
Yeah, would love to see it do something like this... https://gist.github.com/ben-vargas/50c628bd8e61b4c9d971bcc226a2ae93 |
added it! about to push.. |
Release 0.17.0
…changeset-release/main Version Packages
4af76b8 to
e13bae7
Compare
|
Is this fully compatible with 0.17? |
it regressed so now I'm fixing it again :) |
- Add detailed integration guide in docs/claude-code-integration.md - Update CHANGELOG.md with unreleased Claude Code provider changes - Add PR_SUMMARY.md for PR eyaltoledano#777 overview - Document OAuth2 authentication, provider/model format, and migration guide
- Add new claude-code provider using official @anthropic-ai/claude-code SDK - Skip API key validation for claude-code provider (similar to ollama) - Add claude-code to supported models configuration - Export ClaudeCodeProvider from ai-providers index - Include comprehensive unit tests with proper mocking to avoid circular dependencies - Enable Task Master usage without API keys via Claude Code subscription BREAKING CHANGE: None - This is purely additive Implementation approach: Unlike previous attempts that spawned the Claude CLI directly and handled stdin/stdout streams, this implementation uses the official Claude Code SDK's JavaScript API. The SDK provides: - Async iterator pattern for message handling - Structured SDKMessage types (system, assistant, result) - Built-in authentication management - Automatic process lifecycle handling This approach eliminates the need for: - Manual process spawning and stream management - Temporary file creation and cleanup - Platform-specific path handling - Custom readline interfaces for streaming The provider integrates seamlessly with Task Master's existing provider architecture while leveraging the SDK's native capabilities. Tested with: - All unit tests passing (10/10 tests) - 84% code coverage for the provider - Proper error handling for SDK not installed and auth failures - JSON parsing with markdown code block support - Streaming text generation capabilities 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- Update mocking strategy to use jest.unstable_mockModule - Handle cases where @anthropic-ai/claude-code module exists globally - Add proper message content for authentication error test - All 10 tests now passing with proper coverage
- Simplify mocking approach by directly mocking loadSDK method - Remove dependency on @anthropic-ai/claude-code module existing - Tests now pass in all environments regardless of module availability - Maintain full test coverage for all provider functionality
- Add claude-code to providers that don't require API keys (like ollama) - Update isApiKeySet() to return true for claude-code - Update getMcpApiKeyStatus() to handle claude-code - Update ai-services-unified keyMap and resolution logic - Claude Code uses OAuth2 through CLI instead of API keys This enables Task Master users to use their Claude Code flat-fee subscription
- Fix SDK import path to use correct module - Add AbortController support to all methods - Implement accurate token usage tracking from SDK - Add proper model selection with Claude Opus 4 default - Add generateTextWithTools method for function calling - Improve error messages with clear installation guidance - Update tests to cover all new functionality (18 tests passing) - Add changeset for release The provider now properly integrates with the Claude Code SDK without requiring API keys, using the same authentication as Claude desktop app.
- Add separate opus and sonnet models in supported-models.json - Implement model mapping logic (claude-code → opus by default) - Fix telemetry to show actual model used (e.g. claude-opus-4-20250514) - Fix cost display to show 'Free' for all claude-code models - Update config saving to store mapped model IDs - Ensure consistency across all model displays This allows users to select between different Claude models while maintaining the free OAuth2 authentication through Claude Code.
- Remove confusing claude-code, claude-code-sonnet, claude-code-opus entries - Keep only actual model IDs (claude-opus-4-20250514, claude-sonnet-4-20250514) - Add support for provider/model format (e.g., claude-code/claude-opus-4-20250514) - Fix cost display to always show 'Free' for claude-code provider - Fix model lookup to match both provider and model ID - Remove 'Unknown provider' warnings for claude-code This makes claude-code work like openai/openrouter pattern where the same model can be accessed through different providers with different billing mechanisms.
- Add example showing claude-code/model format for free tier - Add example showing anthropic/model format for API usage - Makes it clear how to choose between providers for same model
- Add detailed integration guide in docs/claude-code-integration.md - Update CHANGELOG.md with unreleased Claude Code provider changes - Add PR_SUMMARY.md for PR eyaltoledano#777 overview - Document OAuth2 authentication, provider/model format, and migration guide
b8ca318 to
15cafb0
Compare
- Fix claude-code.test.js to expect defaultModel: 'claude-code' - Add ClaudeCodeProvider mock to ai-services-unified.test.js - Add 'claude-code' to VALID_PROVIDERS in test mock All tests now pass with 100% success rate. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
2799329 to
60c7397
Compare
|
There's an issue with researching using claude-code. Here is what I saw: When running: With the research model set as ---
title: Research Session
query: "Document ways to use the official claude-code package instead of manually spawning sub processing. Focus only on typescript. https://docs.anthropic.com/en/docs/claude-code/sdk"
date: 6/16/2025
time: 1:44:34 PM
timestamp: 2025-06-16T16:44:34.772Z
exchanges: 1
---
# Research Session
## Initial Query
**Question:** Document ways to use the official claude-code package instead of manually spawning sub processing. Focus only on typescript. https://docs.anthropic.com/en/docs/claude-code/sdk
**Response:**
I'll research how to use the official claude-code SDK package instead of manually spawning subprocesses in TypeScript.
---
*Generated by Task Master Research Command*
*Timestamp: 2025-06-16T16:44:34.772Z*If I switch to I tried adding the Simplifying the command to Otherwise, this is working great so far! Thank you for taking the time to implement this! |
|
If you're feeling adventurous @germanoeich - I'd be curious if this approach passes your testing and provides better result for It takes a little different approach of implementing a Vercel AI SDK custom community provider and then uses the BaseAIProvider class like the other providers defined in Task Master. In my test, it seems to respond fine to research commands when I tested. https://github.com/ben-vargas/ai-claude-task-master/tree/feature/claude-code-sdk |
|
@ben-vargas I tested your branch and found no issues with research or any other features, I parsed a prd, expanded tasks, performed research, task updates, etc all using claude-code and everything is working perfectly! |
|
Thanks @germanoeich - I've submitted it as #805 after making a few scope changes as it was overstepping its scope modifying the config.json setup (there's an issue where maxTokens doesn't update correctly, but I pulled that fix out of the PR as it probably warrants a dedicated PR). The maxTokens and temperature parameters are not support by claude code anyway, so it doesn't really need to be in the PR implementing claude code. |
|
closing this in favour of #805 |
- Enable Claude Code provider to work without API keys - Add comprehensive tag management functionality - Enhance task expansion with context gathering and fuzzy search - Update model documentation with latest pricing - Add research capabilities and improved MCP tools - Resolve conflicts in models.md and expand-task.js imports
Summary
This PR introduces a new AI provider (
claude-code) that integrates with the official Claude Code SDK, enabling Task Master users to leverage their Claude Code subscription without needing API keys.Motivation
Many developers already have Claude Code (formerly Claude.ai) subscriptions but need separate API keys to use Task Master. This integration bridges that gap by using the locally authenticated Claude Code SDK, making Task Master accessible to more users without additional costs.
Changes
claude-codeprovider insrc/ai-providers/claude-code.jsclaude-codeprovider (similar toollama)claude-codeto supported models configurationImplementation Details
The provider uses the official
@anthropic-ai/claude-codeSDK and:claude auth login)Testing
task-master parse-prd- Successfully generates tasks from PRDtask-master expand- Expands tasks into subtaskstask-master add-task- Adds new tasks with AI assistanceUsage
Benefits
Breaking Changes
None. This is a purely additive feature that doesn't affect existing functionality.
Dependencies
@anthropic-ai/claude-codeSDK (peer dependency)Implementation Strategy vs Previous Attempts
Previous PR #649 took a CLI-based approach that:
claudeCLI process directlyThis implementation instead:
@anthropic-ai/claude-codeSDK's JavaScript APITechnical Notes
SDKMessagetypes withsystem,assistant, andresultmessage typesFixes #[issue-number] (if applicable)