Skip to content

feat(core): add vendor-neutral AGENT=gemini environment variable#21032

Closed
sw-square wants to merge 2 commits intogoogle-gemini:mainfrom
sw-square:swesterman-gemini.2026-03-03.add-agent-env-var
Closed

feat(core): add vendor-neutral AGENT=gemini environment variable#21032
sw-square wants to merge 2 commits intogoogle-gemini:mainfrom
sw-square:swesterman-gemini.2026-03-03.add-agent-env-var

Conversation

@sw-square
Copy link
Copy Markdown

@sw-square sw-square commented Mar 3, 2026

Summary

Add a vendor-neutral AGENT=gemini environment variable to all child processes spawned by Gemini CLI, alongside the existing GEMINI_CLI=1.

This allows downstream tools to detect they are being executed by an AI agent using a single, standardized variable — without needing to check for each agent's tool-specific variable (GEMINI_CLI, CLAUDECODE, CODEX_SANDBOX, CURSOR_AGENT, etc.).

Details

Key Changes

  • Adds exported constants AGENT_IDENTIFICATION_ENV_VAR (AGENT) and AGENT_IDENTIFICATION_ENV_VAR_VALUE (gemini) in shellExecutionService.ts
  • Sets AGENT=gemini in all three child process spawning paths:
    • child_process.spawn — fallback shell execution
    • PTY spawn — primary interactive shell execution
    • MCP stdio transport — MCP server child processes
  • Adds test assertions verifying the new variable in both PTY and child_process paths

Why a standard AGENT variable?

Every AI coding agent currently sets its own env var:

Agent Variable Value
Gemini CLI GEMINI_CLI 1
Claude Code CLAUDECODE 1
Codex CLI CODEX_SANDBOX seatbelt
Cursor CURSOR_AGENT 1
Goose GOOSE_TERMINAL 1
Amp (internal) -

This forces every downstream tool to maintain a detection matrix. A shared AGENT variable (analogous to CI=true) lets tools write one check:

if [[ -n "${AGENT:-}" ]]; then
  # Adapt behavior for AI agent execution
fi

The value (gemini) identifies which agent is running, enabling agent-specific behavior when needed.

Adoption

Goose (PR #7017) and Amp already ship AGENT=<name>. Consumer-side detection is already happening in Bun and Vercel.

See the standardization discussion at agentsmd/agents.md#136.

Related Issues

Relates to #17079

How to Validate

  1. Run Gemini CLI locally: npm start
  2. Ask it to execute: echo $AGENT
  3. Should output: gemini
  4. Run unit tests: npx vitest run packages/core/src/services/shellExecutionService.test.ts

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Added/updated tests (if needed)
  • Noted breaking changes (if any)
  • Validated on required platforms/methods:
    • MacOS
      • npm run

Add AGENT=gemini environment variable to all child processes spawned by
Gemini CLI, alongside the existing GEMINI_CLI=1. This provides a
vendor-neutral way for downstream tools to detect they are being
executed by an AI agent.

The AGENT env var is set in all three process spawning paths:
- child_process.spawn (fallback shell execution)
- PTY spawn (primary interactive shell execution)
- MCP stdio transport (MCP server child processes)

Relates to google-gemini#17079
@sw-square sw-square requested a review from a team as a code owner March 3, 2026 23:43
@google-cla
Copy link
Copy Markdown

google-cla bot commented Mar 3, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the Gemini CLI by introducing a standardized, vendor-neutral AGENT environment variable. This variable, set to gemini, allows any child process spawned by the CLI to signal its origin as an AI agent. The primary goal is to simplify detection for downstream tools, enabling them to adapt their behavior based on a single, consistent identifier rather than managing a diverse set of agent-specific environment variables. This promotes greater interoperability and a more unified approach to AI agent identification across different platforms.

Highlights

  • Vendor-Neutral Agent Identification: Introduced a new vendor-neutral AGENT=gemini environment variable to all child processes spawned by the Gemini CLI, complementing the existing GEMINI_CLI=1.
  • Standardization for Downstream Tools: This change allows downstream tools to detect AI agent execution using a single, standardized variable, eliminating the need to check for multiple agent-specific variables.
  • Comprehensive Integration: The AGENT=gemini variable is now set across all three child process spawning paths: child_process.spawn (fallback), PTY spawn (primary interactive shell), and MCP stdio transport (MCP server child processes).
  • Test Coverage: Added new test assertions to verify the correct propagation of the AGENT environment variable in both PTY and child_process execution paths.
Changelog
  • packages/core/src/services/shellExecutionService.test.ts
    • Added assertions to verify the presence and value of the AGENT environment variable in PTY and child process environments.
  • packages/core/src/services/shellExecutionService.ts
    • Defined new constants AGENT_IDENTIFICATION_ENV_VAR and AGENT_IDENTIFICATION_ENV_VAR_VALUE for the AGENT environment variable.
    • Injected the AGENT=gemini environment variable into the environment of child processes spawned via child_process.spawn.
    • Injected the AGENT=gemini environment variable into the environment of child processes spawned via PTY.
  • packages/core/src/tools/mcp-client.ts
    • Imported the newly defined AGENT_IDENTIFICATION_ENV_VAR and AGENT_IDENTIFICATION_ENV_VAR_VALUE constants.
    • Injected the AGENT=gemini environment variable into the environment of MCP server child processes.
Activity
  • No human activity has occurred on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a vendor-neutral AGENT=gemini environment variable to child processes, which is a good step towards standardization for AI agent detection. The changes are applied consistently across PTY, child_process, and MCP transports, and the tests are updated accordingly. I've found one minor area for improvement regarding code consistency in shellExecutionService.ts.

Address review feedback: replace hardcoded GEMINI_CLI: '1' with the
exported constants for consistency with the child_process and MCP
transport paths.
@gemini-cli
Copy link
Copy Markdown
Contributor

gemini-cli bot commented Mar 18, 2026

Hi there! Thank you for your interest in contributing to Gemini CLI.

To ensure we maintain high code quality and focus on our prioritized roadmap, we have updated our contribution policy (see Discussion #17383).

We only guarantee review and consideration of pull requests for issues that are explicitly labeled as 'help wanted'. All other community pull requests are subject to closure after 14 days if they do not align with our current focus areas. For this reason, we strongly recommend that contributors only submit pull requests against issues explicitly labeled as 'help-wanted'.

This pull request is being closed as it has been open for 14 days without a 'help wanted' designation. We encourage you to find and contribute to existing 'help wanted' issues in our backlog! Thank you for your understanding and for being part of our community!

@gemini-cli gemini-cli bot closed this Mar 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant