# CLI

## Prerequisites

- A Codebahn account
- Linux or macOS (amd64 or arm64)

The `codebahn` CLI manages your repositories, pull requests, issues, and CI from the terminal. One binary, OAuth login, auto-updates.

Source: [github.com/codebahn/codebahn-cli](https://github.com/codebahn/codebahn-cli)

## Install

```bash
curl -fsSL https://releases.codebahn.net/cli/install.sh | sh
```

This detects your platform, downloads the latest binary, verifies its SHA256 checksum, and installs to `~/.local/bin`. Override the location with `INSTALL_DIR`:

```bash
curl -fsSL https://releases.codebahn.net/cli/install.sh | INSTALL_DIR=/usr/local/bin sh
```

Or install from source (source builds skip auto-update):

```bash
go install github.com/codebahn/codebahn-cli/cmd/codebahn@latest
```

Builds are available for Linux and macOS on amd64 and arm64.

### Updates

The CLI checks for new versions once every 24 hours and prints a notice when one is available.

```bash
codebahn update
```

This downloads the new binary from `releases.codebahn.net`, verifies its GPG signature and SHA256 checksum, and replaces itself.

To check without installing: `codebahn update --check`. To silence the periodic check: set `CODEBAHN_NO_UPDATE_CHECK=1`.

## Authenticate

```bash
codebahn auth login
```

This opens your browser for OAuth authorization. After you approve, the CLI saves your tokens to `~/.config/codebahn/config.json` (it honors `XDG_CONFIG_HOME`). Tokens refresh automatically. Check the connection with `codebahn auth status`.

If you use [two-factor authentication](/docs/two-factor-authentication/), the browser asks for it during this sign-in. The token you get afterwards needs no second factor.

For CI or other headless environments, pass `--token` or set `CODEBAHN_TOKEN`. Create a token under **Settings > Applications** in your Codebahn account.

## Commands

When you run inside a Git repo, `--owner` and `--repo` are detected from the remote. Add `--json` for machine-readable output and `--no-color` to turn off colored output. Every subcommand accepts `--help`.

### User

| Command | Description |
|---|---|
| `user info` | Show current user info |

### Repositories

| Command | Description |
|---|---|
| `repo list` | List your repositories |
| `repo create` | Create a repository |
| `repo cat` | Read file content |
| `repo ls` | List directory contents |
| `repo tree` | Show the file tree |
| `repo log` | List commits |
| `repo branches` | List branches |
| `repo create-branch` | Create a branch |
| `repo delete-branch` | Delete a branch |
| `repo create-file` | Create a file via commit |
| `repo update-file` | Update a file via commit |
| `repo delete-file` | Delete a file via commit |
| `repo mirror` | Mirror a repo or org from GitHub/GitLab |
| `repo import` | One-time import from GitHub/GitLab |
| `repo list-remote` | Preview repos available via the GitHub App |

### Pull requests

| Command | Description |
|---|---|
| `pr list` | List pull requests |
| `pr get` | Show a pull request |
| `pr create` | Open a pull request |
| `pr update` | Update title, body, base, or assignees |
| `pr merge` | Merge a pull request |
| `pr diff` | Print the unified diff |
| `pr files` | List changed files |
| `pr reviews` | List reviews |
| `pr get-review` | Show a specific review |
| `pr review-comments` | List comments on a review |
| `pr create-review` | Create a review with inline comments |
| `pr submit-review` | Submit a pending review |
| `pr dismiss-review` | Dismiss a review |
| `pr delete-review` | Delete a pending review |
| `pr request-review` | Request reviews from users or teams |
| `pr cancel-review` | Cancel pending review requests |

### Issues

| Command | Description |
|---|---|
| `issue list` | List issues |
| `issue get` | Show an issue |
| `issue create` | Open an issue |
| `issue update` | Update title, body, assignees, or milestone |
| `issue state` | Open or close an issue |
| `issue comment` | Comment on an issue |
| `issue comments` | List comments |
| `issue get-comment` | Show a comment |
| `issue edit-comment` | Edit a comment |
| `issue delete-comment` | Delete a comment |
| `issue labels` | List labels |
| `issue add-labels` | Add labels to an issue |
| `issue remove-labels` | Remove labels from an issue |
| `issue create-label` | Create a label |
| `issue edit-label` | Edit a label |
| `issue delete-label` | Delete a label |
| `issue milestones` | List milestones |

### CI

| Command | Description |
|---|---|
| `ci list` | List workflow runs |
| `ci get` | Show a workflow run |
| `ci logs` | Print build logs (filterable by job) |
| `ci dispatch` | Trigger a workflow |
| `ci cancel` | Cancel a running build |

### Search

| Command | Description |
|---|---|
| `search all` | Search across code, repos, issues, and users |
| `search code` | Search code (with language and filename filters) |
| `search repos` | Search repositories |

### Examples

```bash
codebahn pr merge --index 42 --style squash
codebahn repo cat --ref main --filePath README.md
codebahn ci logs --run_id 7 --job build
codebahn repo mirror github.com/acme/backend --owner my-org
codebahn repo import github.com/acme --owner my-org -y
codebahn repo list-remote github.com/acme
```

## Migration

The CLI can mirror or import repositories from GitHub and GitLab, including bulk operations on entire organizations.

**List remote** previews which repos are accessible via the Codebahn GitHub App before you import or mirror:

```bash
codebahn repo list-remote github.com/acme
```

Use `--include` and `--exclude` with glob patterns to filter. Add `--json` for machine-readable output.

**Mirror** creates a pull mirror that stays in sync with the source:

```bash
# Single repo
codebahn repo mirror github.com/acme/backend

# Entire org
codebahn repo mirror github.com/acme --owner my-org --source-token $GITHUB_TOKEN -y
```

**Import** copies code, issues, PRs, labels, milestones, and releases as a one-time migration:

```bash
# Single repo
codebahn repo import github.com/acme/backend

# Entire org, skip wiki
codebahn repo import github.com/acme --owner my-org --source-token $GITHUB_TOKEN --no-wiki -y
```

For private repos and org-level operations, pass `--source-token` or set `GITHUB_TOKEN`. Use `--include` and `--exclude` with glob patterns to select repos from an org.

See also: [Migrate from GitHub](/docs/migrate-from-github/), [Migrate from GitLab](/docs/migrate-from-gitlab/), [Migrate from Forgejo](/docs/migrate-from-forgejo/), [Mirror GitHub repos](/docs/mirror-github-repos/).
