Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@MattieTK
Copy link
Member

@MattieTK MattieTK commented Jan 7, 2026

Note: This PR was written by OpenCode Opus 4.5 and reviewed by @MattieTK.

Summary

This PR adds AI agent detection to Wrangler analytics events using the am-i-vibing library. When Wrangler commands are executed by AI coding agents (such as Claude Code, Cursor, GitHub Copilot, etc.), the agent ID is now included as an agent property in all analytics events.

  • Detects AI coding environments at dispatcher initialization
  • Adds agent property to CommonEventProperties type
  • Includes agent ID in both command events and adhoc events
  • Agent is null when not running in an agentic environment
  • Silent failure (agent = null) if detection throws an error

Supported Agents

The library detects agents including: Claude Code, Cursor, GitHub Copilot, Windsurf, Zed, Aider, Codex CLI, Jules, Replit, Warp, and others.


  • Tests
    • Tests included/updated
    • Tests not necessary because:
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: Telemetry documentation updated in telemetry.md

A picture of a cute animal (not mandatory, but encouraged)

cute robot cat

@MattieTK MattieTK requested a review from a team as a code owner January 7, 2026 14:05
@changeset-bot
Copy link

changeset-bot bot commented Jan 7, 2026

🦋 Changeset detected

Latest commit: 6687834

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@claude
Copy link
Contributor

claude bot commented Jan 7, 2026

Claude finished @MattieTK's task —— View job


Changeset Review

  • Read changeset guidelines
  • Review changeset file
  • Check for cute animals
  • Provide verdict

⚠️ Issues found

Version Type Issue

The changeset is marked as patch, but according to the review discussion and the nature of the change, there's ambiguity about whether this should be a patch or minor version bump.

Analysis: Based on .changeset/README.md guidelines:

  • patch: Bug fixes, small improvements, documentation fixes
  • minor: New features, new CLI commands, new configuration options

This change adds new functionality (AI agent detection with a new agent property in analytics events), which is technically a new feature. However, since:

  1. It's purely telemetry/analytics related
  2. It has no user-facing behavioral changes
  3. It doesn't add new CLI commands or configuration options
  4. It's internal instrumentation

Recommendation: This is borderline, but patch is acceptable for internal telemetry additions that don't change user-facing behavior. The review comment from @dario-piotrowicz supports this assessment.

Changeset Quality

Title: Clear and imperative ("Add AI agent detection to analytics events")
Body: Well-written with explanation of what the feature does
Markdown Headers: No h1/h2/h3 headers used
Description Quality: Explains the change clearly with technical details


Cuteness Report

This is Loading Icon. They're just a simple orange circle doing their best. Minimal effort, maximum charm. Would spin again. 7/10


@pkg-pr-new
Copy link

pkg-pr-new bot commented Jan 7, 2026

create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@11820

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@11820

miniflare

npm i https://pkg.pr.new/miniflare@11820

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@11820

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@11820

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@11820

@cloudflare/vitest-pool-workers

npm i https://pkg.pr.new/@cloudflare/vitest-pool-workers@11820

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@11820

@cloudflare/workers-utils

npm i https://pkg.pr.new/@cloudflare/workers-utils@11820

wrangler

npm i https://pkg.pr.new/wrangler@11820

commit: 6687834

@MattieTK MattieTK force-pushed the mattietk/agentic-analytics branch from 7f10c5d to 08ad648 Compare January 7, 2026 15:14
Comment on lines 73 to 80
try {
const processAncestry = process.platform === "win32" ? [] : undefined;
const agentDetection = detectAgenticEnvironment(
process.env,
processAncestry
);
agent = agentDetection.id;
} catch {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like something that should be fixed upstream

Copy link
Member

@dario-piotrowicz dario-piotrowicz Jan 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not even sure if there is actually an issue or if open-code just produced some (potentially overly) defensive code here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a problem in the Windows tests at the moment, but happy for you to fix it upstream @ascorbic. I stopped Opencode from going mad at this, and was going to chat to you about it anyway.

Copy link
Member Author

@MattieTK MattieTK Jan 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have tested this further and resolving this as wmic is not throwing or printing errors in win 11 currently I was very wrong

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ascorbic as discussed, I think we agree this should be resolved upstream, but I also think we should aim to get this in for as many clients as possible asap, so I'm pushing the change to prevent the windows errors for the time being and we can revisit. Hopefully that unblocks this in the tests 🙏

Copy link
Member

@dario-piotrowicz dario-piotrowicz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -0,0 +1,9 @@
---
"wrangler": minor
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if this should maybe be a patch since it doesn't introduce any new user-facing feature 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, probably right here again, I think we possibly need some clearer instructions for the LLMs.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⬆️ we definitely need better instructions: one minute ago it was complaining this was still a minor based on your comment, now it's suggesting that it should be a minor again.

Leaving this unresolved for clarity.

@github-project-automation github-project-automation bot moved this from Untriaged to Approved in workers-sdk Jan 7, 2026
@MattieTK MattieTK added the wrangler Relating to the Wrangler CLI tool label Jan 8, 2026
The am-i-vibing library's detectAgenticEnvironment function uses
process-ancestry to check for running processes. When processAncestry
is undefined, it calls getProcessAncestry() which uses execSync('ps ...')
to walk up the entire process tree.

For each provider with processChecks (6 providers), it would call
getProcessAncestry() separately, causing:
- Massive slowdowns (tests took 78+ seconds instead of 3 seconds)
- Timeouts in CI environments (especially on Linux)
- Race conditions where output wasn't captured properly

By passing an empty array [], we skip process tree traversal entirely.
Environment variable detection is sufficient for identifying most
agentic environments (Claude Code, Cursor, Windsurf, etc.) and is
instantaneous.
@MattieTK MattieTK merged commit b0e54b2 into main Jan 12, 2026
41 of 42 checks passed
@MattieTK MattieTK deleted the mattietk/agentic-analytics branch January 12, 2026 13:19
@github-project-automation github-project-automation bot moved this from Approved to Done in workers-sdk Jan 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

wrangler Relating to the Wrangler CLI tool

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants