selan.ai
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?

selan agent-run <agent> <message>

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

▸ 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 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.

# 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.

How do I write a Claude Code agent file?

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

---
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.

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 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?