Foundry.ClaudeCodeProvider (foundry v0.2.0)

Copy Markdown

Spawns Claude Code CLI as a subprocess and streams LLM responses.

Claude Code acts as the inference engine with its own tools (Bash, Read, Grep, etc.). Foundry provides domain context via the system prompt.

Uses claude -p headless mode with --output-format stream-json for streaming. No API key required — Claude Code uses browser OAuth authentication.

See ADR-025 for the full specification.

Summary

Functions

Runs a conversation through Claude Code CLI.

Runs a conversation through Claude Code CLI and calls on_event as text arrives.

Functions

chat(messages, opts \\ [])

Runs a conversation through Claude Code CLI.

Options

  • :system_prompt — Foundry's system prompt (AGENTS.md content, stack versions, etc.)
  • :timeout_ms — Max wait time in milliseconds (default: 120_000)
  • :model — Model override (nil = Claude Code default)
  • :project_root — Working directory for Claude Code's tools

Returns

{:ok, text, metadata} — text response and metadata {:error, reason} — if Claude Code is not installed or fails

stream(messages, opts \\ [], on_event)

Runs a conversation through Claude Code CLI and calls on_event as text arrives.

Events are:

  • {:delta, text} — newly streamed assistant text
  • {:result, text, metadata} — final successful response