Skip to content

Latest commit

 

History

History
243 lines (178 loc) · 6.65 KB

File metadata and controls

243 lines (178 loc) · 6.65 KB
title Claude CLI
description Use Claude Code CLI as an external agent in PraisonAI
icon message-bot

Overview

For programmatic use inside a Python Agent, see [CLI Backend](/docs/features/cli-backend).

Using Claude Model for Creative Tasks

Claude Code CLI is Anthropic's AI-powered coding assistant that can read files, run commands, search the web, edit code, and more. PraisonAI integrates with Claude CLI to use it as an external agent.

Installation

# Install Claude Code CLI
curl -fsSL https://claude.ai/install.sh | bash

# Or using npm
npm install -g @anthropic-ai/claude-code

Authentication

Set your Anthropic API key:

export ANTHROPIC_API_KEY=your-api-key

Or authenticate via Claude subscription:

claude setup-token

Basic Usage with PraisonAI

`--external-agent claude` invokes Claude CLI via a manager Agent by default. The manager reasons and calls Claude as a subagent tool. Use `--external-agent-direct` for pass-through proxy behavior.
# Manager delegation (default — manager reasons + calls claude as subagent tool)
praisonai "Fix the bug in auth.py" --external-agent claude

# Direct proxy (escape hatch — no manager, passes prompt straight to claude)
praisonai "Fix the bug in auth.py" --external-agent claude --external-agent-direct

# With verbose output
praisonai "Refactor this module" --external-agent claude --verbose

CLI Options Reference

Print Mode (Non-Interactive)

Option Description
-p, --print Print response and exit (useful for pipes/scripts)
--output-format <format> Output format: text (default), json, or stream-json
--include-partial-messages Include partial message chunks (with stream-json)
--input-format <format> Input format: text (default) or stream-json

Model Selection

Option Description
--model <model> Model alias (sonnet, opus) or full name (claude-sonnet-4-5-20250929)
--fallback-model <model> Fallback model when default is overloaded

System Prompts

Option Description
--system-prompt <prompt> Custom system prompt for the session
--append-system-prompt <prompt> Append to default system prompt (recommended)

Tool Control

Option Description
--allowedTools <tools> Comma-separated list of allowed tools (e.g., Bash,Edit,Read)
--disallowedTools <tools> Comma-separated list of denied tools
--tools <tools> Specify available tools: "" (none), default (all), or specific names

Permission Modes

Option Description
--permission-mode <mode> Permission mode for the session
--dangerously-skip-permissions Bypass all permission checks (use with caution)

Permission Mode Values:

  • default - Standard permission behavior
  • acceptEdits - Auto-accept file edits
  • bypassPermissions - Bypass all permission checks
  • plan - Planning mode (no execution)
  • delegate - Delegate decisions
  • dontAsk - Don't ask for permissions

Session Management

Option Description
-c, --continue Continue the most recent conversation
-r, --resume [value] Resume by session ID or open picker
--fork-session Create new session ID when resuming
--no-session-persistence Disable session persistence
--session-id <uuid> Use specific session ID

Budget & Limits

Option Description
--max-budget-usd <amount> Maximum dollar amount for API calls

MCP Integration

Option Description
--mcp-config <configs> Load MCP servers from JSON files
--strict-mcp-config Only use MCP servers from --mcp-config

Additional Options

Option Description
--add-dir <directories> Additional directories for tool access
--verbose Override verbose mode setting
--debug Enable debug mode
--json-schema <schema> JSON Schema for structured output validation
--agents <json> JSON object defining custom agents
--settings <file-or-json> Path to settings JSON file

Commands

Command Description
claude mcp Configure and manage MCP servers
claude plugin Manage Claude Code plugins
claude setup-token Set up authentication token
claude doctor Check auto-updater health
claude update Check for and install updates
claude install [target] Install native build

Examples

Basic Query

# Simple question
praisonai "What files are in this directory?" --external-agent claude

# Code analysis
praisonai "Analyze the code quality of src/" --external-agent claude

With Tool Restrictions

# Allow only read operations
claude -p --allowedTools "Read,Glob,Grep" "Find all TODO comments"

# Deny bash access
claude -p --disallowedTools "Bash" "Review this code"

With Custom System Prompt

claude -p --append-system-prompt "You are a Python expert" "Optimize this function"

JSON Output

claude -p --output-format json "List all functions in main.py"

Continue Session

# Start a session
claude "Create a new feature"

# Continue the session
claude -c "Now add tests for it"

Python Integration

from praisonai.integrations import ClaudeCodeIntegration

# Create integration
claude = ClaudeCodeIntegration(
    workspace="/path/to/project",
    output_format="json",
    model="sonnet"
)

# Execute a task
result = await claude.execute("Refactor the auth module")
print(result)

# Stream output
async for event in claude.stream("Add error handling"):
    print(event)

Environment Variables

Variable Description
ANTHROPIC_API_KEY Anthropic API key
CLAUDE_API_KEY Alternative API key variable

Built-in Tools

Claude Code includes these built-in tools:

Tool Description
Read Read any file in the working directory
Write Create new files
Edit Make precise edits to existing files
Bash Run terminal commands, scripts, git operations
Glob Find files by pattern
Grep Search file contents with regex
WebSearch Search the web for information
WebFetch Fetch and parse web page content

Related