agentdetection

agentdetection is a small Go package for detecting whether a process is running under an AI coding agent and, when possible, identifying which agent.
It is based on supporting the proposal in agents.md issue #136, "Proposal: Standard AGENT=$agent environment variable for agent runtime detection".
Goal
The goal is to let CLI tools default to non-interactive behavior while still providing the extra context and actionable output that agent-driven workflows benefit from when appropriate.
Usage
package main
import (
"fmt"
"github.com/jehiah/agentdetection"
)
func main() {
if agentdetection.IsAgent() {
// ... use defaults appropriate for Agentic tools
}
}
Detection
| Project |
Variable |
Value |
| Standard |
AGENT |
agent name, true, or 1 |
| Standard |
AI_AGENT |
agent name, true, or 1 |
| Claude Code |
CLAUDECODE |
true or 1 |
| Cursor |
CURSOR_AGENT |
true or 1 |
| Gemini CLI |
GEMINI_CLI |
true or 1 |
| Codex CLI |
CODEX_SANDBOX |
any non-empty value |
| Augment |
AUGMENT_AGENT |
true or 1 |
| Cline |
CLINE_ACTIVE |
true or 1 |
| OpenCode |
OPENCODE_CLIENT |
true or 1 |
| TRAE AI |
TRAE_AI_SHELL_ID |
any non-empty value |
| Devin |
/opt/.devin |
file exists |
Agent() returns the detected agent name, or "" when no agent signal is present. IsAgent() returns whether any supported signal was detected.