Skip to main content

Headless & CI

When a person runs the CLI, they use 4rged login on a laptop — browser sign-in, then commands from a repo. When a pipeline runs the CLI, there is no browser: the job uses a User API key stored as a CI secret, installs the CLI, runs the agent, and passes or fails the build from the result.

That second pattern is headless — the same X4RGE agents and org rules as desktop, but built for GitHub Actions, GitLab CI, cron, and internal bots.

This page is for teams wiring the CLI into automation. For a first install on your machine, see Installation. For when to use the CLI at all, see CLI overview.

What this page is for

You want to…Headless & CI helps you…
Understand headlessRun agents without a human at the keyboard
Authenticate in CIAPI keys in secrets — not browser login
Gate merges on agent resultsExit codes and structured output
Track automated runsRun IDs for polling and artifacts
Keep pipelines stablePin CLI version so jobs do not drift
Pick local vs cloud in CIShort work on the runner; long work in cloud
Stay within company policySame models, budgets, and repos as desktop
No CI bypass

Automation uses your organization's model control and usage. Denied models and budget stops fail the job — same as for a developer on a laptop.

Who this page is for

You are…Start here
Developer adding a bot to one repoSet up for CITypical pipeline flow
Platform / DevOps rolling out org-wideFor org admins + pin version + key rotation
Org admin enabling keys and budgetsRules that still apply + Settings
PM / lead wondering if CI fitsHeadless vs cloud automations

You do not need to be an org admin to run headless on a single repo — you need a key, a secret, and access to the project.

Understand headless at a glance

TermPlain meaningExample
Headless runCLI started by a script or CI jobGitHub Action on every PR
User API keyLong-lived secret for automationCreated in dashboard → Integrations
CI secretEncrypted store for the keyX4RGE_API_KEY in GitHub Secrets
Structured outputMachine-readable resultJSON with run ID and status
Run IDReference until the agent finishesPoll or upload as artifact
Pinned CLI versionFixed install in every job1.2.0 until you bump it deliberately
Exit codeHow CI knows pass vs fail0 = success; non-zero fails the job

First time wiring CI — typical order:

  1. Create API key (dashboard)
  2. Save as CI secret (never in git)
  3. Add job steps: install CLI (pinned) → whoamiagent run
  4. Optional wait step for long or cloud runs
  5. Fail the job on error; store JSON summary if useful
  6. Ask admin to link repo on the project if policy errors appear

Command flags change over time — 4rged.ai/cli/install has the current reference. This page explains concepts that stay stable.

Headless vs interactive login

InteractiveHeadless
WhereYour laptopCI, cron, server bot
Sign-in4rged login + browserAPI key in secrets
DocInstallationThis page
Rotate whenNew machine / sign outOffboarding, leak, quarterly
Works in GitHub Actions?No — no browserYes
Never commit secrets

API keys belong in GitHub Secrets, GitLab protected variables, or a vault — never in the repository, workflow files, or log output.

Headless vs cloud automations

Both can run agents without a person watching — choose by who owns the trigger:

Headless CLI in CICloud automations
Triggered byYour pipeline (PR, schedule, manual workflow)Events and rules in X4RGE cloud
Runs onCI runner (install CLI each job)X4RGE cloud runtime
Best for"Run agent as part of this build""When X happens, start agent in cloud"
You manageYAML, secrets, pinned CLIAutomation config in product

Many teams use CLI in CI for PR checks and cloud automations for ongoing monitors — not either/or.

Choose local vs cloud in CI

Same CLI command — different where the work runs:

Run in CI…When to choose it
Local (on the CI runner)Short prompts — review diff, lint summary, small fix attempt
Cloud handoffLong generation, large refactors, jobs that exceed runner timeout
SignalAction
Job times outAdd wait timeout or switch to cloud
Runner cost is highOffload long work to Cloud agents
Need result in same jobPrefer local if it finishes within limits

Why headless matters

Without headless CLIWith headless CLI
Agents only when someone is at a laptopPRs and schedules trigger agents automatically
Manual copy-paste of agent outputJSON and run IDs for the next pipeline step
No merge gate on agent reviewPipeline fails when policy or agent fails
Fragile "latest CLI" installsPinned version — predictable behavior
Ad hoc personal keys in scriptsDocumented secret + rotation

How headless fits together

PieceRoleLearn more
API keyProves identity in CISet up for CI
CLI install4rged on the runnerInstallation
Project scopeRepos, policy, usageProjects overview
Agent runPrompt → work → outputCLI overview
Run ID / exit codePass or fail the jobWhat success looks like
Cloud handoffLong work off the runnerCloud agents
AlternativeEvent-driven cloudCloud automations

How automation works

PieceWhy it matters
Scriptable outputNext step reads run ID, summary, or PR link
Run IDPoll, artifact upload, trace in Usage
Exit codeStandard CI pass/fail — non-zero on policy or agent error
Project flagSame repos and rules as desktop for that initiative
Task link (optional)Tie run to Tasks & views

One-line flow: install → verify key → agent run → (wait) → pass or fail.

Set up for CI

  1. Create a User API key

    Dashboard → Integrations → User API keys. If missing, an org admin enables keys in Settings.

  2. Store as a CI secret

    Name it clearly (e.g. X4RGE_API_KEY). Map into the job environment. Never log the value.

  3. Install pinned CLI in the job

    Same installer as Installation, with a fixed version — see Pin the CLI version.

  4. Verify before heavy runs

    Run 4rged whoami (or JSON variant) so bad keys fail in seconds, not after a long agent run.

  5. Run with project + clear prompt

    Use your project slug when the org scopes repos. Write a prompt the job can repeat safely (review rules, doc sync scope, etc.).

Use a bot or service account when possible

A dedicated automation user (not a personal developer key) simplifies rotation and audit when someone leaves the team.

Typical pipeline flow

Same shape for GitHub Actions, GitLab, Jenkins, or other CI:

  1. Checkout

    Clone the repo the agent should read or modify.

  2. Install CLI

    Pinned version your platform team approved.

  3. Authenticate

    Inject secret; confirm org with whoami.

  4. Run agent

    Focused prompt; project + json output when scripts parse the result.

  5. Wait (if needed)

    Local runs may finish inline; cloud or long runs need poll/wait by run ID with a timeout.

  6. Gate

    Non-zero exit fails the pipeline; optional artifact or PR comment from JSON summary.

Full provider YAML samples live in hidden operator notes and on the install page — adapt steps above to your provider's syntax.

What success looks like

OutcomeWhat it means for the team
Job green, exit 0Agent completed; policy allowed models and repos
Job red, policy errorModel, budget, or repo blocked — fix config, not the prompt
Job red, agent errorAgent failed task — treat like a failed test; review logs
JSON artifact savedDebugging and audit without re-running the agent
Run ID in logsTrace spend and history in Usage

A healthy pipeline fails loudly on policy problems so bad merges do not slip through.

Pin the CLI version

Problem with "always latest"Benefit of pinning
Job breaks with no app code changeUpgrades are deliberate
Flags differ between branchesSame behavior on main and PRs
Hard to reproduce locallyMatch pinned version on a dev machine

Pick a version your org tested; bump it in one test pipeline before company-wide rollout. Version env details are on the install page and in operator notes below.

Rules that still apply

ControlWhat happens in CI
Model controlDisallowed model → job fails with policy message
Usage / budgetHard/soft stop may block or warn
Project + repo linkUnlinked repo may fail when enforcement is strict
MembershipAPI key user must access the project

Check Dashboard → Usage for denial hints; confirm repos on the project.

For org admins

Before enabling CI for many teams:

StepAction
CLI modelsSensible default for CLI in Model control
BudgetWarn vs stop for automation that could use on-demand capacity
ProjectsCI repos linked to the right projects
KeysEnable API keys; document rotation; revoke on offboarding
OwnershipName who owns the org CI secret and approved CLI version
AlternativeConsider Cloud automations for always-on monitors

In practice

You want to…Do this
Agent review on every PRSecret + pinned install + review prompt + fail on error
Nightly doc syncScheduled job; cloud if generation is long
Block merge on agent failureRely on exit code; store JSON artifact for reviewers
Link to Jira-style ticketsPass task context — Tasks & views
Save CI runner minutesCloud for multi-hour work
Debug "it worked yesterday"Check unpinned CLI, revoked key, budget stop
Avoid maintaining YAMLEvaluate Cloud automations

Fix CI issues

  1. Fails on first step (auth)

    Wrong secret name, revoked key, or keys disabled in Settings — recreate and update CI.

  2. whoami OK but agent denied

    Model not allowed, budget stop, or missing project access for key user.

  3. Repo / project error

    Link repo on project; verify project slug matches GitHub integration.

  4. Job hangs

    Add timeout on wait; use cloud for long runs.

  5. Flaky without code changes

    Unpinned CLI upgraded — pin version and retest.

  6. Key person left company

    Rotate API key; update CI secret; revoke old key in Integrations.

  7. Still stuck

    Troubleshooting or org admin.

Questions about headless and CI?

QuestionAnswer
What does headless mean?CLI runs in automation without browser login
Can I use 4rged login in CI?No — use an API key
Where do I put the key?CI secrets / vault — never in git
Who creates keys?Usually each user; admins may restrict
Does CI usage bill like desktop?Yes — Usage
GitHub vs GitLab?Same CLI; only secret syntax differs
Local or cloud in CI?Short = local runner; long = cloud handoff
Headless vs cloud automations?CI owns trigger vs X4RGE event rules — see above
Where are YAML examples?Install page + hidden operator section
How often rotate keys?Offboarding, leak, or quarterly
Can I run CI without a project?Depends on org; most teams pass project for policy
What if the job is green but wrong?Tighten prompt, add review step, fail on JSON fields