From caf61815a8545d84ff0c4f9b1d11886a3cfbc2ae Mon Sep 17 00:00:00 2001 From: Diane Diaz Date: Thu, 19 Feb 2026 11:13:25 -0800 Subject: [PATCH 1/2] agent variable --- documentation/docs/guides/environment-variables.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/documentation/docs/guides/environment-variables.md b/documentation/docs/guides/environment-variables.md index 43b4d80155d2..d73cecf63a7c 100644 --- a/documentation/docs/guides/environment-variables.md +++ b/documentation/docs/guides/environment-variables.md @@ -611,14 +611,20 @@ These variables are automatically set by goose during command execution. | Variable | Purpose | Values | Default | |----------|---------|---------|---------| | `GOOSE_TERMINAL` | Indicates that a command is being executed by goose, enables [customizing shell behavior](#customizing-shell-behavior) | "1" when set | Unset | +| `AGENT` | Generic agent identifier for cross-tool compatibility, enables tools and scripts to detect when they're being run by goose | "goose" | Unset | | `AGENT_SESSION_ID` | The current session ID for [session-isolated workflows](#using-session-ids-in-workflows), automatically available to STDIO extensions and the Developer extension shell commands | Session ID string (e.g., `20260217_5`) | Unset (only set in extension/shell contexts) | ### Customizing Shell Behavior Sometimes you want goose to use different commands or have different shell behavior than your normal terminal usage. For example, you might want goose to use a different tool, prevent goose from running `git commit`, or block long-running development servers that could hang the AI agent. This is most useful when using goose CLI, where shell commands are executed directly in your terminal environment. +goose provides the `GOOSE_TERMINAL` and `AGENT` variables you can use to detect whether goose is the executing agent. + **How it works:** -1. When goose runs commands, `GOOSE_TERMINAL` is automatically set to "1" + +1. When goose runs commands: + - `GOOSE_TERMINAL` is automatically set to "1" + - `AGENT` is automatically set to "goose" 2. Your shell configuration can detect this and change behavior while keeping your normal terminal usage unchanged **Examples:** @@ -640,7 +646,7 @@ fi ```bash # Guide goose toward better tool choices -if [[ -n "$GOOSE_TERMINAL" ]]; then +if [[ "$AGENT" == "goose" ]]; then alias find="echo 'Use rg instead: rg --files | rg for filenames, or rg for content search'" fi ``` From 0026328d59568e76c20199d98d3317e0ee8f9dfe Mon Sep 17 00:00:00 2001 From: Diane Diaz Date: Thu, 19 Feb 2026 11:56:26 -0800 Subject: [PATCH 2/2] use cases --- .../docs/guides/environment-variables.md | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/documentation/docs/guides/environment-variables.md b/documentation/docs/guides/environment-variables.md index d73cecf63a7c..26d22308cc68 100644 --- a/documentation/docs/guides/environment-variables.md +++ b/documentation/docs/guides/environment-variables.md @@ -611,17 +611,24 @@ These variables are automatically set by goose during command execution. | Variable | Purpose | Values | Default | |----------|---------|---------|---------| | `GOOSE_TERMINAL` | Indicates that a command is being executed by goose, enables [customizing shell behavior](#customizing-shell-behavior) | "1" when set | Unset | -| `AGENT` | Generic agent identifier for cross-tool compatibility, enables tools and scripts to detect when they're being run by goose | "goose" | Unset | +| `AGENT` | Generic agent identifier for cross-tool compatibility, enables tools and scripts to detect when they're being run by goose | "goose" when set | Unset | | `AGENT_SESSION_ID` | The current session ID for [session-isolated workflows](#using-session-ids-in-workflows), automatically available to STDIO extensions and the Developer extension shell commands | Session ID string (e.g., `20260217_5`) | Unset (only set in extension/shell contexts) | ### Customizing Shell Behavior -Sometimes you want goose to use different commands or have different shell behavior than your normal terminal usage. For example, you might want goose to use a different tool, prevent goose from running `git commit`, or block long-running development servers that could hang the AI agent. This is most useful when using goose CLI, where shell commands are executed directly in your terminal environment. +Sometimes you want goose to use different commands or have different shell behavior than your normal terminal usage. Common use cases include: +- Skipping expensive shell initialization (e.g. syntax highlighting, custom prompts) +- Blocking interactive commands that would hang the agent (e.g., `git commit`) +- Redirecting to agent-friendly tools (e.g., `rg` instead of `find`) +- Building cross-agent tools and scripts that detect AI agent execution +- Integrating with MCP servers and LLM gateways -goose provides the `GOOSE_TERMINAL` and `AGENT` variables you can use to detect whether goose is the executing agent. +This is most useful when using goose CLI, where shell commands are executed directly in your terminal environment. **How it works:** +goose provides the `GOOSE_TERMINAL` and `AGENT` variables you can use to detect whether goose is the executing agent. + 1. When goose runs commands: - `GOOSE_TERMINAL` is automatically set to "1" - `AGENT` is automatically set to "goose" @@ -646,11 +653,22 @@ fi ```bash # Guide goose toward better tool choices -if [[ "$AGENT" == "goose" ]]; then +if [[ -n "$GOOSE_TERMINAL" ]]; then alias find="echo 'Use rg instead: rg --files | rg for filenames, or rg for content search'" fi ``` +```bash +# Detect AI agent execution using standard naming convention +if [[ -n "$AGENT" ]]; then + echo "Running under AI agent: $AGENT" + # Apply agent-specific behavior if needed + if [[ "$AGENT" == "goose" ]]; then + echo "Detected goose - applying goose-specific settings" + fi +fi +``` + ### Using Session IDs in Workflows STDIO extensions (local extensions that communicate via standard input/output) and the Developer extension's shell commands automatically receive the `AGENT_SESSION_ID` environment variable. This enables you to create session-isolated workflows and make it easier to: