amplihack-rs Parity Reference¶
This reference describes Rust subprocess prompt delivery parity for amplihack
launcher, orchestration, auto-mode, and doctor surfaces.
Subprocess prompt delivery¶
amplihack-rs routes prompt-bearing subprocess launches through
amplihack-utils::prompt_delivery. The delivery engine knows four modes; only
the last three are ever used to launch a process:
| Mode | Behavior | Primary use |
|---|---|---|
argv |
Reported by amplihack doctor as a binary's capability. |
Never used to deliver a prompt. |
tempfile |
Writes the prompt to a restricted temporary file and passes the file path using the binary's verified prompt-file contract. | Long prompts when the target binary supports prompt files. |
stdin |
Pipes the prompt to child stdin from a writer thread, then closes stdin. | Long prompts when the target binary supports prompt input from stdin. |
file-reference |
Writes the prompt to a 0600 temporary file and passes one short argument asking the agent to read that file. | Long prompts for agents that can read files but have no prompt-file or stdin contract. |
The Rust launcher, orchestration, and auto-mode paths use the same selector and
capability metadata. A prompt is not shell-escaped or interpolated into a shell
command string. No prompt is put in argv under any setting, so prompts neither exceed Linux
MAX_ARG_STRLEN nor appear in /proc/<pid>/cmdline; see
Large Payload Delivery to Child Processes
and Agent Prompt Channels Reference.
Parity status¶
| Parity area | Rust behavior |
|---|---|
| Subprocess prompt delivery | tempfile, stdin and file-reference are selected through amplihack-utils::prompt_delivery using static per-binary capabilities. argv is never used to deliver a prompt: AMPLIHACK_PROMPT_DELIVERY=argv is treated as auto with a warning. Unsupported explicit tempfile requests degrade to stdin, then file-reference. Unsupported explicit stdin requests degrade to file-reference. When nothing fits, the launch fails with NoSafeChannel. A binary-specific contract can require rejection instead. |
Configuration¶
Set AMPLIHACK_PROMPT_DELIVERY to choose the requested prompt delivery mode.
This setting applies to migrated subprocess launch paths.
# Default: choose a channel that keeps the prompt out of argv.
unset AMPLIHACK_PROMPT_DELIVERY
amplihack claude -- "Summarize this repository"
# Request prompt-file delivery when the selected binary supports it.
AMPLIHACK_PROMPT_DELIVERY=tempfile \
amplihack claude -- "Review this 64 KiB prompt without shell parsing"
# Request stdin delivery once the selected binary has a verified stdin contract.
AMPLIHACK_PROMPT_DELIVERY=stdin \
amplihack codex -- "Analyze this generated task description"
AMPLIHACK_PROMPT_DELIVERY¶
| Value | Meaning |
|---|---|
unset, empty, or auto |
Use automatic mode selection. |
tempfile |
Request temporary-file delivery. |
stdin |
Request stdin delivery. |
Values are case-insensitive. Unknown values, including argv, resolve to
auto and emit a warning that names the value. The environment variable is a request, not a capability override: a
binary only uses tempfile or stdin when the launcher has a verified contract
for that binary.
Amplifier is the explicit rejection case: AMPLIHACK_PROMPT_DELIVERY=tempfile
and AMPLIHACK_PROMPT_DELIVERY=stdin must fail before launching Amplifier
because Amplifier has no documented task-prompt file or stdin contract.
Binary capability matrix¶
Capabilities are static launcher metadata, not user-controlled configuration.
Tempfile and stdin support are only marked when the binary has a verified
task-prompt contract for that channel. File-reference support is marked for
agents that can read a file at a temporary path. The test
prompt_delivery_caps_match_verified_cli_contracts in flag_matrix.rs pins
this table.
| Binary | argv |
tempfile |
Tempfile flag | stdin |
file-reference |
Notes |
|---|---|---|---|---|---|---|
| Claude Code | Supported | Unsupported | None for task prompts | Supported | Unsupported | claude -p reads the task prompt from stdin when no prompt argument is given. The operating contract uses --append-system-prompt-file (Claude Code 2.1.319 or later) and is not a task-prompt channel. |
| GitHub Copilot CLI | Supported | Unsupported | None | Unsupported | Supported | No verified prompt-file or stdin contract. Auto mode runs Copilot with --add-dir / and --allow-all-paths, so it can read the referenced file. |
| Codex | Supported | Unsupported | None | Supported (exec) |
Supported | codex exec - receives the prompt on stdin; interactive Codex with a first prompt receives a file reference. |
| Microsoft Amplifier | Supported | Unsupported | None | Unsupported | Supported | Amplifier documents run [PROMPT] with no prompt-file or stdin contract. Every prompt uses a file reference. |
Every caller of build_tool_command_with_prompt_delivery that can route to
Claude must write DeliveredCommand::stdin_payload to the child, because the
command itself no longer carries the prompt. stdin_payload is Some if and
only if the selected mode is stdin.
When a future binary version adds a prompt-file or stdin contract, update
crates/amplihack-launcher/src/flag_matrix.rs first, then update this table.
Amplifier prompt-delivery contract¶
Amplifier has no documented long-form prompt channel. The documented upstream prompt shape is:
| Capability | Amplifier behavior |
|---|---|
| Structured argv prompt | Supported. The task prompt is one Command::arg value. |
| Temporary prompt file | Unsupported. Amplifier does not document a --prompt-file, --prompt-path, or equivalent task-prompt file option. |
| Stdin task prompt | Unsupported. Amplifier does not document stdin as a task-prompt input channel. |
| File reference | Supported. Every prompt is written to a 0600 temporary file, and the positional PROMPT is a short sentence naming that file. |
AMPLIHACK_PROMPT_DELIVERY=tempfile and
AMPLIHACK_PROMPT_DELIVERY=stdin fail before spawning Amplifier. The launcher
does not write prompt bytes to stdin, add a synthetic --prompt flag, or
interpolate prompts into shell command strings.
Evidence required to enable Amplifier long-form delivery¶
File-reference delivery does not count as such a contract. Do not enable
Amplifier tempfile or stdin support from observed behavior,
internal experiments, or generic prompt_delivery support alone. The launcher
capability matrix can mark Amplifier as supporting a long-form channel only when
upstream Amplifier exposes a documented, stable task-prompt contract such as:
- a named prompt-file option in
amplifier run --help, - documentation that stdin is read as the task prompt for a named command mode,
- or an upstream release note/API document that commits to one of those contracts.
When that evidence exists, update flag_matrix.rs, add round-trip regression
coverage for a 64 KiB prompt containing apostrophes, and update this reference.
Mode selection¶
prompt_delivery resolves a requested mode into an effective mode using the
prompt size and the selected binary's capabilities.
| Requested mode | Selection rule |
|---|---|
auto |
Prefer stdin, then file-reference, then tempfile, at every prompt size. Never argv. If none is supported, fail with NoSafeChannel before spawning. |
tempfile |
Use tempfile when supported; otherwise degrade to stdin, then file-reference, then fail. |
stdin |
Use stdin when supported; otherwise degrade to file-reference, then fail. Do not degrade an explicit stdin request to tempfile, because stdin and prompt-file delivery have different process contracts. |
file-reference is not accepted as a value of AMPLIHACK_PROMPT_DELIVERY; it
is reached only through auto or the degrade chain.
Every unsupported explicit-mode degradation emits a warning that names the requested mode and the effective mode. The warning does not include the raw prompt, temporary-file contents, or stdin payload.
Binary-specific rejection rules override the generic degradation table. For
Amplifier, explicit tempfile and stdin requests are invalid and must fail
before execution.
Usage examples¶
Send a long prompt safely through auto mode¶
Create a long prompt and let amplihack choose the safest supported delivery channel for the child binary.
python3 - <<'PY' > /tmp/amplihack-long-prompt.txt
print("Review this text safely: " + ("don't shell-expand $HOME; " * 4096))
PY
AMPLIHACK_PROMPT_DELIVERY=auto \
amplihack claude -- "$(cat /tmp/amplihack-long-prompt.txt)"
This shell form still passes the prompt to the parent amplihack process as one
argv element. The parity guarantee in this document applies to the child agent
subprocess launched by amplihack, which receives the prompt on stdin. To keep
the prompt out of the parent's argv as well, use auto mode's --prompt-file,
which goes before -- and requires --auto:
Diagnose unsupported requested modes¶
Requesting tempfile delivery for a generic binary without a verified tempfile contract degrades safely unless the binary has a stricter rejection rule.
For Amplifier, doctor reports capabilities: argv, file-reference. Runtime
Amplifier launches reject explicit tempfile and stdin requests before
launch. With the requested mode unset or auto, every prompt uses a file
reference.
Run Amplifier with the documented prompt channel¶
Amplifier's documented prompt input is the positional PROMPT argument on
amplifier run.
The prompt is written to a 0600 temporary file and the positional argument is a short sentence asking Amplifier to read it.
Use prompt delivery in auto-mode¶
Auto-mode prompt-bearing wrappers use prompt delivery. Ordinary Amplifier passthrough launch validates the same Amplifier unsupported-mode policy before spawning the child process.
AMPLIHACK_PROMPT_DELIVERY=auto \
amplihack auto --agent claude --task "$(cat /tmp/amplihack-long-prompt.txt)"
The DeliveryHandle returned by the prompt delivery engine is owned until the
subprocess exits. For tempfile and file-reference delivery, that keeps the
temporary prompt file available for the entire child lifetime. Each turn runs
through run_output_with_timeout_stdin, which writes any stdin payload from a
separate thread and sets AMPLIHACK_NONINTERACTIVE=1 on the child.
Rust API¶
The generic delivery engine lives in amplihack-utils. The low-level API exists
for delivery mutation; launcher-level command building wraps it with binary
capability metadata.
use std::process::Command;
use amplihack_utils::prompt_delivery::{
DeliveryCaps, DeliveryHandle, DeliveryMode, PromptDelivery, deliver, from_env,
};
fn build_command(prompt: &str) -> std::io::Result<(Command, DeliveryHandle)> {
let mut cmd = Command::new("claude");
let requested = from_env();
let caps = DeliveryCaps::argv_only();
let handle = deliver(&mut cmd, prompt, requested, &caps)?;
Ok((cmd, handle))
}
Public types include PromptDelivery, DeliveryMode, DeliveryCaps, and
DeliveryHandle. Public functions include from_env(),
try_select_mode(requested, caps), and
deliver(cmd, prompt, requested, caps).
Launcher API¶
Launcher command builders expose delivery-aware construction instead of pushing prompt strings directly into argv.
use amplihack_launcher::flag_matrix::AgentBinary;
use amplihack_launcher::prompt_delivery::build_tool_command_with_prompt_delivery;
use amplihack_utils::prompt_delivery::PromptDelivery;
let delivered = build_tool_command_with_prompt_delivery(
AgentBinary::Claude,
std::env::current_dir()?.as_path(),
&[],
"Summarize this repository",
PromptDelivery::Auto,
)?;
let mut child = delivered.command.spawn()?;
let status = child.wait()?;
drop(delivered.delivery_handle);
The DeliveredCommand shape is:
| Field | Meaning |
|---|---|
command |
Structured std::process::Command with prompt delivery applied. |
delivery_handle |
RAII handle that owns the temporary file for tempfile and file-reference, or marks stdin ownership. |
requested_mode |
Mode requested by configuration. |
selected_mode |
Mode actually selected for the target binary. |
warnings |
Deterministic degradation or invalid-configuration warnings safe for logs. |
stdin_payload |
Prompt bytes to write when the effective mode is stdin; absent for every other mode. |
Async orchestration contract¶
Async orchestration builds a std::process::Command, applies
prompt_delivery::deliver, then convert the command to tokio::process::Command
for spawning. It does not duplicate delivery selection logic.
When the effective mode is stdin, orchestration hands the child's stdin and
the prompt to amplihack_utils::payload_delivery::spawn_stdin_writer, which
writes the bytes on its own thread and closes the pipe, then awaits child exit.
claude_process uses stdin caps for claude delegates.
The DeliveryHandle remains owned until after wait completes.
Doctor reporting¶
amplihack doctor reports prompt delivery diagnostics without printing prompt
contents.
Example output:
Prompt delivery
requested: tempfile
claude
capabilities: argv, stdin
effective: stdin
warning: requested tempfile is unsupported; degrading to stdin
copilot
capabilities: argv, file-reference
effective: file-reference
warning: requested tempfile is unsupported; degrading to file-reference
codex
capabilities: argv, stdin, file-reference
note: codex exec reads the prompt on stdin after `-`
effective: stdin
warning: requested tempfile is unsupported; degrading to stdin
amplifier
capabilities: argv, file-reference
note: no documented prompt-file or stdin contract; long prompts use a file reference
effective: file-reference
warning: requested tempfile is unsupported; degrading to file-reference
Doctor diagnostics are deterministic:
- they list the requested mode,
- they list static capabilities per binary,
- they show the effective mode, or
unavailablewhen no channel keeps the prompt out of argv (a spawn then fails), - they show degradation warnings when a requested mode is unsupported,
- they never include raw prompt data.
Doctor is a capability report. It shows the effective delivery mode for each
binary under the requested setting, but it does not model every launch-time
policy. The Amplifier launch path is stricter than the generic doctor
degradation report: explicit tempfile and stdin launch requests fail before
spawning amplifier instead of degrading to argv.
Regression contract¶
Prompt delivery behavior is defined by these externally visible contracts:
| Contract | Required behavior |
|---|---|
| Prompt privacy | For every command builder, a prompt of any size, including a short sentinel phrase, is absent from child argv under auto, tempfile and stdin. A builder with no non-argv channel fails with NoSafeChannel. AMPLIHACK_PROMPT_DELIVERY=argv behaves as auto. |
| Kernel argument limit | A prompt over 128 KiB reaches Claude (stdin), Copilot and Amplifier (file reference) byte for byte, and no argv element exceeds 131,072 bytes. |
| File-reference argument | The argument is the fixed template with only the temporary path substituted, is under 512 bytes, and the file is mode 0600. |
| Prompt fidelity | The same 64 KiB apostrophe-containing prompt round-trips unchanged through the selected delivery channel. |
| Unsupported tempfile request | A requested tempfile mode degrades to stdin, then file-reference, and emits a warning; otherwise it fails. It never degrades to argv. |
| Unsupported stdin request | A requested stdin mode degrades to file-reference and emits a warning; otherwise it fails. It does not degrade to tempfile or argv. |
| Amplifier unsupported mode request | For Amplifier, explicit tempfile and stdin requests fail before spawning amplifier; they do not degrade to argv. |
| Tempfile lifetime | Tempfile and file-reference prompts remain readable until the child process exits and are unlinked when the DeliveryHandle is dropped. |
| Stdin lifecycle | Stdin payloads are written by a writer thread and stdin is closed afterwards. A child that exits without reading all of its input (BrokenPipe) is not an error. With no payload, stdin is Stdio::null(). |
| Diagnostics safety | Doctor output, logs, and warnings include modes, capabilities, and degradation messages, but never include raw prompt bytes. |
Security and lifecycle guarantees¶
Prompt delivery follows these guarantees:
| Guarantee | Detail |
|---|---|
| No shell command construction | Prompts are passed through Command argv, restricted tempfiles, or child stdin. |
| No prompt logging | Diagnostics and warnings describe modes and capabilities only. |
| Restricted tempfiles | Tempfile prompts are created with owner-only permissions on Unix and are unlinked by RAII drop. |
| Child-lifetime ownership | DeliveryHandle lives until the child exits, preventing premature tempfile deletion. |
| Closed stdin | Stdin payloads are written from a separate thread and then closed, so a child that fills its stdout pipe cannot deadlock the parent. |
| Static capabilities | Users cannot force an unsupported binary to claim tempfile or stdin support. |
| Deterministic handling | Unsupported modes either degrade through the documented order with warnings or fail through a documented binary-specific rejection policy. |
Troubleshooting¶
A requested mode is not used or is rejected¶
Run doctor with the same environment:
If the selected binary lists only argv, it cannot take a prompt at all: every
launch fails with NoSafeChannel, and setting AMPLIHACK_PROMPT_DELIVERY=auto
does not change that. Doctor reports capability selection only; the Amplifier
launch path separately rejects explicit tempfile and stdin requests before
launch. Use a binary with a verified tempfile, stdin or file-reference
prompt contract.
Prompt text appears in argv¶
Any prompt text in a child's argv is a bug; report it. amplihack never falls
back to argv: when the target binary supports none of tempfile, stdin and
file-reference, the launch fails with NoSafeChannel instead. Only the short
pointer sentence that names the prompt file may appear in argv. To check a
running agent, see
Check Agent Processes for Prompt Text.
A tempfile prompt disappears before the child reads it¶
Keep the returned DeliveryHandle alive until after the child process has been
waited on. Dropping the handle unlinks the tempfile.
A stdin-launched child hangs¶
Use spawn_stdin_writer (or run_output_with_timeout_stdin in
amplihack-cli) rather than writing to stdin on the thread that waits for the
child. The writer closes stdin when it finishes. Holding stdin open can make
the child wait for more input.