-
Notifications
You must be signed in to change notification settings - Fork 473
Emit Claude Code plugin hint to stderr #1550
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+59
−0
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
b71d5a1
Emit Claude Code plugin hint to stderr
tomer-stripe 1922c83
Use DetectAIAgent instead of checking CLAUDECODE directly
tomer-stripe 487700f
Merge branch 'master' into tomer/claude-code-plugin-hint
tomer-stripe 93f45b6
Merge branch 'master' into tomer/claude-code-plugin-hint
tomer-stripe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| package cmd | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "io" | ||
| "os" | ||
|
|
||
| "github.com/stripe/stripe-cli/pkg/useragent" | ||
| ) | ||
|
|
||
| const claudeCodePluginHint = `<claude-code-hint v="1" type="plugin" value="stripe@claude-plugins-official" />` | ||
|
|
||
| // emitClaudeCodePluginHint writes a plugin hint to stderr when running inside | ||
| // Claude Code. Claude Code strips the hint from command output and may prompt | ||
| // the user to install the Stripe plugin. See | ||
| // https://code.claude.com/docs/en/plugin-hints for the protocol. | ||
| func emitClaudeCodePluginHint() { | ||
| writeClaudeCodePluginHint(os.Getenv, os.Stderr) | ||
| } | ||
|
|
||
| func writeClaudeCodePluginHint(getEnv func(string) string, w io.Writer) { | ||
| if useragent.DetectAIAgent(getEnv) != "claude_code" { | ||
| return | ||
| } | ||
| fmt.Fprintln(w, claudeCodePluginHint) | ||
| } | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| package cmd | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| func TestWriteClaudeCodePluginHint_EmitsWhenSet(t *testing.T) { | ||
| var buf bytes.Buffer | ||
| getEnv := func(key string) string { | ||
| if key == "CLAUDECODE" { | ||
| return "1" | ||
| } | ||
| return "" | ||
| } | ||
|
|
||
| writeClaudeCodePluginHint(getEnv, &buf) | ||
|
|
||
| assert.Equal(t, claudeCodePluginHint+"\n", buf.String()) | ||
| } | ||
|
|
||
| func TestWriteClaudeCodePluginHint_SilentWhenUnset(t *testing.T) { | ||
| var buf bytes.Buffer | ||
| getEnv := func(string) string { return "" } | ||
|
|
||
| writeClaudeCodePluginHint(getEnv, &buf) | ||
|
|
||
| assert.Empty(t, buf.String()) | ||
| } |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.