Skip to content

feat: detect OpenCode as an AI agent - #665

Merged
mwbrooks merged 1 commit into
mainfrom
mwbrooks-detect-opencode-agent
Sep 1, 2026
Merged

feat: detect OpenCode as an AI agent#665
mwbrooks merged 1 commit into
mainfrom
mwbrooks-detect-opencode-agent

Conversation

@mwbrooks

@mwbrooks mwbrooks commented Sep 1, 2026

Copy link
Copy Markdown
Member

Changelog

The CLI now reports opencode as the AI agent name when run from OpenCode, instead of the literal 1.

Summary

This pull request teaches the CLI to detect OpenCode so its telemetry and User-Agent carry a real agent name.

  • OpenCode sets AGENT=1 (not AGENT=opencode), so the AGENT fallback in internal/useragent/useragent.go passed 1 straight through as the agent name.
  • It also sets OPENCODE=1 unconditionally, alongside AGENT=1 and OPENCODE_PID, in packages/opencode/src/index.ts - a reliable discriminator present in every process it spawns.
  • Adds an OPENCODE case to GetAIAgent() just ahead of the AGENT fallback. Ordering matters: OpenCode sets both variables, so OPENCODE has to be checked first.
  • Higher-priority agents still win, since someone can run another agent from inside an OpenCode shell.

internal/tracking/tracking.go already feeds useragent.GetAIAgentName() into the ai_agent telemetry field, so no other production code changes were needed.

Closes #664

Preview

Verified via ./bin/slack version --skip-update --verbose:

Environment Reported name
OPENCODE=1 AGENT=1 AI-Agent (name: opencode)
AGENT=1 AI-Agent (name: 1) (fallback unchanged)
AGENT=goose AI-Agent (name: goose) (fallback unchanged)
CURSOR_AGENT=1 OPENCODE=1 AI-Agent (name: cursor) (priority holds)
no agent variables no AI-Agent suffix

Testing

  1. Build the CLI with make build.
  2. Run env -u CLAUDECODE -u CLAUDE_CODE_ENTRYPOINT OPENCODE=1 AGENT=1 ./bin/slack version --skip-update --verbose and confirm the user_agent debug line ends with AI-Agent (name: opencode).
  3. Re-run with only AGENT=1 set and confirm the name is still 1, so the generic fallback is unchanged for other agents.
  4. Re-run with CURSOR_AGENT=1 OPENCODE=1 and confirm cursor wins, so detection priority is preserved.

Note: unset CLAUDECODE/CLAUDE_CODE_ENTRYPOINT when testing from inside Claude Code, otherwise it takes priority and masks the result.

Notes

  • OpenCode does not document these variables, so this could break if they rename OPENCODE. The AGENT fallback would then resume reporting 1, which is the current behavior - no worse than today.

Requirements

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

codecov Bot commented Sep 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.19%. Comparing base (f36b480) to head (c627192).
⚠️ Report is 1 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@mwbrooks mwbrooks self-assigned this Sep 1, 2026
@mwbrooks mwbrooks added enhancement M-T: A feature request for new functionality semver:minor Use on pull requests to describe the release version increment labels Sep 1, 2026
@mwbrooks mwbrooks added this to the Next Release milestone Sep 1, 2026
@mwbrooks mwbrooks added the changelog Use on updates to be included in the release notes label Sep 1, 2026
@mwbrooks
mwbrooks marked this pull request as ready for review September 1, 2026 22:06
@mwbrooks
mwbrooks requested a review from a team as a code owner September 1, 2026 22:06

@zimeg zimeg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

💾 praise: Thanks for adding support for more agents!

@mwbrooks

mwbrooks commented Sep 1, 2026

Copy link
Copy Markdown
Member Author

Thanks for the quick review @zimeg! 🙇🏻 🚢

@mwbrooks
mwbrooks merged commit 74c284e into main Sep 1, 2026
13 checks passed
@mwbrooks
mwbrooks deleted the mwbrooks-detect-opencode-agent branch September 1, 2026 22:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog Use on updates to be included in the release notes enhancement M-T: A feature request for new functionality semver:minor Use on pull requests to describe the release version increment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Detect opencode as an AI agent in GetAIAgent()

2 participants