docs/claude-code-integration.md
This guide covers how to use Task Master with Claude Code AI SDK integration for enhanced AI-powered development workflows.
Claude Code integration allows Task Master to leverage the Claude Code CLI for AI operations without requiring direct API keys. The integration uses OAuth tokens managed by the Claude Code CLI itself.
The Claude Code provider uses token authentication managed by the Claude Code CLI.
Install Claude Code CLI (if not already installed):
# Installation method depends on your system
# Follow Claude Code documentation for installation
Set up OAuth token using Claude Code CLI:
claude setup-token
This command will:
Task Master will attempt authentication in this order:
Environment Variable (optional): CLAUDE_CODE_OAUTH_TOKEN
Claude Code CLI Token (recommended): Token managed by claude setup-token
Fallback: Error if neither is available
Add Claude Code to your Task Master configuration:
// In your .taskmaster/config.json or via task-master models command
{
"models": {
"main": "claude-code:sonnet", // Use Claude Code with Sonnet
"research": "perplexity-llama-3.1-sonar-large-128k-online",
"fallback": "claude-code:opus" // Use Claude Code with Opus as fallback
}
}
claude-code:sonnet - Claude 3.5 Sonnet via Claude Code CLIclaude-code:opus - Claude 3 Opus via Claude Code CLIWhile not required, you can optionally set:
export CLAUDE_CODE_OAUTH_TOKEN="your_oauth_token_here"
This is only needed in specific scenarios like:
# Use Claude Code for task operations
task-master add-task --prompt="Implement user authentication system" --research
task-master expand --id=1 --research
task-master update-task --id=1.1 --prompt="Add JWT token validation"
# Set Claude Code as main model
task-master models --set-main claude-code:sonnet
# Use interactive setup
task-master models --setup
# Then select "claude-code" from the provider list
Problem: Task Master cannot connect to Claude Code CLI.
Solutions:
claude setup-token to configure authenticationclaude --helpProblem: Token authentication is failing.
Solutions:
claude setup-token to refresh your OAuth tokenclaude commandProblem: Specified Claude Code model is not supported.
Solutions:
sonnet or opustask-master models --listTest Claude Code CLI directly:
claude --help
# Should show help without errors
Test authentication:
claude setup-token --verify
# Should confirm token is valid
Test Task Master integration:
task-master models --test claude-code:sonnet
# Should successfully connect and test the model
Check logs:
--verbose flag for more detailed outputWhen running in Docker, you'll need to:
Install Claude Code CLI in your container
Set up authentication via environment variable:
ENV CLAUDE_CODE_OAUTH_TOKEN="your_token_here"
For automated environments:
Task Master's Claude Code integration uses the official ai-sdk-provider-claude-code package, providing:
As of ai-sdk-provider-claude-code v2.2.0, Claude Code supports native structured outputs via the Claude Agent SDK's outputFormat option. This provides significant benefits for Task Master's structured data generation:
When Task Master calls generateObject() or streamObject() with a Zod schema, the Claude Code provider:
mode: 'json' (via needsExplicitJsonSchema = true)outputFormat: { type: 'json_schema', schema: ... }structured_output with guaranteed schema complianceimport { z } from 'zod';
import { generateObjectService } from './scripts/modules/ai-services-unified.js';
// Define your schema
const taskSchema = z.object({
title: z.string().min(1),
description: z.string().min(1),
priority: z.enum(['high', 'medium', 'low']),
dependencies: z.array(z.number().int())
});
// Generate structured output - guaranteed to match schema
const result = await generateObjectService({
role: 'main', // Uses Claude Code if configured as main provider
schema: taskSchema,
objectName: 'task',
prompt: 'Create a task for implementing user authentication',
systemPrompt: 'You are a task planning assistant.',
commandName: 'add-task',
outputType: 'cli'
});
// result.mainResult is guaranteed to match taskSchema
console.log(result.mainResult);
// { title: "...", description: "...", priority: "high", dependencies: [] }
All Task Master commands that generate structured data benefit from native schema support:
parse-prd - Parsing PRD documents into tasksadd-task - Creating new tasksexpand-task - Expanding tasks into subtasksupdate-tasks - Batch updating tasksupdate-task-by-id - Updating individual tasksanalyze-complexity - Analyzing task complexityimport { generateText } from 'ai';
import { ClaudeCodeProvider } from './src/ai-providers/claude-code.js';
const provider = new ClaudeCodeProvider();
const client = provider.getClient();
const result = await generateText({
model: client('sonnet'),
messages: [
{ role: 'user', content: 'Hello Claude!' }
]
});
console.log(result.text);
If you encounter issues:
claude setup-token --verify