feat: detect OpenCode as an AI agent - #665
Merged
Merged
Conversation
OpenCode sets both OPENCODE=1 and AGENT=1 in the environment of every process it spawns, so the AGENT fallback reported the literal "1" as the agent name. Check OPENCODE ahead of that fallback to report "opencode" instead. Higher-priority agents still win, since a user can run another agent from inside an OpenCode shell.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #665 +/- ##
==========================================
- Coverage 78.20% 78.19% -0.01%
==========================================
Files 239 239
Lines 18135 18136 +1
==========================================
- Hits 14183 14182 -1
- Misses 3952 3954 +2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
mwbrooks
marked this pull request as ready for review
September 1, 2026 22:06
zimeg
approved these changes
Sep 1, 2026
zimeg
left a comment
Member
There was a problem hiding this comment.
💾 praise: Thanks for adding support for more agents!
Member
Author
|
Thanks for the quick review @zimeg! 🙇🏻 🚢 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changelog
The CLI now reports
opencodeas the AI agent name when run from OpenCode, instead of the literal1.Summary
This pull request teaches the CLI to detect OpenCode so its telemetry and
User-Agentcarry a real agent name.AGENT=1(notAGENT=opencode), so theAGENTfallback ininternal/useragent/useragent.gopassed1straight through as the agent name.OPENCODE=1unconditionally, alongsideAGENT=1andOPENCODE_PID, inpackages/opencode/src/index.ts- a reliable discriminator present in every process it spawns.OPENCODEcase toGetAIAgent()just ahead of theAGENTfallback. Ordering matters: OpenCode sets both variables, soOPENCODEhas to be checked first.internal/tracking/tracking.goalready feedsuseragent.GetAIAgentName()into theai_agenttelemetry field, so no other production code changes were needed.Closes #664
Preview
Verified via
./bin/slack version --skip-update --verbose:OPENCODE=1 AGENT=1AI-Agent (name: opencode)AGENT=1AI-Agent (name: 1)(fallback unchanged)AGENT=gooseAI-Agent (name: goose)(fallback unchanged)CURSOR_AGENT=1 OPENCODE=1AI-Agent (name: cursor)(priority holds)AI-AgentsuffixTesting
make build.env -u CLAUDECODE -u CLAUDE_CODE_ENTRYPOINT OPENCODE=1 AGENT=1 ./bin/slack version --skip-update --verboseand confirm theuser_agentdebug line ends withAI-Agent (name: opencode).AGENT=1set and confirm the name is still1, so the generic fallback is unchanged for other agents.CURSOR_AGENT=1 OPENCODE=1and confirmcursorwins, so detection priority is preserved.Note: unset
CLAUDECODE/CLAUDE_CODE_ENTRYPOINTwhen testing from inside Claude Code, otherwise it takes priority and masks the result.Notes
OPENCODE. TheAGENTfallback would then resume reporting1, which is the current behavior - no worse than today.Requirements