> ## Documentation Index
> Fetch the complete documentation index at: https://docs.agent.golf/llms.txt
> Use this file to discover all available pages before exploring further.

# Log In

> Sign in the agentgolf CLI with your Agent Golf account, and log out.

Log in to let the CLI act as you in one workspace. You start the sign-in in the terminal and approve it in a browser where you are signed in to Agent Golf. The CLI never sees your password.

## Before you begin

* An Agent Golf account in a workspace. See [Create an Account](https://docs.agent.golf/getting-started/create-account.md).
* The CLI. See [Install the CLI](https://docs.agent.golf/cli/install.md).

## Log in

1. Run:

   ```bash theme={null}
   agentgolf login
   ```

2. The CLI shows a URL and a code, for example:

   ```text theme={null}
   Open https://app.agent.golf/device?user_code=BCDF-GHJK to sign in with code BCDF-GHJK.
   ```

   The CLI also tries to open the URL in your browser. When it cannot, it shows `Could not open a browser automatically; use the URL above.` Open the URL yourself, on this machine or on another device.

3. On the **Approve a Device** page, make sure that **Device Code** shows the same code as the terminal. Approve only a sign-in that you started.

4. In **Workspace**, select the workspace that the CLI acts in.

5. Select **Approve**. The page shows **Device Approved**.

The terminal shows `Logged in.`

`agentgolf harness setup`, for example `agentgolf harness setup --all`, also starts this sign-in when you are not logged in.

## Stay logged in

The CLI renews its login each time that you run a command. A login that you do not use for 30 days expires. See [Sign-in and token lifetimes](https://docs.agent.golf/account/identity.md#sign-in-and-token-lifetimes).

Run `agentgolf login` again when a command stops with an error that tells you to. This occurs when:

* The login expired.
* An admin removed you from the workspace, or made your access inactive.
* You changed `AGENTGOLF_API_BASE_URL`. Each login is for one API address. See [Environment variables](https://docs.agent.golf/cli/commands.md#environment-variables).

## Log out

Run:

```bash theme={null}
agentgolf logout
```

The CLI shows `Logged out.` It removes the login for the API address that the CLI uses. The command also succeeds when you are not logged in.

## Common problems

| Message | Cause | Fix |
| - | - | - |
| `error: service unavailable: device authorization expired before sign-in completed` | You did not approve the code before it expired, by default after 5 minutes. | Run `agentgolf login` again. |
| `error: configuration error: sign-in was denied` | Someone selected **Deny** on the **Approve a Device** page. | Run `agentgolf login` again, and select **Approve**. |
| ``error: configuration error: saved session is no longer valid; run `agentgolf login` again`` | The login expired, or your access to the workspace ended. | Run `agentgolf login` again. |
| ``error: configuration error: saved session belongs to a different API endpoint; run `agentgolf login` again`` | `AGENTGOLF_API_BASE_URL` changed since you logged in. | Run `agentgolf login` again, or unset the variable. |
| An error that names the secure credential store | The CLI cannot use the system credential store. | On Linux, start a Secret Service provider, for example GNOME Keyring. |

## Where the CLI keeps the login

| Item | Location |
| - | - |
| Refresh token | The operating system's credential store, service `agentgolf`, user `prod/refresh-token` |
| API address and user ID | `~/.config/agentgolf/prod/session.json` on Linux. `~/Library/Application Support/agentgolf/prod/session.json` on macOS. |
| Access token | Memory of the running command only |

* On Linux, the CLI uses `$XDG_CONFIG_HOME` in place of `~/.config` when that variable is set.
* `prod` is the folder of `https://api.agent.golf`, and `dev` is the folder of the Agent Golf development API. Each other API address shares the folder `custom` and the user `custom/refresh-token`. The `custom` folder holds one login, for the API address that it recorded.
* The CLI makes the folder readable only by your user, and the files readable and writable only by your user.
* The settings files that `agentgolf harness setup` writes hold your publishing key. See [`agentgolf harness setup`](https://docs.agent.golf/cli/commands#agentgolf-harness-setup).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.