# Connect Forgejo

> Connect a Forgejo server, such as Codeberg or your own instance, to AI CodeOps with a personal access token, and see what the platform does with your repos.

Source: https://aicodeops.dev/docs/git/forgejo

AI CodeOps works with Forgejo servers, whether you run your own or use a public instance. You connect with the server's address and a personal access token. Sessions then write changes on a new branch and open a pull request for review.

## Before you start

- The server's public **https** address, for example `https://forgejo.example.com`. AI CodeOps runs in the cloud and has to reach it over the internet.
- Addresses on private networks, `localhost`, link-local addresses and `.local` or `.internal` names are refused, as are URLs with a query string or `#fragment`.
- An account with write access to the repositories you want to use.
- On Codeberg (`https://codeberg.org`), read its [Terms of Use](https://codeberg.org/Codeberg/org/src/branch/main/TermsOfUse.md) first: they don't allow projects that mostly consist of code written by generative AI tools.

## Create a token in Forgejo

1. In Forgejo, open **Settings → Applications** and generate a new access token.
2. Grant read and write on **repository** (clone, push branches, create and merge pull requests) and read on **user** (show which account is connected).
3. Copy the token now. Forgejo shows it only once.

## Connect the token

1. In your workspace, open **Configure → Settings** and scroll to **Git Providers**.
2. On the **Forgejo** card, enter the **Instance URL**. It is required.
3. Paste the token into **or access token** and choose **Connect with token**.

AI CodeOps checks the token against the server before saving it. If you see "Token rejected — check the URL and key.", check the address and the token's scopes.

## OAuth

**Connect via OAuth** only works for the one Gitea or Forgejo server the platform's OAuth app is registered on. For any other server you will see "sign-in isn't set up on this server": use a token instead.

## What AI CodeOps does with the repository

- **Browse:** **Develop → Repositories** lists the repositories the account can see, with branches, files and pull requests.
- **Branches and pull requests:** when a change is approved and passes its [quality gates](https://aicodeops.dev/docs/quality-gates), AI CodeOps pushes a branch named `codeops/run-<id>` and opens a pull request into the project's default branch. Commits are authored as "AI CodeOps".
- **Merge:** a pull request the console opened can be merged from the console. The release gate runs again first.

AI CodeOps doesn't install webhooks on the server or comment on pull requests. It also doesn't read Forgejo Actions results; tests run in the session's own sandbox.

## Your token and your access

- A connection belongs to you, not the workspace. Workspace roles still decide what each member can do.
- The token is encrypted at rest (AES-256-GCM) and isn't written into any repository's Git configuration.
- To remove access, choose **Disconnect**, or delete the token in Forgejo. To rotate it, disconnect and connect again.

## Next steps

- [Create a project](https://aicodeops.dev/docs/projects) from a Forgejo repository.
- [Run your first session](https://aicodeops.dev/docs/sessions).
- [Troubleshooting](https://aicodeops.dev/docs/troubleshooting)
