Add ai detection to include the agent or model using the cli Closes #459 - #462
Conversation
… cli this should help with meta monitoring of agentic use of the CLI, assist with evals, potentially power optimisation for agent use
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
There was a problem hiding this comment.
Pull request overview
Adds best-effort AI agent/model detection to the Prolific CLI’s HTTP User-Agent so downstream observability can attribute API traffic to agent-driven usage, while preserving the existing prolific-oss/cli/<version> base.
Changes:
- Build and send a versioned
User-Agentheader fromclient.Execute, optionally appendingagent/<name>when an agent env var is detected. - Introduce
agentenvpackage to detect agent environment variables and validate a safe value for headers. - Add tests covering User-Agent composition and agent env var detection behavior.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
| client/client.go | Constructs the new User-Agent string (version + optional agent token) for all API requests. |
| client/client_test.go | Adds an HTTP test asserting Execute sends the expected User-Agent. |
| agentenv/agentenv.go | Implements env-var based agent detection and header-safety validation. |
| agentenv/agentenv_test.go | Adds unit tests for detection precedence and header-value validation. |
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
| } | ||
|
|
||
| var sources = []agentSource{ | ||
| {"CLAUDE_CODE", "claude-code"}, |
There was a problem hiding this comment.
Per the env-vars docs, Claude Code sets CLAUDECODE=1 (no underscore) in spawned subprocesses — not CLAUDE_CODE.
Have you tested if what's present works..? (env | grep CLAUDE in a live session)? Be good to ensure it doesn't miss primary case.
There was a problem hiding this comment.
Ack: Tested that Claude propagates through to internal Prolific observability via the user agent header but will check that as you suggest.
This should help with meta monitoring of agentic use of the CLI, assist with evals, potentially power optimisation for agent use.
Appends agent/model to the User-Agent header along with Prolific CLI version.
Structure: prolific-oss/cli/, then — only when an agent or model is detected — a space-separated agent/ key/value token. is whatever version.Get() returns. This approach does rely on one of a handful of popular AI model env vars being set, or one of a couple of emerging conventional env vars being set - so it is not a guaranteed catch all, just a best attempt.
Examples
Tested and the new header values propagate through to internal observabilty.