Cursor CLI: Authentication required. Please run agent login
Fix Cursor CLI's "Authentication required. Please run 'agent login' first" when another tool launches cursor-agent: test, match the binary, set CURSOR_API_KEY.
Updated 5 min read
On this page
You ran agent login and it succeeded, but the tool that spawns Cursor CLI still reports this:
agent exited with code 1 Error: Authentication required. Please run 'agent login' first, or set CURSOR_API_KEY environment variable.People report this from tools that launch cursor-agent for them, including an open-source design tool on Windows 10 and Goose on macOS 26.1. In the Goose case, the visible symptom was a different message: "init chat completion request with tool did not succeed". The steps below apply the same way on macOS.
Why it happens
Most common first:
- The launcher runs a different binary. The error says
agent login, but the executable many tools call iscursor-agent. A reply on one of the reported issues says the login may not apply to the binary the tool actually uses. - The launcher runs in a different environment. A Mac app opened from the Dock or Finder does not read your
~/.zshrc, so exported variables and PATH changes don't reach it. - A different user, service, container or VM. A login belongs to the account and machine where you ran it.
- The login never completed. The browser flow was closed early, or it was done on another machine.
- Organization policy. A reply on one of the issues says an org policy may disable
--force. We could not confirm this beyond that report.
We don't know which of these applies to you until you run the test below.
Step-by-step fixes
1. Test in a fresh shell
Open a new Terminal window, not one that has been open for hours.
Run a one-word prompt:
bash cursor-agent -p testing --forceRead the result:
- It answers normally. Your login works for that binary in a clean shell. The launcher has a different binary or environment. Continue with fixes 2 to 4.
- It prints the same authentication error. The login isn't there. Run
cursor-agent login, finish the browser flow, then repeat the test. - It fails some other way. On a work account, ask your Cursor admin whether policy blocks
--forcebefore changing anything else.
2. Make sure the launcher uses the same binary
List every copy on your PATH:
bash which -a cursor-agentIf more than one path appears, the first wins in your shell. A launcher may use another one, for example a full path in its own settings.
Log in with the exact path the tool runs, such as
/path/from/the/tool/cursor-agent login, then repeat the test with that same path.
3. Run the launcher as the same user, in the same environment
- If the tool runs as another user, as a service, or inside a container or VM, log in there.
- If the tool can be started from a terminal, start it from the terminal where the test worked.
4. Set CURSOR_API_KEY
The error message offers this as an alternative to logging in. Set the variable in the shell that starts the tool:
export CURSOR_API_KEY="paste-your-key-here"This applies to that shell session only. To undo it, run unset CURSOR_API_KEY or close the window. Launch the tool from that same shell and repeat the test.
Cause, symptom and fix at a glance
| Cause | Symptom | Fix |
|---|---|---|
| Different binary | Test works, tool fails | which -a cursor-agent, log in with the tool's path |
| No shell profile | Works from Terminal, fails from Dock | Launch from Terminal or set the key |
| Other user or machine | Works for you, fails in service or VM | Log in there |
| Login incomplete | Test fails in fresh shell | cursor-agent login again |
| Org policy | Fails only with --force | Ask your Cursor admin |
Checklist before you try again
- The fresh-shell test prints a normal answer.
which -a cursor-agentshows the path the tool uses.- The tool runs as the same user on the same machine.
- Either the login was done with that binary, or
CURSOR_API_KEYis set in the launching environment.
What Sledbot covers
Sledbot lists Cursor CLI (cursor-agent) as a supported agent, with cursor-agent login as its login command. It runs the agent in a real terminal on the machine you choose, so the login that counts is the one on that machine. It does not change how Cursor CLI authenticates, and we don't document CURSOR_API_KEY handling, so use fix 4 for key setup.
- Log in on the right machine. In Settings > Agents, pick the Machine, find Cursor CLI and click Log in…. After you confirm, the login runs in a terminal pane on that machine, and browser or device-code flows work on remotes too.
- Check status. The row shows the vendor and version, or "not installed". Refresh repeats the detection.
- Profile loading. Settings > General > Load ~/.zshrc when starting agents is on by default and applies to this Mac only.
- Doctor.
sled doctorchecks the machine, including agent CLIs and their logins.
Sledbot can't fix a separate tool that launches cursor-agent from another binary or user. See Run agents on your own servers for per-machine logins.
If nothing works
Contact Cursor support, or your Cursor admin on a work account, and the maintainers of the tool that launches the agent. Include the exact error, the output of which -a cursor-agent, your OS version, how the tool is launched, and what the fresh-shell test printed.
A tool that launches cursor-agent fails with: "Authentication required. Please run 'agent login' first, or set CURSOR_API_KEY environment variable." (exit code 1).
`cursor-agent -p testing --force` in a fresh terminal gives: <result>.
`which -a cursor-agent` shows: <paths>.
OS: <version>. The tool is started from: <Terminal / Dock / service>.
I have already run `cursor-agent login` and tried setting CURSOR_API_KEY.Common questions
Does agent login log in cursor-agent?
Not necessarily. One reply on the reported issues says the login may not apply to the binary the tool runs. Log in with the exact binary path the tool uses.
Is CURSOR_API_KEY better than logging in?
It is simpler for tools that run headless, because the key travels in the environment rather than a stored login. You must set it where the tool starts, not just in another window.
Why does it work in Terminal but not from an app?
Apps opened from the Dock or Finder don't read your shell profile. Start the app from Terminal or give it the variable another way.