Skip to content

API Reference parrot.agents.claude_code

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.agents.claude_code

View source

Claude Code-backed agent target for the Agent CLI Daemon (agentd).

Serves an :class:~parrot.bots.agent.Agent whose LLM is a :class:~parrot.clients.anthropic.claude_agent.ClaudeAgentClient, so every turn is delegated to a local Claude Code sub-agent authenticated with the credentials the bundled claude CLI already holds (claude auth / claude.ai login) rather than an ANTHROPIC_API_KEY.

Usage::

PARROT_CLAUDE_USE_CC_AUTH=1 parrot serve examples/agents/claude_code_daemon.yaml
parrot ask claude-code "What is 2 + 2?"
parrot attach claude-code

Two environment hazards this factory works around — both are properties of how ai-parrot boots, not of claude-agent-sdk:

  1. Importing parrot loads the navconfig settings/ tree into os.environ, which injects the INI section headers ([aws], [google], …) as environment variable names. The bundled Node claude CLI refuses to start with those present, and the SDK surfaces it only as an empty CLIConnectionError: Failed to start Claude Code:. :func:sanitize_claude_environment strips them.

  2. The same settings tree usually exports ANTHROPIC_API_KEY, and the CLI gives an API key precedence over the claude.ai login — billing would silently move to the API key. This target therefore drops the API-key variables by default so the Claude Code credentials win. The CLI confirms the choice in its init message: apiKeySource: "none" plus a five_hour rate-limit event means the claude.ai login; apiKeySource: "ANTHROPIC_API_KEY" means a key took over. Set PARROT_CLAUDE_USE_CC_AUTH=0 (or force_cc_auth=False) to bill an API key instead.

FEAT-434 (Claude Agent Tool Bridge): this factory is the reference integration parrot serve exercises for the bridged-HITL wiring (TASK-2290). The daemon (AgentDaemon._configure_hitl, parrot.integrations.agentd.service) attaches a ConfirmationGuard to whatever agent make_agent() returns — nothing here has to build one itself. Any confirming tool the agent registers is therefore already bridged through the real HITL channel (never Telegram, never self-granted) once served this way.

Function make_agent

Build a Claude Code-backed agent for parrot serve.

Sanitises the environment, then constructs the agent. Pass llm="claude-agent:<model>" (or "claude-code:<model>") so the bot resolves a :class:ClaudeAgentClient; any other llm value yields an ordinary agent and the Claude Code delegation is lost.

make_agent(force_cc_auth: bool | None = None, **kwargs: Any) -> Agent

Parameter Type Default Description
force_cc_auth bool | None None Whether to drop ANTHROPIC_API_KEY / ANTHROPIC_AUTH_TOKEN so the CLI uses its Claude Code login. None (the default) reads PARROT_CLAUDE_USE_CC_AUTH, which itself defaults to on — set it to "0" to bill an API key instead.
**kwargs Any {} Forwarded verbatim to :class:~parrot.bots.agent.Agent (name, llm, system_prompt, …). Supplied by the agentd YAML's agent.kwargs.

Returns: Agent — A configured :class:~parrot.bots.agent.Agent. parrot serve awaits its configure() afterwards, which is where the LLM client is actually instantiated.

Function sanitize_claude_environment

Remove env entries that break (or hijack) the bundled claude CLI.

sanitize_claude_environment(force_cc_auth: bool = True) -> dict[str, list[str]]

Parameter Type Default Description
force_cc_auth bool True When True (the default), also drop the API-key variables so the CLI falls back to its stored claude.ai / Claude Code login. Pass False to bill an API key instead.

Returns: dict[str, list[str]] — Mapping with two keys: invalid — names dropped for being unusable as environment variable names — and auth — API-key variables dropped to force Claude Code credentials.

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally