Headless CLI
opensre ask is OpenSRE’s headless CLI command. It runs one agent turn, prints
the response, and exits instead of opening the interactive shell. Each run is
saved as a resumable session unless you pass --ephemeral.
It uses the hosted model of the signed-in account (opensre account login), or
LLM_PROVIDER plus the provider API key on a machine that is not signed in, and
any tools configured with opensre integrations setup. Without either it exits
with status 1 before the agent runs and prints the command that fixes the
setup, such as opensre login <provider>.
Follow-ups and required input¶
When the agent completes the request, a terminal run prints a session ID and a command you can use for a later follow-up:
Session: 489e2ba8-3b7f-4fa2-bcdf-55a93177337c
Continue: opensre ask --resume 489e2ba8-3b7f-4fa2-bcdf-55a93177337c "<reply>"
Use the full ID or an unambiguous prefix:
If the agent cannot continue without a decision, it exits with status
needs_input and prints numbered options. Resume the same session with the
option number, or a custom answer when the question allows one:
For a batch of questions, pass a JSON object keyed by the displayed labels:
Use --ephemeral for scripts or one-off requests that should not write
resumable session history or print a session ID:
Prompt and response logging
has separate controls. Set OPENSRE_PROMPT_LOG_DISABLED=1 to disable it,
including for ephemeral requests.
Live activity¶
When both output streams are attached to a terminal, ask starts with a
Thinking… spinner with elapsed time. It switches to the active diagnostic
tool (or a neutral tool count for a batch) when tools are invoked. The final
answer remains on standard output without echoing raw tool transcripts. Piped
and --json runs do not emit progress, so their output remains
machine-readable.
Pass - as the prompt to read all of standard input:
File context¶
Attach an alert, log excerpt, deployment note, or other regular UTF-8 text file with
-i or --context-file while keeping the positional prompt as the instruction:
Repeat the option to correlate several files:
Worked example¶
Given alert.json:
{
"alert": "CheckoutLatencyHigh",
"service": "checkout-api",
"started_at": "2026-09-22T09:15:00Z",
"p95_latency_ms": 2410,
"baseline_p95_latency_ms": 420,
"error_rate_percent": 8.2
}
And deployment.md:
# Recent deployment
- Service: checkout-api
- Version: 2026.09.22-rc3
- Completed: 2026-09-22T09:12:00Z
- Change: Enabled the payment-routing client with a 3-second upstream timeout.
Run:
Response wording varies by model, but the result should use facts from both files. For example:
The deployment is a strong likely trigger for the alert:
- checkout-api rc3 completed at 09:12 UTC; the alert began three minutes later.
- P95 latency rose from 420 ms to 2,410 ms, about 5.7x baseline, with an 8.2%
error rate.
- The observed latency is consistent with requests waiting near the new
3-second upstream timeout.
Next action: disable the new client or roll back rc3, then verify whether
latency and errors return to baseline.
Attach up to 16 files. Files are treated as untrusted context, not operator instructions. Each file may contain up to 64 KiB, with a combined limit of 128 KiB. Empty, binary, and non-UTF-8 files are rejected before the agent starts. The combined limit also applies after JSON encoding, so content dominated by control characters, quotes, or backslashes may reach it earlier.
Review attachments for secrets before running the command. Their contents are sent to the configured LLM provider as part of the prompt.
When a resumed session is waiting for a numbered choice, submit that answer without context files. Attach files in the following turn instead.
Tool approvals¶
Read-only tools run automatically. Tools that mutate state, contact an external service, explicitly require approval, or do not declare their side effects are denied by default.
Reading the working directory is read-only, so a question about a repository
needs no flag: the agent reads, searches and lists its files with read_file,
search_files and list_files. See
Reading files for
what those tools leave out.
Authorize only the tools needed for this invocation by repeating
--allowed-tool:
opensre ask "inspect the repository and run its focused tests" \
--allowed-tool shell_run \
--allowed-tool github_cli
An unknown tool name is rejected before the agent starts. The authorization is
not saved and applies only to that process. The root --yes (-y) option does
not authorize agent tools.
--dangerously-bypass-approvals authorizes every approval-gated tool for that
invocation. Use it only in a trusted environment where the prompt and connected
integrations are controlled:
Do not combine the bypass flag with --allowed-tool. Neither option bypasses
the operating-system permissions or sandboxing that applies to OpenSRE.
Commands authorized through shell_run use the host environment's shell. See
Shell command syntax
for native Windows cmd.exe, PowerShell, WSL, and working-directory behavior.
JSON output and exit codes¶
Put the global --json option before ask for machine-readable output:
The command writes one JSON object with status, response, session_id,
questions, denied_tools, and error. Each question includes its title,
label, options, whether it accepts multiple selections, and whether a custom
answer is allowed. The error value is either null or an object with
message and suggestion.
For required input, read session_id and questions from that object, then
pass the answer to another JSON invocation of the same session:
opensre --json ask "investigate the failing CI"
opensre --json ask --resume 489e2ba8-3b7f-4fa2-bcdf-55a93177337c "1"
The first result can be needs_input (exit code 4) with a question like:
{"status":"needs_input","response":"Which repository?\n 1. Tracer-Cloud/opensre\n 2. Another repository","denied_tools":[],"session_id":"489e2ba8-3b7f-4fa2-bcdf-55a93177337c","questions":[{"label":"Repository","title":"Which repository?","options":["Tracer-Cloud/opensre","Another repository"],"multi_select":false,"allow_custom":true}],"error":null}
After the answer, a successful result has status: "success", the same
session_id, and an empty questions array.
JSON mode emits no terminal-only continuation footer; use the returned ID.
--json is a global option, so it must appear before ask on both invocations.
Without --json, a required question also prints Session: ID on stderr when
output is redirected, so the choice can still be resumed.
| Exit code | Meaning |
|---|---|
0 |
The agent completed the request. |
1 |
Setup or agent execution failed. |
2 |
The command arguments were invalid. |
3 |
A tool required approval and was denied. |
4 |
The agent needs structured user input; resume the returned session. |
130 |
The invocation was interrupted with SIGINT. |
143 |
The invocation was terminated with SIGTERM. |
Markdown source: View on AtomGit·Content from the open-source project op/opensre