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

# Sourcegraph

> Connect Sourcegraph to search code, repositories, and code host sync health

Connect Sourcegraph so CloudThinker can search code, repositories and code host sync health, and add, change or remove repository metadata (tags) after you approve it. It signs in with an access token.

## Prerequisites

* An existing Sourcegraph account or deployment containing the resources you want to inspect.
* Permission to create or obtain the credential described below.
* A CloudThinker workspace role that can add connections; see [Roles](https://docs.cloudthinker.io/guide/security/roles.md).
* An HTTPS route from CloudThinker to your service. For a private service, see [Reaching private services](https://docs.cloudthinker.io/guide/connections/overview.md#reaching-private-services).

## Setup

**1. Prepare the credential**

Obtain a Sourcegraph access token from the account that should perform searches. See the [vendor's authentication documentation](https://sourcegraph.com/docs/api) for the procedure that applies to your account.

**2. Add the connection**

Open **Settings → Connections**, find **Sourcegraph**, and click **Connect**. Enter the values in [Connection details](#connection-details).

Use your Sourcegraph instance URL. Keep TLS verification enabled when its certificate is trusted.

**3. Check the result**

Click **Connect** and wait for the connection check.

**Success state:** the connection shows **Connected**. Run the verification prompt below and confirm that the expected resources appear.

## Connection details

| Field | Required | What to enter |
| - | - | - |
| **Sourcegraph URL** | Yes | Your instance, such as [https://sourcegraph.example.com](https://sourcegraph.example.com), or [https://sourcegraph.com](https://sourcegraph.com). Default: `https://sourcegraph.com`. |
| **Access token** | Yes | A site admin token also shows code host sync health. |
| **TLS certificate** | Yes | Options: **Verify (recommended)**, **Skip SSL verification (self-signed)**. Default: `true`. |

## Required permissions

Read: the token's user can read the repositories you want searched; search sees only cloned repositories. Repository stats and code host sync health need a site admin token.

Change metadata: Sourcegraph must allow the token's user to edit metadata on that repository. If it refuses, use a user that can.

## Agent capabilities

| Capability | What agents can do | Approval |
| - | - | - |
| Code search | Search code, files and commits. | No |
| Repositories | List repositories, fetch and clone state, and one repository's metadata. | No |
| Sync health | Read code host sync errors (site admin token). | No |
| Add metadata | Add a metadata key and value to one repository. | Yes |
| Change metadata | Replace the value of a metadata key on one repository. | Yes |
| Remove metadata | Remove a metadata key from one repository. | Yes |

Changes run only after you approve them. Agents show the current and new value first. Batch changes, settings and code host changes stay in Sourcegraph.

### Verify the connection

```text theme={null}
Inspect my Sourcegraph connection. Identify the accessible account or resource scope and show a small sample without changing anything.
```

Confirm that the returned scope matches the credential you intended to connect. An empty result can mean missing data or restricted access; it is not proof that the service is healthy.

### Example prompts

```text theme={null}
Which repositories fail to fetch? Show the last error for each.
Add the metadata key "team" with value "payments" to repository github.com/acme/api.
```

## Troubleshooting

> [accordion] The token is rejected
>
> Sourcegraph answers 401. Create a new token under Settings → Access tokens and reconnect.

> [accordion] Stats or code hosts show an error
>
> These need a site admin token. Use one, or skip those sections.

> [accordion] The certificate is not trusted
>
> The instance uses a self-signed certificate. Reconnect with TLS certificate set to Skip SSL verification.

> [accordion] The URL is not accepted
>
> It must be the instance root. Reconnect with the exact https address.

## Security

* **Least privilege** — grant only the permissions the agents need for your use case; start read-only and widen later.
* **Read-only by default** — use read-only credentials unless you want agents to make changes through this connection.
* **Rotate credentials** — rotate keys and tokens on your normal schedule; CloudThinker picks up the new value when you update the connection.
* **Revoke on offboarding** — remove the credential at the provider when you delete a connection or a teammate leaves.

- Keep this integration's credential separate from personal daily-use credentials where your provider supports it.
- Revoke or rotate it in Sourcegraph when access is no longer needed, and update the connection after rotation.

## Related

> [card] [Connections](https://docs.cloudthinker.io/guide/connections/overview.md)
>
> Manage access to the services CloudThinker investigates.

> [card] [Approvals](https://docs.cloudthinker.io/guide/approvals/overview.md)
>
> Control which requested changes can run.


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