Ask mode cannot use valid gh auth, but Agent mode can

Where does the bug appear (feature/product)?

Cursor IDE

Describe the Bug

On macOS, gh works in Agent mode but fails in Ask mode in the same repo/session.

In Ask mode:

gh auth status says the keyring token is invalid
gh pr view <public PR URL> fails with Post "https://api.github.com/graphql": Forbidden

In Agent mode:

gh auth status succeeds
gh pr view succeeds
gh api graphql -f query='{ viewer { login } }' succeeds

This suggests Ask mode shell runs in a restricted context that cannot access the same keychain-backed gh credentials as Agent mode.

Steps to Reproduce

Use gh cli in Ask mode and then in Agent mode

Expected Behavior

Ask mode should either support the same local gh auth context for read-only commands, or clearly report that gh auth is unavailable in Ask mode due to sandboxing.

Operating System

MacOS

Version Information

Version: 3.0.13 (Universal)
VSCode Version: 1.105.1
Commit: 48a15759f53cd5fc9b5c20936ad7d79847d914b0
Date: 2026-04-07T03:05:17.114Z
Layout: editor
Build Type: Stable
Release Track: Default
Electron: 39.8.1
Chromium: 142.0.7444.265
Node.js: 22.22.1
V8: 14.2.231.22-electron.0
OS: Darwin arm64 25.4.0

Does this stop you from using Cursor

No - Cursor works, but with this issue

Hey there!

The “token in keyring is invalid” error is a red herring. gh reports that when the outbound API request is blocked, not because there’s actually a problem with your keychain credentials.

Ask mode runs all shell commands inside a sandbox with restricted network access. By default, api.github.com is not on the network allowlist, so gh requests get blocked.

To fix this:

  1. Add a .cursor/sandbox.json to your project root with api.github.com in the network allowlist:
{
  "networkPolicy": {
    "default": "deny",
    "allow": [
      "api.github.com"
    ]
  }
}

See the sandbox documentation for the full config reference.

  1. Check your auto-run network settings in Cursor Settings > Agents > Auto Run > Auto-Run Network Access. Make sure it’s set to “sandbox.json” or “sandbox.json + Defaults”. You can also set this to “Allow All”.

This works the same way in Agent mode when sandbox is enabled, and it’s not specific to Ask mode. Ask mode just always enforces the sandbox.

Thanks, that solved the problem! I will spread the info :slight_smile:

1 Like