-
Notifications
You must be signed in to change notification settings - Fork 0
Fix credential setup (PKCE OAuth) and restore broad lang_path_pattern #25
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
KHAEntertainment
merged 7 commits into
master
from
claude/oauth-setup-and-pattern-fix-RBCuj
Mar 29, 2026
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
97abc43
Fix Claude Code credential setup: PKCE OAuth flow, no key in-context
claude e8f12cd
Restore broad lang_path_pattern and absolute path rebasing after rebase
claude ee5234d
fix: apply CodeRabbit auto-fixes
coderabbitai[bot] b2c0cba
fix: apply CodeRabbit auto-fixes
coderabbitai[bot] 58eb8f1
fix: apply CodeRabbit auto-fixes
coderabbitai[bot] 5ec80ed
fix: apply CodeRabbit auto-fixes
coderabbitai[bot] ef45401
Update platforms/claude/commands/setup.md
KHAEntertainment 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
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
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 |
|---|---|---|
| @@ -1,42 +1,100 @@ | ||
| --- | ||
| name: setup | ||
| description: Set up your OpenRouter API key for Grok Swarm. Run this before first use if prompted. | ||
| description: Authorize Grok Swarm with your OpenRouter account via OAuth. No API key handling in-context. | ||
| argument-hint: None | ||
| allowed-tools: | ||
| - Bash | ||
| --- | ||
|
|
||
| # Setup Grok Swarm | ||
|
|
||
| This command guides you through configuring your OpenRouter API key for Grok Swarm. | ||
| Follow these steps exactly. Do not ask the user for their API key — the OAuth | ||
| flow ensures the key never passes through this conversation. | ||
|
|
||
| ## Usage | ||
| ## Step 1 — Check for existing key | ||
|
|
||
| Run: | ||
| ```bash | ||
| OAUTH_PATH="$(find ~/.claude/plugins -name 'oauth_setup.py' 2>/dev/null | head -1)" | ||
| if [ -n "$OAUTH_PATH" ]; then | ||
| python3 "$(dirname "$OAUTH_PATH")/oauth_setup.py" --check 2>/dev/null | ||
| else | ||
| OAUTH_PATH="$(find /usr /usr/local ~/.local -name 'oauth_setup.py' 2>/dev/null | head -1)" | ||
| [ -n "$OAUTH_PATH" ] && python3 "$OAUTH_PATH" --check 2>/dev/null | ||
| fi | ||
| ``` | ||
| /grok-swarm:setup | ||
|
|
||
| Alternative (locate bridge relative to this command file): | ||
| ```bash | ||
| OAUTH_PATH="$(find ~/.claude/plugins -name 'oauth_setup.py' 2>/dev/null | head -1)" | ||
| if [ -n "$OAUTH_PATH" ]; then | ||
| BRIDGE_DIR="$(dirname "$OAUTH_PATH")" | ||
| else | ||
| OAUTH_PATH="$(find /usr /usr/local ~/.local -name 'oauth_setup.py' 2>/dev/null | head -1)" | ||
| [ -n "$OAUTH_PATH" ] && BRIDGE_DIR="$(dirname "$OAUTH_PATH")" | ||
| fi | ||
| if [ -f "$BRIDGE_DIR/oauth_setup.py" ]; then | ||
| python3 "$BRIDGE_DIR/oauth_setup.py" --check | ||
| fi | ||
| ``` | ||
|
|
||
| ## What it does | ||
| If the check exits 0, tell the user their key is already configured and offer | ||
| to run a test query. **Stop here.** | ||
|
|
||
| ## Step 2 — Run the OAuth flow | ||
|
|
||
| 1. Checks for existing API key in: | ||
| - `~/.claude/grok-swarm.local.md` (plugin settings) | ||
| - `~/.config/grok-swarm/config.json` (CLI config) | ||
| - `$OPENROUTER_API_KEY` environment variable | ||
| Locate `oauth_setup.py` in the plugin's `src/bridge/` directory and run it | ||
| with a 240 seconds timeout. The timeout is enforced by the Bash tool invocation | ||
| (via the `timeout` parameter in the tool call or CI runner timeout settings): | ||
|
|
||
| ```bash | ||
| OAUTH_PATH="$(find ~/.claude/plugins -name 'oauth_setup.py' 2>/dev/null | head -1)" | ||
| if [ -n "$OAUTH_PATH" ]; then | ||
| PLUGIN_ROOT="$(cd "$(dirname "$OAUTH_PATH")/../.." 2>/dev/null && pwd)" | ||
| else | ||
| OAUTH_PATH="$(find /usr /usr/local ~/.local -name 'oauth_setup.py' 2>/dev/null | head -1)" | ||
| [ -n "$OAUTH_PATH" ] && PLUGIN_ROOT="$(cd "$(dirname "$OAUTH_PATH")/../.." 2>/dev/null && pwd)" | ||
| fi | ||
| timeout 240s python3 "$PLUGIN_ROOT/src/bridge/oauth_setup.py" | ||
| ``` | ||
|
|
||
| 2. If no key found, prompts you to enter one | ||
| **Note**: The `timeout 240s` wrapper ensures the command terminates if the OAuth | ||
| flow exceeds 240 seconds. The script itself has an internal OAUTH_TIMEOUT_SECS | ||
| (180s) for the callback phase plus roughly 30s for token exchange, so the 240s | ||
| outer limit provides a safe margin. | ||
|
|
||
| 3. Saves configuration to plugin settings file | ||
| The script will: | ||
| 1. Print an authorization URL | ||
| 2. Start a local server on `localhost:3000` | ||
| 3. Wait up to 180 seconds for the browser callback | ||
| 4. Exchange the auth code for an API key | ||
| 5. Save the key to `~/.config/grok-swarm/config.json` (chmod 600) | ||
|
|
||
| ## First-time setup | ||
| ## Step 3 — Present the auth URL | ||
|
|
||
| If you're seeing this for the first time: | ||
| Show the user the URL printed by the script and tell them: | ||
|
|
||
| 1. Get an OpenRouter API key at https://openrouter.ai/keys | ||
| 2. Run `/grok-swarm:setup` | ||
| 3. Paste your API key when prompted | ||
| > **Click this link to authorize Grok Swarm with your OpenRouter account.** | ||
| > After approving in your browser, return here — setup completes automatically. | ||
|
|
||
| ## Troubleshooting | ||
| ## Step 4 — Report result | ||
|
|
||
| - **Invalid key error**: Make sure you copied the key correctly from OpenRouter | ||
| - **Key starts with `sk-`**: That's correct! OpenRouter keys begin with `sk-or-v1-` | ||
| - **Permission denied**: The setup script needs to write to `~/.claude/` and `~/.config/` | ||
| - If the script exits 0: confirm success and suggest running `/grok-swarm:analyze Hello world` | ||
| - If it exits 1 (timeout or port conflict): show the error message from the script | ||
| and suggest the manual fallback: | ||
| Direct them to https://openrouter.ai/keys for a key. | ||
|
|
||
| ## xAI Direct Users | ||
|
|
||
| If the user says they want to use xAI directly (not OpenRouter), run: | ||
| ```bash | ||
| OAUTH_PATH="$(find ~/.claude/plugins -name 'oauth_setup.py' 2>/dev/null | head -1)" | ||
| if [ -n "$OAUTH_PATH" ]; then | ||
| PLUGIN_ROOT="$(cd "$(dirname "$OAUTH_PATH")/../.." 2>/dev/null && pwd)" | ||
| else | ||
| OAUTH_PATH="$(find /usr /usr/local ~/.local -name 'oauth_setup.py' 2>/dev/null | head -1)" | ||
| [ -n "$OAUTH_PATH" ] && PLUGIN_ROOT="$(cd "$(dirname "$OAUTH_PATH")/../.." 2>/dev/null && pwd)" | ||
| fi | ||
| python3 "$PLUGIN_ROOT/src/bridge/oauth_setup.py" --provider xai | ||
| ``` | ||
| This prints manual credential instructions without attempting OAuth. | ||
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
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
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
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.