# Work with source control and pull requests

**[Koder](https://www.aixplain.com/support/articles/get-started-with-koder)** works with the services that host your code, so you can open a pull request from your changes and start a session from someone else's. This article explains how to connect your code host, how to work in a worktree per chat, how to open a pull request and how to pick up a pull request with its review comments.

> Source control works in Koder in aixplain Desktop on macOS, Windows and Linux, and in the `koder` CLI. It supports GitHub, GitLab, Bitbucket, Azure DevOps, Forgejo and Gitea, including servers you host yourself. Koder is in early releases (version 0.x), so features can change from one release to the next.

## Connect your code host

Open **Settings → Source control**, then sign in to each host one of three ways:

- **A token saved in Koder:** under **Accounts**, select **Add token**, paste an **Access token** and select **Save token**. Koder checks it, then keeps it in your system's keychain.
- **An environment variable:** Koder reads tokens such as `GITHUB_TOKEN`, `GITLAB_TOKEN`, `GITEA_TOKEN`, `BITBUCKET_TOKEN` or `AZURE_DEVOPS_EXT_PAT`.
- **The host's own CLI:** if you're signed in with `gh auth login`, `glab auth login`, `tea login add` or `az login`, Koder uses that sign-in.

| Host | Where to create a token |
| --- | --- |
| **GitHub** | Your GitHub settings, under **Developer settings → Personal access tokens** |
| **GitLab** | Your GitLab user settings, under **Access tokens** |
| **Forgejo, Gitea** | Your user settings, under **Applications** |
| **Bitbucket** | An Atlassian API token, with your **Username or email** |
| **Azure DevOps** | A personal access token |

After you change a token, select **Check again**.

> **Note:** Bitbucket no longer accepts app passwords. Use an Atlassian API token instead.

### Connect a server you host

For GitHub Enterprise, GitLab, Forgejo or Gitea on your own servers, go to **Your own servers**, select **Add server**, and enter its **Server name** and, if it differs, its **Web address**.

## Work in a worktree per chat

Turn on **New worktree** when you start a chat, and Koder works on a new branch in its own folder, named from your request. Chats in separate worktrees don't change each other's files.

You choose how branches are named: a prefix and words from your request, the kind of change chosen by the model, or your own instructions. To clean up, open **Finished worktrees** and select **Remove finished**.

## Open a pull request

1. Review and commit your changes in the **Review** panel.
2. Select **Create pull request**. On GitLab, it's a merge request.
3. Check the **Title** and **Description**, which Koder drafts from your changes, and the branch it goes into.
4. Turn on **Draft** if it isn't ready for review.
5. Create it. Koder pushes your commits first.

Koder then watches the pull request and tells the chat when checks pass or fail, when it's merged or closed, and when new comments arrive. In the terminal, use `/pr`.

> **Important:** Pushing and opening a pull request publish your code to the host. Pushing always asks first, in every access mode.

## Start from a pull request

1. Choose **Start from a pull request**.
2. Enter the **Pull request link or number**.
3. Choose **In a new worktree** or **In this checkout**, then select **Start session**.

Koder checks out the branch and begins with the pull request's description, comments and diff. To address feedback, select **Add review comments**, and the unresolved comments go into your message.

### Example requests

- "Address the review comments on this pull request."
- "Fix the failing checks and push."
- "Summarize what this pull request changes and what could break."

## Limitations

- Koder reads checks only on hosts that report them to it.
- On a public repository, a Scan fix is offered as a patch to copy, not as a pull request.
- Starting a session from an issue isn't available yet.

## Troubleshooting

### Koder can't open a pull request

Run `koder pr` in the project. It says what's missing: a remote, the host's CLI, a supported host or a sign-in.

### My token isn't accepted

Check that it hasn't expired and that it can read and write the repository, then select **Check again** in **Settings → Source control**.

## Frequently asked questions

### Where are my tokens stored?

In your system's keychain, when you save them in Koder. Tokens from environment variables or a host's CLI stay where they are.

### Can I use Koder with a self-hosted GitLab or Gitea?

Yes. Add it under **Your own servers** in **Settings → Source control**.

## Get help

- **Review and commit:** see **[Get started with Koder](https://www.aixplain.com/support/articles/get-started-with-koder#review-and-commit-changes)**.
- **Report a problem:** email **care@aixplain.com** with your code host and what happened.
