aiagent

package
v1.16.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 18, 2026 License: MIT Imports: 5 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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

func Variables

func Variables() []string

Variables lists every environment variable detection reads, in table order.

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

func (d Detection) Describe() string

Describe names the agent and every marker that found it, for messages: "claude-code (from AI_AGENT, CLAUDE_CODE_CHILD_SESSION)".

func (Detection) Detected

func (d Detection) Detected() bool

Detected reports whether an agent was found.

func (Detection) SetHeaders

func (d Detection) SetHeaders(h http.Header)

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

type LookupFunc func(key string) (string, bool)

LookupFunc reads one environment variable, like os.LookupEnv.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL