Skip to content

feat(analytics): enhance command tracking with agent identification properties - #1553

Merged
ramya18101 merged 4 commits into
DXCDT-1862-enhance-command-tracking-with-additional-propertiesfrom
DXCDT-1862-enhance-tracking-with-agent-id-property
Jun 22, 2026
Merged

ramya18101 merged 4 commits into
DXCDT-1862-enhance-command-tracking-with-additional-propertiesfrom
DXCDT-1862-enhance-tracking-with-agent-id-property

Conversation

@ramya18101

@ramya18101 ramya18101 commented Jun 17, 2026 •

Copy link
Copy Markdown
Contributor

🔧 Changes

This pull request introduces a robust agent detection system to the CLI, allowing the application to identify which AI agent or client is invoking the CLI.

📚 References

DXCDT-1876

🔬 Testing

Added agent_detection_test.go

📝 Checklist

  • All new/changed/fixed functionality is covered by tests (or N/A)
  • I have added documentation for all new/changed functionality (or N/A)

@brth31

brth31 commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Several issues to fix before merging:

1. COPILOT_AGENT doesn't exist — change to COPILOT_AGENT_SESSION_ID
Confirmed from the github/copilot-cli changelog: "Shell commands and MCP servers now receive COPILOT_AGENT_SESSION_ID as an environment variable." The current entry will never match.

// fix
{envVar: "COPILOT_AGENT_SESSION_ID", agentName: "github-copilot"},

2. OPENAI_CODEX doesn't exist — change to CODEX_THREAD_ID
Confirmed from codex-rs/protocol/src/shell_environment.rs in openai/codex — CODEX_THREAD_ID is injected into every subprocess Codex spawns. OPENAI_CODEX doesn't exist anywhere in the codebase. On macOS, Codex also sets CODEX_SANDBOX=seatbelt as a secondary signal.

// fix
{envVar: "CODEX_THREAD_ID", agentName: "codex"},
{envVar: "CODEX_SANDBOX",   agentName: "codex"},

3. GEMINI_CLI_VERSION is not an env var — remove it
In the Gemini CLI source it's a protobuf metadata key (integer 54) used for internal analytics — not set on child processes. Gemini passes env: process.env unmodified to subprocesses. This entry is dead code. Note: Gemini CLI is also being deprecated in favour of Antigravity (agy).

4. Antigravity (agy) is missing — add it
Google's Antigravity CLI (agy, Gemini's successor) injects ANTIGRAVITY_CONVERSATION_ID into every subprocess it spawns. Confirmed from the agy binary directly.

{envVar: "ANTIGRAVITY_CONVERSATION_ID", agentName: "antigravity"},

5. MCP server detection doesn't work via either path
The AUTH0_CLI_CLIENT handshake (Tier 1) requires the Auth0 MCP server to set AUTH0_CLI_CLIENT=mcp-server when shelling out to the CLI — that change doesn't exist in the MCP server repo yet. The process walk fallback (Tier 3) also doesn't work: the MCP server runs as node /path/to/auth0-mcp-server.js, so the OS process name is node, not auth0-mcp-server. There is currently no path where MCP server traffic gets identified — it will always fall through to unknown. The fix is a one-line change in the MCP server repo to set AUTH0_CLI_CLIENT=mcp-server when invoking the CLI. Please track this as a linked follow-up to DXCDT-1876 before the epic is closed.

Suggested enhancement: wildcard sweep for unknown future agents
Three naming conventions have emerged across major agent CLIs: *_CONVERSATION_ID, *_THREAD_ID, *_AGENT_SESSION_ID. A secondary sweep after the known-list catches future agents without a code change per agent:

for _, e := range os.Environ() {
    key, val, ok := strings.Cut(e, "=")
    if !ok || val == "" {
        continue
    }
    upper := strings.ToUpper(key)
    if strings.HasSuffix(upper, "_CONVERSATION_ID") ||
        strings.HasSuffix(upper, "_THREAD_ID") ||
        strings.HasSuffix(upper, "_AGENT_SESSION_ID") {
        return "unknown-agent"
    }
}

@ramya18101

ramya18101 commented Jun 22, 2026 •

Copy link
Copy Markdown
Contributor Author

Tested and added screenshots

Screenshot 2026-06-22 at 6 24 47 AM Screenshot 2026-06-22 at 6 56 34 AM Screenshot 2026-06-22 at 8 25 45 AM Screenshot 2026-06-22 at 1 47 57 PM Screenshot 2026-06-22 at 4 05 41 PM

@ramya18101
ramya18101 marked this pull request as ready for review June 22, 2026 08:19
@ramya18101
ramya18101 requested a review from a team as a code owner June 22, 2026 08:19
@ramya18101

Copy link
Copy Markdown
Contributor Author
  • Claude Code: CLAUDECODE and CLAUDE_CODE_SESSION_ID are called out in the Claude Code changelog entry about subprocess environment propagation. Claude Code changelog.

  • Claude Code: AI_AGENT is called out in the Claude Code changelog entry about subprocess attribution. Claude Code changelog.

  • Gemini CLI: ANTIGRAVITY_CLI_ALIAS and CURSOR_TRACE_ID are checked in Gemini’s IDE detection code. Gemini CLI detect-ide.ts.

  • Gemini CLI: GEMINI_CLI_VERSION is present in Gemini’s telemetry event metadata keys. Gemini CLI event-metadata-key.ts.

@ramya18101

Copy link
Copy Markdown
Contributor Author
  • CURSOR_CONVERSATION_ID: observed in a real Cursor session and validated locally.
  • ANTIGRAVITY_CONVERSATION_ID: observed in local
  • CODEX_THREAD_ID: observed in real Codex runs

@ramya18101
ramya18101 merged commit 8b882ce into DXCDT-1862-enhance-command-tracking-with-additional-properties Jun 22, 2026
8 of 10 checks passed
@ramya18101
ramya18101 deleted the DXCDT-1862-enhance-tracking-with-agent-id-property branch June 22, 2026 17:29
ramya18101 added a commit that referenced this pull request Jun 23, 2026
…1552)

* feat(analytics): enhance command tracking with additional properties

* feat(analytics): enhance command tracking with agent identification properties (#1553)

* feat(analytics): enhance command tracking with agent identification properties

* enhance agent detection with additional environment variables and process info caching

* remove un-necessary func

* feat(agent-detection): enhance agent detection with final env variables
ramya18101 added a commit that referenced this pull request Jun 23, 2026
…ents (#1551)

* feat(analytics): enhance command tracking with success and failure events

* feat(analytics): improve error handling for API responses

* feat(analytics): unify command tracking events under a single method

* feat(analytics): enhance command tracking with additional properties (#1552)

* feat(analytics): enhance command tracking with additional properties

* feat(analytics): enhance command tracking with agent identification properties (#1553)

* feat(analytics): enhance command tracking with agent identification properties

* enhance agent detection with additional environment variables and process info caching

* remove un-necessary func

* feat(agent-detection): enhance agent detection with final env variables
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.

2 participants