feat(models): Claude CLI provider for Pro/Max subscription users#1434
Open
mhooooo wants to merge 1 commit intobytedance:mainfrom
Open
feat(models): Claude CLI provider for Pro/Max subscription users#1434mhooooo wants to merge 1 commit intobytedance:mainfrom
mhooooo wants to merge 1 commit intobytedance:mainfrom
Conversation
Adds `ClaudeCLIModel`, a LangChain `BaseChatModel` that wraps the
Claude Code CLI in `--print` mode. This enables DeerFlow users with
a Claude Pro or Max subscription to use DeerFlow without an API key
at zero additional cost.
Authentication is handled by the CLI's built-in auth (`claude /login`),
which stores credentials in the OS keychain. No `ANTHROPIC_API_KEY`
environment variable is needed.
The provider:
- Spawns `claude --print --output-format json` as a subprocess
- Implements `bind_tools()` for LangGraph agent compatibility
- Parses JSON output including token usage and cost metadata
- Filters environment variables that interfere with the subprocess
- Supports configurable model, max_turns, permission_mode, and timeouts
Config example:
models:
- name: claude-sonnet
display_name: Claude Sonnet 4.6 (Max subscription)
use: deerflow.models.claude_cli_provider:ClaudeCLIModel
model: claude-sonnet-4-6
max_tokens: 16384
Collaborator
|
@mhooooo, thanks for the contribution. You need to sign the CLA by clicking the button before we can review it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
ClaudeCLIModel— a new LangChainBaseChatModelprovider that wraps the Claude Code CLI in--printmode. This enables DeerFlow users with a Claude Pro or Max subscription to run DeerFlow without an API key at zero additional API cost.Problem
Currently, using Claude with DeerFlow requires either:
ANTHROPIC_API_KEY(pay-per-token), orClaudeChatModelwith OAuth tokens — which returns400 invalid_request_errorbecause OAuth tokens are scoped to Claude Code sessions and don't work with direct Messages API callsMany users already have Claude Pro ($20/mo) or Max ($100-200/mo) subscriptions with generous usage included. There's no way to leverage these subscriptions with DeerFlow today.
Solution
ClaudeCLIModelspawnsclaude --print --output-format jsonas a subprocess, which authenticates using the CLI's built-in auth (claude /login). The CLI handles token management, refresh, and all API communication internally.Config:
Prerequisites:
curl -fsSL https://claude.ai/install.sh | bash claude /loginFeatures
BaseChatModel— works with LangGraph agents out of the boxbind_tools()support — tool schemas injected into system prompt for LangGraph compatibilityCLAUDECODE,NODE_OPTIONS, etc.) from subprocessclaudeCLI from$PATHor well-known install locationsTested with
Test plan
ClaudeCLIModel.invoke([HumanMessage("What is 2+2?")])→"4"/threads/{id}/runs/streambind_tools()with DeerFlow's built-in tools (bash, file ops, web search)🤖 Generated with Claude Code