Documentation
¶
Overview ¶
Package claude runs the Claude Code CLI as an agent.Backend: a read-only model call loop over a directory whose final answer is a JSON document.
Index ¶
- Constants
- func SignedIn(ctx context.Context, binary string) (signedIn, known bool)
- type Backend
- func (c *Backend) Check(ctx context.Context) (version string, err error)
- func (c *Backend) Complete(ctx context.Context, request agent.CompleteRequest) (agent.Completion, error)
- func (c *Backend) ConcurrentCalls() bool
- func (c *Backend) Fix(ctx context.Context, request agent.Request) (agent.Result, error)
- func (*Backend) Name() string
- func (c *Backend) Run(ctx context.Context, request agent.Request) (agent.Result, error)
- type Profile
Constants ¶
const CompleteMaxTurns = 2
CompleteMaxTurns bounds a completion's model calls. Claude Code ends the run once a StructuredOutput call is accepted, so a completion normally makes one call; the second turn lets the model submit once more after the harness rejected its reply against the schema, and no further retry is made.
const MinimumVersion = "2.1.248"
MinimumVersion is the oldest Claude Code the User profile runs: the first release whose argument parser accepts every flag args and fixArgs pass. Found with the agent version matrix (scripts/agent-matrix): 2.1.247 refuses --restricted ("unknown option") and 2.1.248 accepts every argument of a review, a resumed or forked session, a fix and a completion. Older 2.1 releases lack --effort (2.1.0 to 2.1.32 at least) or --restricted.
Variables ¶
This section is empty.
Functions ¶
func SignedIn ¶
SignedIn asks Claude Code whether it is signed in, with the environment a run in the User profile gets: a claude.ai or Console sign-in, an API key helper or a key in its settings counts, a provider key in baum's own environment does not, since a run never sees it. known is false when the answer could not be read, as from a Claude Code without `auth status`.
Types ¶
type Backend ¶
type Backend struct {
// Binary is the claude executable. The User profile resolves it with
// exec.LookPath and defaults to "claude".
Binary, Model string
Profile Profile
// Effort is the --effort level; empty leaves it to
// Claude Code. The User profile leaves thinking to Claude Code, while the
// Isolated profile always runs without thinking.
Effort string
// DefaultEndpoint is a provider key and base URL used when the request has
// no Endpoint of its own. The hosted review agent never sets it: its runs
// bring a model proxy endpoint. Local prompt evaluation sets it because it
// runs on a developer's host without a proxy.
DefaultEndpoint *agent.Endpoint
// Env are the user's agent variables (agent.WithUserEnv), for the User
// profile only.
Env []string
// contains filtered or unexported fields
}
Backend runs the Claude Code CLI over a request's directory.
The child runs in its own process group, so a terminal's Ctrl-C (SIGINT) does not reach it. A local caller must cancel the context it passes to Run on SIGINT and SIGTERM, for example with signal.NotifyContext, or the CLI keeps running after baum exits. Cancelling kills the group on Unix, and on Windows only the child itself.
func (*Backend) Check ¶
Check resolves the executable and checks its version, as the first Run does, and returns the installed version. Only the User profile has a check; the Isolated profile returns "" and nil. A host calls it before assembling anything, so a missing or old installation fails at once instead of as a provider failure retried by the loop.
func (*Backend) Complete ¶
func (c *Backend) Complete(ctx context.Context, request agent.CompleteRequest) (agent.Completion, error)
Complete runs Claude Code once with no tools but the StructuredOutput tool --json-schema registers (agent.Completer): the request's system prompt, no settings, plugins, MCP servers or hooks, no session persisted, in an empty temporary directory. The prompt goes on stdin and starts with sessions.GenerationRunMarker, so session discovery leaves the run out should it be recorded after all. Only the User profile completes.
func (*Backend) ConcurrentCalls ¶
ConcurrentCalls reports whether calls may run over one run directory at once (agent.ConcurrentCaller): the User profile passes the schema on the command line and writes nothing per call, as the user running Claude Code twice would. The Isolated profile shares one HOME and CLAUDE_CONFIG_DIR under the run directory between its calls, so it runs them one at a time.
func (*Backend) Fix ¶
Fix runs Claude Code with write access to the request's directory, for a fix a person asked for (agent.Fixer). It runs in restricted mode with the file tools only (Read, Glob, Grep, Edit and Write), confined to the directory: it cannot run a command, so it cannot run tests, git or anything else, and the caller commits what it changed. Its final message is the result's Document. Only the User profile fixes.
type Profile ¶
type Profile int
Profile selects the environment and credentials the Claude Code process gets. Both profiles run it with the same read-only flags.
const ( // User is for local runs and the zero value. The process gets the user's // own HOME and login, an allowlisted copy of the environment // (agent.LocalEnvironment, plus CLAUDE_CONFIG_DIR) and the binary found on // PATH. A provider key and base URL are set only when the request or // DefaultEndpoint names an Endpoint. The installed version is checked // once before the first run. User Profile = iota // Isolated is for hosted and evaluation runs: HOME and CLAUDE_CONFIG_DIR // under <run>/home, a fixed PATH and the provider key and base URL from // the Endpoint, which it requires. It never inherits the caller's // environment, and it does not check the installed version. Isolated )