Headless and pipe mode¶
You can run asksh non-interactively in scripts, CI pipelines, and Unix pipes without launching the TUI.
When pipe mode activates¶
asksh enters headless pipe mode whenever any of these is true:
- You pass
-por--pipe. - You pass
-xor--exec. - You pass
--json. - Standard input is not a TTY (for example data piped via
|) and--hookis not set.
Piping standard input¶
When standard input is not a TTY, asksh reads up to 64 KB (65536 bytes), trims cleanly at a UTF-8 boundary, and appends \n[stdin truncated to 64KB] if the input exceeded 64 KB.
The stdin content is sent alongside your prompt:
Headless runs never resume an earlier interactive session.
Executing suggested commands (-x / --exec)¶
Pass -x (or --exec) to run the command the model suggests via suggest_command:
asksh runs the suggested command on the active --target and prints its stdout and stderr.
Safety and permissions in pipe mode¶
- High-danger refusal:
-xrefuses to run any command ratedhighdanger (by the model or by AST preflight) unless you also pass--yolo(or setyolo = trueinconfig.toml).lowandmediumdanger commands run without prompting. - Tool approvals: Because there is no interactive TUI in pipe mode, any tool call that evaluates to
Askunderpermissions.tomlis automatically denied unless allowed by a rule or bypassed with--yolo. - Proposed plans: If the model returns
propose_plan, headless mode formats the plan as plain text and does not execute its steps. - Turn limit: Headless mode caps multi-turn tool loops at 64 turns.
Structured JSON output (--json)¶
Add --json to emit a single JSON object containing the answer, suggested command, danger rating, AST preflight findings, execution status, and tool call count:
See the inline reference for the exact JSON fields.
Exit codes in headless mode¶
asksh exits 1 on errors such as missing config, LLM request failures, invalid target URIs, or a refused high-danger command under -x.
Child command exit codes under -x
When -x executes a suggested command and that command exits non-zero, asksh captures the child exit code in the --json exit_code field and still exits 0. In scripts that check child success, combine -x --json and inspect .exit_code (and .executed).