claude-code - 💡(How to fix) Fix [DOCS] Bash tool docs missing `AI_AGENT` subprocess environment variable [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#53071Fetched 2026-04-25 06:13:08
View on GitHub
Comments
0
Participants
1
Timeline
3
Reactions
0
Author
Participants
Timeline (top)
labeled ×3
RAW_BUFFERClick to expand / collapse

Documentation Type

Missing documentation (feature not documented)

Documentation Location

https://code.claude.com/docs/en/tools-reference

Section/Topic

Bash tool behavior, specifically the subprocess environment that Claude Code provides to shell commands

Current Documentation

The Bash tool reference currently says:

The Bash tool runs each command in a separate process with the following persistence behavior:

  • When Claude runs cd in the main session, the new working directory carries over to later Bash commands as long as it stays inside the project directory or an additional working directory you added with --add-dir, /add-dir, or additionalDirectories in settings. Subagent sessions never carry over working directory changes.
  • Environment variables do not persist. An export in one command will not be available in the next.

The environment variables reference documents user-configurable variables and subprocess-related controls such as:

CLAUDE_CODE_SUBPROCESS_ENV_SCRUB - Set to 1 to strip Anthropic and cloud provider credentials from subprocess environments (Bash tool, hooks, MCP stdio servers).

No current page documents that Claude Code sets AI_AGENT for subprocesses.

What's Wrong or Missing?

Changelog v2.1.120 includes:

Set AI_AGENT environment variable for subprocesses so gh can attribute traffic to Claude Code

That entry describes a user-visible subprocess environment variable, but the documentation does not explain:

  1. that Claude Code injects AI_AGENT into subprocess environments,
  2. which subprocess surfaces receive it, such as Bash commands, hooks, MCP stdio servers, or only a subset,
  3. what value users and tools should expect, and
  4. how this relates to gh attribution and existing subprocess environment behavior.

Users who inspect command environments, write scripts that branch on agent identity, or troubleshoot gh/GitHub traffic attribution have to infer this behavior from the changelog rather than from the tool or environment-variable references.

Suggested Improvement

Add a short note under Bash tool behavior that documents the subprocess environment Claude Code provides.

Suggested content:

  • State that Claude Code sets AI_AGENT for subprocesses as of v2.1.120.
  • Document the exact value and whether users should treat it as stable.
  • Specify which subprocess types receive the variable.
  • Explain that tools such as gh can use the variable to attribute traffic to Claude Code.
  • Clarify how this interacts with environment persistence: export values from one Bash command still do not persist to the next, but Claude Code-provided subprocess environment variables are added by the parent process for each command.

Also add an entry or cross-reference on the environment variables page so users searching for AI_AGENT can find the behavior from the complete environment variable reference.

Impact

Medium - Makes feature difficult to understand

Additional Context

Affected Pages:

PageContext
https://code.claude.com/docs/en/tools-referencePrimary Bash tool behavior section documents subprocess process boundaries and environment persistence, but not Claude Code-provided environment variables such as AI_AGENT
https://code.claude.com/docs/en/env-varsComplete environment variable reference documents subprocess-related variables but has no AI_AGENT entry or cross-reference
https://code.claude.com/docs/en/best-practicesRecommends using CLI tools like gh, but does not mention Claude Code's subprocess attribution environment

Total scope: 3 pages affected

Source: Changelog v2.1.120

Exact changelog entry: Set AI_AGENT environment variable for subprocesses so gh can attribute traffic to Claude Code

extent analysis

TL;DR

Update the documentation to include information about the AI_AGENT environment variable set by Claude Code for subprocesses.

Guidance

  • Add a note under Bash tool behavior to document the subprocess environment provided by Claude Code, including the AI_AGENT variable.
  • Specify the exact value of AI_AGENT and whether it is stable.
  • Clarify which subprocess types receive the AI_AGENT variable.
  • Explain how this variable interacts with environment persistence.
  • Add an entry or cross-reference on the environment variables page for AI_AGENT.

Example

No code snippet is necessary for this issue, as it is a documentation update.

Notes

The suggested improvement should be applied to the affected pages, including the primary Bash tool behavior section and the complete environment variable reference.

Recommendation

Apply the workaround by updating the documentation to include the missing information about the AI_AGENT environment variable, as this will improve the understandability of the feature.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix [DOCS] Bash tool docs missing `AI_AGENT` subprocess environment variable [1 participants]