Skip to content

feat(client): add AI agent detection to user agent#19

Merged
platinummonkey merged 2 commits into
mainfrom
feat/ai-agent-user-agent-detection
Feb 10, 2026
Merged

feat(client): add AI agent detection to user agent#19
platinummonkey merged 2 commits into
mainfrom
feat/ai-agent-user-agent-detection

Conversation

@jkirsteins
Copy link
Copy Markdown
Contributor

Summary

Add automatic detection of AI coding assistants to the user agent string sent in HTTP requests to Datadog API.

Changes

  • pkg/useragent/useragent.go - New package with user agent generation and AI agent detection
  • pkg/useragent/useragent_test.go - Comprehensive tests with 100% coverage
  • pkg/client/client.go - Use new useragent package, remove old getUserAgent() function
  • pkg/client/client_test.go - Update tests to use useragent.Get()
  • docs/ARCHITECTURE.md - Document user agent implementation

User Agent Format

Without AI agent:

pup/v0.1.0 (go go1.25.0; os darwin; arch arm64)

With Claude Code:

pup/v0.1.0 (go go1.25.0; os darwin; arch arm64) claude-code

With Cursor:

pup/v0.1.0 (go go1.25.0; os darwin; arch arm64) cursor

AI Agent Detection

Automatically detects AI agents via environment variables:

  • CLAUDECODE=1 or CLAUDE_CODE=1 → appends claude-code
  • CURSOR_AGENT=true or CURSOR_AGENT=1 → appends cursor
  • Precedence: CLAUDECODE takes priority if both are set

Testing

  • New pkg/useragent package: 100% test coverage
  • All existing tests pass
  • Manual testing with/without agent environment variables confirmed
  • Integration test verifies user agent appears in HTTP headers

Architecture

Created dedicated pkg/useragent package (instead of keeping in pkg/client) for:

  • Separation of concerns
  • Reusability across packages
  • Easier testing and mocking
  • Future extensibility

🤖 Generated with Claude Code

jkirsteins and others added 2 commits February 10, 2026 15:58
Implement automatic detection of AI coding assistants:
- Detect CLAUDECODE/CLAUDE_CODE environment variables
- Detect CURSOR_AGENT environment variable
- Append agent identifier to user agent string
- Create dedicated pkg/useragent package for better organization

User agent format:
- Without agent: pup/v0.1.0 (go go1.25.0; os darwin; arch arm64)
- With agent: pup/v0.1.0 (go go1.25.0; os darwin; arch arm64) claude-code

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Add documentation for user agent format and AI agent detection mechanism.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@jkirsteins jkirsteins requested a review from a team as a code owner February 10, 2026 15:03
@github-actions
Copy link
Copy Markdown

📊 Test Coverage Report

Overall Coverage: 80.4% Coverage

Threshold: 80% ✅

Coverage by Package
## Coverage by Package

- github.com/DataDog/pup/pkg/auth/callback/server.go:40: 81.2%
- github.com/DataDog/pup/pkg/auth/dcr/client.go:28: 100.0%
- github.com/DataDog/pup/pkg/auth/dcr/types.go:24: 100.0%
- github.com/DataDog/pup/pkg/auth/oauth/client.go:22: 100.0%
- github.com/DataDog/pup/pkg/auth/oauth/pkce.go:24: 85.7%
- github.com/DataDog/pup/pkg/auth/storage/factory.go:53: 94.7%
- github.com/DataDog/pup/pkg/auth/storage/keychain.go:44: 42.9%
- github.com/DataDog/pup/pkg/auth/storage/storage.go:58: 71.4%
- github.com/DataDog/pup/pkg/auth/types/types.go:23: 100.0%
- github.com/DataDog/pup/pkg/client/client.go:32: 94.4%
- github.com/DataDog/pup/pkg/config/config.go:22: 100.0%
- github.com/DataDog/pup/pkg/formatter/formatter.go:31: 100.0%
- github.com/DataDog/pup/pkg/useragent/useragent.go:32: 100.0%
- github.com/DataDog/pup/pkg/util/time.go:20: 95.8%

## Summary

total:								(statements)		80.4%

📈 Coverage Status: ✅ PASSED - Coverage meets minimum threshold

Updated for commit ff3cb6c

@platinummonkey platinummonkey merged commit e370e2f into main Feb 10, 2026
4 checks passed
@platinummonkey platinummonkey deleted the feat/ai-agent-user-agent-detection branch February 10, 2026 15:07
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