Documentation
¶
Overview ¶
Package aiagent tells whether an AI coding agent is driving the CLI, so the CLI can declare it on every request and open an agent session for it.
Detection reads the environment only: no subprocess and no process walk. An agent sets its markers in the shells it spawns, and they survive a tmux or daemon in between where a parent-process chain does not. Signals a person meets every day never count: no TTY, CI, an editor's integrated terminal (TERM_PROGRAM), CLAUDECODE on its own (set in people's editor terminals by Claude Code's IDE extensions), REPL_ID, GOOSE_PROVIDER, and AGENT with any value but goose. There is no setting that turns detection off.
Index ¶
Constants ¶
const ( // NameHeader carries the canonical name of the detected agent. NameHeader = "X-Alpacon-Declared-Agent-Name" // VersionHeader carries the agent's version, only when the environment // states one. VersionHeader = "X-Alpacon-Declared-Agent-Version" // EnvAIAgent is the cross-agent variable: any agent, including one with no // marker of its own, can set AI_AGENT=<name> to be detected. EnvAIAgent = "AI_AGENT" )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Detection ¶
type Detection struct {
// Name is the canonical agent name, empty when no agent was detected.
Name string
// Version is the agent's version, empty when the environment carries none.
Version string
// Markers lists every variable that marked an agent, in table order. It
// holds every match, not only the one that named the agent, because a
// person taken for an agent has to unset all of them.
Markers []string
}
Detection is what the environment says about the agent driving the CLI.
func Detect ¶
func Detect(lookup LookupFunc) Detection
Detect reads the environment through lookup and returns the agent it names.
func FromEnvironment ¶
func FromEnvironment() Detection
FromEnvironment detects the agent from the process environment. It is cheap enough to call per request, which keeps it free of process-wide state.
func (Detection) Describe ¶
Describe names the agent and every marker that found it, for messages: "claude-code (from AI_AGENT, CLAUDE_CODE_CHILD_SESSION)".
func (Detection) SetHeaders ¶
SetHeaders adds the declaration headers to h. It adds nothing when no agent was detected. When the version is unknown it sends no version header and removes one a caller supplied, so the version is only ever the one the environment stated.
type LookupFunc ¶
LookupFunc reads one environment variable, like os.LookupEnv.