Skip to content

Send telemetry on unrecognized commands#1745

Open
keshavc-stripe wants to merge 3 commits into
masterfrom
keshavc/unknown-cmd-telemetry
Open

Send telemetry on unrecognized commands#1745
keshavc-stripe wants to merge 3 commits into
masterfrom
keshavc/unknown-cmd-telemetry

Conversation

@keshavc-stripe

@keshavc-stripe keshavc-stripe commented Jul 6, 2026

Copy link
Copy Markdown

Reviewers

r? @
cc @stripe/developer-products

Summary

https://jira.corp.stripe.com/browse/DEVAI-1146

Testing

https://logscale.corp.stripe.com/main-view/search?live=false&query=%22ARECIBO-EVENT%22%0A%7C%20%22context.p_client_id%22%20%3D%20%22stripe-cli%22%0A%7C%20groupBy(%22context.p_event_name%22)&start=2h&tz=UTC

keshavc@st-keshavc2(laptop) ~/stripe/stripe-cli % ./bin/stripe foobar
Unknown command "foobar" for "stripe".
See "stripe --help" for a list of available commands.
keshavc@st-keshavc2(laptop) ~/stripe/stripe-cli % cat ~/.config/stripe/unknown_commands.json
cat: /Users/keshavc/.config/stripe/unknown_commands.json: No such file or directory
keshavc@st-keshavc2(laptop) ~/stripe/stripe-cli % CLAUDECODE=1 ./bin/stripe foobar
<claude-code-hint v="1" type="plugin" value="stripe@claude-plugins-official" />
Unknown command "foobar" for "stripe".
See "stripe --help" for a list of available commands.
keshavc@st-keshavc2(laptop) ~/stripe/stripe-cli % cat ~/.config/stripe/unknown_commands.json
[{"command":"foobar","timestamp":"2026-07-06T22:06:12Z","agent":"claude_code"}]% 

@keshavc-stripe keshavc-stripe requested a review from a team as a code owner July 6, 2026 23:05
@keshavc-stripe keshavc-stripe marked this pull request as draft July 6, 2026 23:06
keshavc-stripe and others added 3 commits July 7, 2026 10:53
Record unknown CLI commands attempted by AI agents (Claude Code, Cursor,
Codex, etc.) to gain insight into hallucinated/attempted commands. Entries
are stored locally and sent as a batch every 10 occurrences to avoid
per-invocation roundtrips.

Only activates when an agent environment variable is detected — manual
CLI usage is unaffected.

Resolves: DEVAI-1146

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Committed-By-Agent: claude
The goroutine spawned by `go client.SendEvent(...)` was getting killed
by os.Exit(1) before the HTTP request could complete. Remove the `go`
so the send completes before the process exits.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Committed-By-Agent: claude
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Committed-By-Agent: claude
@keshavc-stripe keshavc-stripe force-pushed the keshavc/unknown-cmd-telemetry branch from 10dd27d to b3e767b Compare July 7, 2026 14:53
@keshavc-stripe keshavc-stripe changed the title Keshavc/unknown cmd telemetry Send telemetry on unrecognized commands Jul 7, 2026
@keshavc-stripe keshavc-stripe marked this pull request as ready for review July 7, 2026 15:04
Comment thread pkg/cmd/root.go

case strings.Contains(errString, "unknown command"):
showSuggestion()
recordUnknownCommand(updatedCtx, strings.Join(os.Args[1:], " "))

@keshavc-stripe keshavc-stripe Jul 7, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Note that this is synchronous but the timeout is 3 seconds. Making this async doesn't work since the os.Exit(1) kills all subroutines.

httpClient := &http.Client{
Timeout: time.Second * 3,
}

@keshavc-stripe

Copy link
Copy Markdown
Author

r? @vcheung-stripe @matv-stripe

const (
unknownCmdBatchFile = "unknown_commands.json"
unknownCmdBatchSize = 10
unknownCmdEventName = "Unknown Command Attempted"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

is this a valid event? do we have to update anything on the spark side internally? @vcheung-stripe would know

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Hmm showed up on logscale but might be missing some more context for spark stuff

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