[PR #1749] [CLOSED] feat: set AGENT=1 environment variable to identify AI agent execution #10047

Closed
opened 2026-02-16 18:14:36 -05:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/anomalyco/opencode/pull/1749
Author: @swen128
Created: 8/9/2025
Status: Closed

Base: devHead: feat/add-agent-env-var


📝 Commits (1)

  • 28b8bc8 feat: set AGENT=1 environment variable to identify AI agent execution

📊 Changes

1 file changed (+3 additions, -0 deletions)

View changed files

📝 packages/opencode/src/index.ts (+3 -0)

📄 Description

Summary

Sets the env var AGENT=1 at startup to identify when processes are run by an AI agent.

Context

Claude Code Implementation

Claude Code sets CLAUDECODE=1 environment variable for similar purposes. This is useful when you want to:

  • Block AIs from touching certain sensitive scripts
  • Enable stricter pre-commit hooks when code is being modified by AI
  • Provide clear identification of AI-driven operations

Bun Test Integration

Bun's test runner already supports AI agent detection through the AGENT=1 environment variable:


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/anomalyco/opencode/pull/1749 **Author:** [@swen128](https://github.com/swen128) **Created:** 8/9/2025 **Status:** ❌ Closed **Base:** `dev` ← **Head:** `feat/add-agent-env-var` --- ### 📝 Commits (1) - [`28b8bc8`](https://github.com/anomalyco/opencode/commit/28b8bc8d3593d1f0fb6ef2a814b0fe16c27e6246) feat: set AGENT=1 environment variable to identify AI agent execution ### 📊 Changes **1 file changed** (+3 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `packages/opencode/src/index.ts` (+3 -0) </details> ### 📄 Description ## Summary Sets the env var `AGENT=1` at startup to identify when processes are run by an AI agent. ## Context ### Claude Code Implementation Claude Code sets `CLAUDECODE=1` environment variable for similar purposes. This is useful when you want to: - Block AIs from touching certain sensitive scripts - Enable stricter pre-commit hooks when code is being modified by AI - Provide clear identification of AI-driven operations ### Bun Test Integration Bun's test runner already supports AI agent detection through the `AGENT=1` environment variable: - When `AGENT=1` is detected, Bun shows concise, AI-friendly test reports - This improves the AI's ability to parse and understand test results - Documentation: https://bun.com/docs/cli/test#ai-agent-integration --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-02-16 18:14:36 -05:00
yindo closed this issue 2026-02-16 18:14:36 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#10047