Running in CI and scripts
Explyt CLI runs a single prompt and exits when you start it with the -p flag (text output) or --mode json (event output). It doesn't need a terminal then, so you can run the agent in GitHub Actions, GitLab CI, cron, and shell scripts: to review a diff, analyze failures, and run tests.
Linux and macOS are supported. On Windows a run starts, but it is neither supported nor tested.
How to call it
explyt -p "review the diff" # print mode: the final answer on stdout
explyt --mode json -p "list the files" # JSON mode: JSONL events on stdout
git diff | explyt -p "review this" # piped text is added to the prompt
- Only the answer (print) or the events (JSON) go to stdout. All messages of the agent itself go to stderr.
- Quote the prompt. Every unquoted word becomes a separate prompt, and only the answer to the last one is printed.
- Pass a prompt from a variable after
--:explyt -p -- "$PROMPT". Without--, a prompt that starts with-is read as a flag:--permission-mode=bypassPermissionsinside$PROMPTwould allow any command to run. A word starting with@stays a file to attach even after--, so pass text you don't control through stdin, not on the command line. - Write a JSON run as
--mode json -p "<prompt>". A prompt before the flags requires-p:explyt "review" -pworks, whileexplyt "review" --mode jsonis rejected as an unknown command. - Subcommands (
update,login,plugin,tuiand others) work only as the first argument. In a run with-panywhere else they reach the model as a prompt:explyt -p updateasks the model about "update". - A bare
explytwithout a terminal refuses to start: it is the terminal UI. - A run without a prompt (an empty
-p, an empty pipe, an unset$PROMPT) exits with code 1 before any model request. - If nothing is piped in and the job's stdin may stay open, add
< /dev/null: the agent reads a piped stdin to its end before it starts. A GitHub Actions step closes stdin itself. - Pass command output through a pipe or a file, not through
@<(git diff): the engine skips a zero-size file, and a process substitution reports zero size.
Model and keys
Set the model explicitly: --model <provider>/<model>. Without the flag the agent picks a model itself, usually the provider's most capable and most expensive one. explyt --list-models prints the model list (without -p, so the list goes to stdout).
Priority when a key is set in several places: --api-key, auth.json, apiKey in models.json, the provider's environment variable. Don't pass the key through --api-key: it is visible to every process on the runner and can end up in the step's log.
A provider key from the environment
A known provider (Anthropic, OpenAI, Google, OpenRouter, Mistral, and others) needs no file. Set the provider's variable from a CI secret, for example ANTHROPIC_API_KEY, OPENAI_API_KEY, or OPENROUTER_API_KEY, and pass --model <provider>/<model>.
Explyt models
You can't sign in with /login on a runner, so in CI Explyt models are connected through Explyt Gateway with a personal API key from your personal account. The API key is available on Community and paid plans. Describe the gateway in models.json as your own provider. A value of the form "$NAME" is read from an environment variable:
{
"providers": {
"explyt-gateway": {
"baseUrl": "https://api.explyt.ai/openai/api/v1",
"api": "openai-completions",
"apiKey": "$EXPLYT_API_KEY",
"models": [{ "id": "autobalanced" }]
}
}
}
Run with --model explyt-gateway/autobalanced and set EXPLYT_API_KEY from a secret. autobalanced routes requests to mid-range models itself, see Models and automatic selection. Other model IDs are listed at https://api.explyt.ai/openai/api/models.
Your own provider
Any server with a supported API (a corporate proxy, vLLM, LM Studio, a cloud gateway) is described in models.json as a provider of its own. apiKey and the headers values can name environment variables:
{
"providers": {
"corp": {
"baseUrl": "https://llm.example.com/v1",
"api": "openai-completions",
"apiKey": "$CORP_LLM_KEY",
"headers": { "X-Team": "$CORP_TEAM" },
"models": [{ "id": "qwen2.5-coder-32b" }]
}
}
}
Run with --model corp/qwen2.5-coder-32b. The api field sets the server protocol: openai-completions (most OpenAI-compatible servers), openai-responses, azure-openai-responses, anthropic-messages, google-generative-ai, or mistral-conversations. How to connect your own provider in the terminal is described on the Your own providers and local models page.
Where models.json and auth.json live
Both files are in the agent directory:
- installed with the installer:
<installation root>/agent, by default~/.local/share/explyt-ai-agent/agent; - installed with npm for the duration of a job (see Pin a version):
$XDG_DATA_HOME/explyt-ai-agent/agent, or~/.local/share/explyt-ai-agent/agentifXDG_DATA_HOMEis not set.
The PI_CODING_AGENT_DIR variable overrides the agent directory for either kind of installation with a directory of your choice, for example the one where the job writes models.json itself.
Permissions
A run starts in the permission mode of a terminal session: default, unless permissions.defaultMode sets another one (see Settings). In default, a call that would require confirmation is blocked because nobody can answer, and the model is told why. To let every call run:
explyt --permission-mode bypassPermissions -p "fix the failing test"
A continued chat (--continue) starts in the mode saved with it, and a saved afk starts as bypassPermissions. See Permission modes for details.
A job that works with pull request content follows any instructions in it. Until a person you trust has read that content, don't give the job secrets in any permission mode.
defaultblocks only the calls that would ask for confirmation. Other commands run without questions, including network commands (curl) and commands that print the environment.- A run loads project resources the same way as the terminal:
.explyt/settings.json, rules (.explyt/rules/,AGENTS.md), skills, helper agents, model profiles and enabled Marketplace plugins. It also reads rule and skill files of other agents (CLAUDE.md,.claude/and others) for the agents you allowed inotherAgents. - A run asks nothing, so project MCP servers and project hook files run only with an answer recorded earlier or under the global
allowpolicy (mcp.projectServers,hooks.projectFiles). Underallow, their commands come from the project files and run before the model sees anything. - The engine doesn't load the project's
.pisettings, system prompts, packages, and extensions.
Don't pass text from a pull request, issue or comment on the command line. Keep the -p argument your own fixed text, and pass the untrusted text through stdin, where the agent reads it as plain text: write it to a file and redirect < "$RUNNER_TEMP/input.txt".
In GitHub Actions, never put ${{ github.event.* }} or any other expression whose value someone else controls inside run:: the runner pastes the value into the script before the shell starts, so it can run commands. Pass the value through env: and refer to the variable.
on: pull_request gives a pull request from a fork no secrets, so a review job there has no key and fails. Don't switch it to pull_request_target or to workflow_run with a checkout of the pull request head: both hand the secrets to the fork's content. A pull request from your own repository does get secrets, so in the example below the key lives in a GitHub environment with required reviewers: the job waits until a reviewer has read the pull request and approved the run, and only then sees the key. Create the environment (agent-review in the example) under Settings → Environments, add yourself or your team to Required reviewers, turn on "Prevent self-review", and store the key as an environment secret, not a repository secret.
Installing on a fresh runner
The installer installs the latest version of the chosen channel:
curl --proto '=https' --tlsv1.2 -fsSL https://explyt.ai/cli/install.sh | sh -s -- --channel stable
Without a terminal the installer doesn't add ~/.local/bin to PATH; it only reports the line to add. A later step calls ~/.local/bin/explyt by its full path or adds the directory first:
echo "$HOME/.local/bin" >> "$GITHUB_PATH"
See Installation and updates for details.
Pin a version
The installer doesn't accept a version. To pin one, install the package into the job's temporary directory and run it from there. This needs Node.js 22.19 or newer on PATH, for example from actions/setup-node:
npm install --prefix "$RUNNER_TEMP/agent" @explyt/ai-agent@<version>
exec "$RUNNER_TEMP/agent/node_modules/.bin/explyt" -p -- "$PROMPT"
Such an installation adds nothing to PATH and doesn't apply the transitive dependencies pinned in the release, so they may differ from the managed installation. npx is not recommended in CI: npm stays the step's top process and doesn't pass on every cancel signal.
Cancelling and time limits
Make the agent the last command of the step with exec:
exec explyt -p -- "$PROMPT"
On cancel, the runner signals only the step's shell. With exec, the agent itself becomes that process, so it stops at once. Without exec, the shell ends and the agent keeps working and spending tokens until the runner tears the job down. A pipe into the agent (git diff | exec explyt …) also keeps the shell on top, so pass the output through a file:
git diff > "$RUNNER_TEMP/diff.txt"
exec explyt -p "review" < "$RUNNER_TEMP/diff.txt"
Give the step a time limit (timeout-minutes in GitHub Actions): the agent has no turn or time limit of its own. If the agent is killed outright (kill -9, the OOM killer), its engine notices within about a second and stops by itself.
Exit codes
| Run | Exit code |
|---|---|
| print: the answer was received | 0 |
| print: the answer ended with an error or an abort | 1 |
| print: the answer was cut off at the model's output token limit | 1; the partial answer is on stdout, a warning on stderr |
| JSON: any model outcome | 0, the outcome is recorded in the events |
| no prompt | 1 |
a UserPromptSubmit hook blocked the prompt | 1; the reason is on stderr |
| no key found, or the engine didn't start | non-zero |
| cancelled by a signal | 128 + the signal number: 130 for SIGINT, 143 for SIGTERM |
Cancelling a GitHub Actions step with exec explyt -p ... gives 130: the runner sends SIGINT first.
A complete GitHub Actions example
name: review
on: pull_request
permissions:
contents: read
jobs:
review:
runs-on: ubuntu-latest
environment: agent-review # required reviewers; the key is an environment secret
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: false
- name: Install the agent
run: curl --proto '=https' --tlsv1.2 -fsSL https://explyt.ai/cli/install.sh | sh -s -- --channel stable
- name: Review the diff
env:
EXPLYT_API_KEY: ${{ secrets.EXPLYT_API_KEY }}
BASE: ${{ github.base_ref }}
run: |
mkdir -p ~/.local/share/explyt-ai-agent/agent
cat > ~/.local/share/explyt-ai-agent/agent/models.json <<'EOF'
{"providers":{"explyt-gateway":{"baseUrl":"https://api.explyt.ai/openai/api/v1","api":"openai-completions","apiKey":"$EXPLYT_API_KEY","models":[{"id":"autobalanced"}]}}}
EOF
git diff "origin/$BASE...HEAD" > "$RUNNER_TEMP/diff.txt"
exec ~/.local/bin/explyt --model explyt-gateway/autobalanced -p "Review this diff" < "$RUNNER_TEMP/diff.txt"
What's next
- Workflows: multi-stage subagent scenarios that also run without a terminal:
explyt --workflow <name>. - Permission modes: how
default,paranoid,bypassPermissionsandafkwork.