# Troubleshooting



## Sign-in succeeds but commands still return 401 [#sign-in-succeeds-but-commands-still-return-401]

CCP checks `CCP_API_KEY` first, then `CCP_SESSION_TOKEN`, then your saved login.
An expired token in your shell can therefore override a fresh login. To use your
saved session in a terminal, clear the overrides in that shell and try the
command again.

```bash
unset CCP_API_KEY CCP_SESSION_TOKEN
```

If the saved session has expired and cannot refresh, run `ccp auth login`.
Over SSH, use `ccp auth login --device` and approve the code from a browser.
For CI, replace the expired credential in the runner’s secret store.
See [Authentication](/docs/ccp/authentication) and [Headless Mode](/docs/ccp/headless).

## CCP selects an unexpected organization or App [#ccp-selects-an-unexpected-organization-or-app]

Run `ccp org current --json` to see the organization ID and selection source.
If it reports multiple organizations on a headless runner, supply the intended
ID with `--org-id` on the command. To change a saved default, run
`ccp org use` and select an organization. Commands that use a project's link
can still target the organization recorded in that checkout.
See [Organizations](/docs/ccp/organizations).

On a fresh clone of an existing App, run `ccp link` before deploying. If a
headless deploy says the App name is already in use, link the existing App
using its IDs, then retry the deploy from that directory.

```bash
ccp link --org-id "$ORG_ID" --app-id "$APP_ID"
```

## A database operation returns 409, 429, or 503 [#a-database-operation-returns-409-429-or-503]

Use the operation and the error code together to decide what to change.

| Symptom                                                              | Recovery                                                                                                                                                                              |
| -------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Attaching a private network returns `409 database_not_running`       | Check the database state with `ccp db get`. Resume a manually paused database, or restore billing eligibility for a billing pause. Retry the attachment once the database is running. |
| Opening a native database connection returns `429 Too Many Requests` | The gateway has reached its connection limit. Release idle connections and reduce concurrent opens before retrying.                                                                   |
| Creating a database returns `503 provision_pending`                  | Cleanup from a previous attempt is still running. Wait, then retry creation with the same name.                                                                                       |
| Attaching a private network returns `503 network_attachment_pending` | Retry the same attachment with the same network after reconciliation has had time to finish.                                                                                          |

See [Databases](/docs/ccp/database) for availability states and operation-specific errors.

## A command is missing or a local build fails [#a-command-is-missing-or-a-local-build-fails]

Run `ccp --version` to identify the binary in your shell. For a standalone
installation, `ccp update` installs the latest released version. If CCP reports
that the toolchain is managed by Build, update it through Build.

Run `ccp doctor` to test the local JavaScript runtime and inspect build
dependencies. Use `ccp doctor --deps` when you only need the toolchain report.
