Skip to main content
mcode exec runs one task without starting the TUI. It is designed for automation, batch processing, and reproducible evaluations. Before running, sign in or configure a working API-key provider.

Minimal invocation

Set a workspace and machine-readable output:

Choose task instructions

Starting with 0.4.7, regular mcode exec tasks can select system instructions with --prompt-mode:
Each mode uses a complete system template bundled with the installation. Tools and permissions still follow the current TUI configuration. This option applies to regular exec tasks.When resuming with --session or --continue, the selected mode must match the saved session mode. Pass the same --prompt-mode again for a session using a non-default mode. Start a new session if an older session has no saved mode information.

Set reasoning effort for one run

Starting with 0.4.9, mcode exec and mcode exec review accept --effort as a run-only override:
Use --effort on its own or together with --model. The level must be supported by the selected model. Unsupported levels and models without effort support fail with a non-zero exit code before the task starts.The override is not saved to the session. Resuming later with --session or --continue and no --effort uses the session’s original level. #variant is part of a model identity: --model provider/model#high does not replace --effort high.

Input

Positional prompt

Text from stdin

Read stdin only when explicitly requested with --input -:
Do not combine --input - with a positional prompt.

JSON from stdin

--input-format json accepts a JSON string or an object such as { "prompt": "..." }:

Attachments

Use --file for code, logs, images, videos, and other supported files. Paths resolve relative to --cwd:
A run accepts up to 10 files and 100 MB total. A file-only invocation is valid when at least one --file is provided.

Options

--session and --continue cannot be combined. Headless rejects --permission ask because it has no interactive host; use the TUI or ACP when a human must approve an action.

Output formats

Task results go to stdout and diagnostics go to stderr, so stdout can be passed safely to jq, CI artifacts, or another process.

text

Prints the final answer for humans or simple Shell pipelines.

json

Prints one stable ExecResult JSON document:
status can be succeeded, failed, timeout, cancelled, or limit_exceeded. The error, model, and usage fields are optional; check status first.

stream-json

Prints newline-delimited, versioned events for live progress. Events include schemaVersion, sequence, timestampMs, runId, sessionId, and turnId. Common types are:
  • exec.started and exec.completed;
  • session.started and session.resumed;
  • turn.started, turn.completed, and turn.failed;
  • item.started, item.updated, and item.completed.
Process events by sequence and preserve forward compatibility for unknown event types.

Structured output

--output-schema accepts an inline JSON object or a Schema file. The final answer must be JSON matching the Schema:
Parsing or validation failures return status: failed with error code STRUCTURED_OUTPUT_INVALID. --output-last-message writes atomically only after a successful run and Runtime shutdown; a write failure is reported as a failure.

Sessions and recovery

Continue an existing session in a selected workspace:
If a session has a pending questionnaire or permission request, Headless does not wait for it. The run returns an interaction error and asks you to use the TUI or ACP first.

Timeouts, limits, and cancellation

SIGINT, SIGTERM, and SIGHUP cancel the current run. In CI, set a timeout and step limit, and preserve stdout and stderr separately.

Exit codes

Check both the process exit code and the JSON status: