---
title: "Claude Code agents in GitHub Actions & GitLab CI · Selan"
description: "selan agent-run runs a Claude Code agent with nobody watching: an agent file and an API token in a GitHub Actions or GitLab CI job, under company limits."
url: https://selan.ai/docs/agents
updated: 2026-11-24T21:08:23+02:00
---

Agents

Docs · Agents

# Run Claude Code agents in CI

`selan agent-run` runs a Claude Code agent with nobody watching, and prints a line per tool call while it works.

## What does selan agent-run do?

```bash
selan agent-run <agent> <message>
```

It runs one of the agents in your repository's `.claude/agents/`, headless:

```text
▸ Bash  Show the full diff
▸ Read  internal/cli/agentrun.go
▸ Bash  Run the test suite
  x     Test Suites: 1 failed, 77 passed
· Four findings, one question.
─── success  104s  $0.36
```

**It is the same launch as `selan claude`:** same session, proxy, company settings, model resolution and repository attribution. It spends your company's key, has the same per-user limits, and shows up in Usage and Logs. Its requests send `x-selan-application: selan-local-agent`, so Usage shows them as **Selan local agents**.

**It skips every permission prompt, and asks nothing first.** Naming the agent on the command line is the consent. What the agent can reach is the boundary.

## How does a CI job sign in?

A CI job cannot `selan login`. An owner mints a token under [**Settings → API tokens**](https://control.selan.ai/settings/access) and the job carries it in the environment as `SELAN_TOKEN`.

**Give each job its own token, named after the job.** A token spends as itself, under an address like `ci-review@tokens.selan.ai`, so Usage and Logs show the job. You can revoke it from the same panel, and the per-user spend limit applies. A company holds up to 50 live API tokens; `selan login` sign-ins and the tokens Reactor mints for remote-agent runs do not count.

```bash
# GitHub
gh secret set SELAN_TOKEN --body 'selanct_...'

# GitLab: Settings → CI/CD → Variables, Masked and Protected
```

More on running without a browser: [docs → running unattended](https://selan.ai/docs#ci).

## How do I write a Claude Code agent file?

An agent is one Markdown file, `.claude/agents/<name>.md`: front matter, then the instructions.

```markdown
---
name: code-review
description: Reviews a branch's diff and writes review.md. Changes nothing, posts nothing.
tools: Bash, Read, Grep, Glob, Write
---

You review one branch's changes and write what you find to `review.md`.

Two things you must not do: change any code, and post anything anywhere. Write
`review.md` and stop. Something else decides what happens to it.
```

Worth copying:

-   **It writes a file; it does not post.** The pipeline posts, so the agent needs no GitHub or GitLab token.
-   **`tools:` is a whitelist.** A reviewer does not need `Edit`, so leave it out.
-   **Your conventions are already in context.** Claude Code loads `AGENTS.md` (or `CLAUDE.md`) itself. Tell the agent to work _against_ that file, not restate it.

## How do I run it in GitHub Actions or GitLab CI?

Check out deep enough to see what you work on, install `selan` and Claude Code, run the agent with `SELAN_TOKEN` in the environment, and use the file it wrote. The workspace variable is `$GITHUB_WORKSPACE` on Actions, `$CI_PROJECT_DIR` on GitLab.

```bash
curl -fsSL https://dl.selan.ai/install.sh | sh
npm install -g @anthropic-ai/claude-code

selan agent-run code-review "…what to do. Write the result to $GITHUB_WORKSPACE/out.md."
```

**Give the agent an absolute path for anything it writes.** With a bare filename the file can land outside the workspace, the job stays green, and the next step finds nothing.

A complete pipeline for GitHub Actions and GitLab CI is on the [code review](https://selan.ai/docs/agents/code-review) page.

## What is good practice for an agent in CI?

-   **Advisory, never a gate.** `continue-on-error` on GitHub, `allow_failure` on GitLab, including on the step that posts. A model's opinion should not block a merge.
-   **Set a timeout.** Twenty minutes is generous for most jobs.
-   **Cancel the previous run on a re-push** (a concurrency group keyed on the merge request), or two runs finish in either order.
-   **One agent, one job.** A reviewer should not also fix things.
-   **On a self-hosted runner, install into the job's temp directory** (`SELAN_INSTALL_DIR="$RUNNER_TEMP/bin"`), and put that directory on `PATH` _before_ running the installer, or it adds a `PATH` line to the runner user's shell profile on every job.
-   **Watch the first few runs.** The run log prints the cost.

## Which agents can I copy?

-   [Code review → Reviews every pull request and posts one comment: a severity table, a block per finding with a fix.](https://selan.ai/docs/agents/code-review)
-   [Minimise comments → Deletes the comments that restate their code and keeps the ones that explain why. Runs on a cheap model from a pre-commit hook.](https://selan.ai/docs/agents/minimise-comments)

## Related

-   [Claude Code in GitHub Actions for a team](https://selan.ai/guides/claude-code-github-actions)
-   [Claude Code in GitLab CI for a team](https://selan.ai/guides/claude-code-gitlab-ci)
-   [Claude Code in CI without API keys](https://selan.ai/guides/claude-code-without-api-keys#ci)
-   [Code review](https://selan.ai/docs/agents/code-review)
-   [Self-hosted runners](https://selan.ai/docs/runners)
