Pass Large Recipe Context and Agent Text¶
Use these patterns when a recipe value, prompt or GitHub body can grow past a
few kilobytes. Each one keeps the text out of argv, so the spawn cannot fail
with Argument list too long (os error 7).
Contents¶
- Pass one large value from a file
- Pass a whole context as JSON
- Read a context value of any size in a bash step
- Re-invoke a recipe from a bash step
- Give a nested recipe the context it needs
- Create an issue or pull request with agent text
- Commit with an agent-written message
- Pass agent text to jq
- Start auto mode from a prompt file
- Troubleshooting
Pass one large value from a file¶
Use --context-from-file KEY=PATH. The file's raw UTF-8 contents become the
value; nothing is parsed.
gh issue view 1570 --json body --jq .body > /tmp/issue-1570.md
amplihack recipe run default-workflow \
--context-from-file task_description=/tmp/issue-1570.md \
-c repo_path=.
The option can be repeated, once per key.
The value stays out of amplihack's own argv at any size. How it reaches the
recipe runner depends on the runner:
- The pinned runner reports the
context_file_v1capability and receives the whole context in a 0600 file under the run's private runtime folder; its argv holds only--context-file <path>. There is no per-value size limit beyond the 16 MiB each file source may hold. This is the path every ordinary run takes. - A runner older than v0.7.0 takes context as
--set KEY=VALUEarguments. In practice you reach one by pointingRECIPE_RUNNER_RS_PATHat it; an older installed runner can also persist if the freshness check failed or recorded a skip that is still within its cooldown. Each value must then fit in one argument (128 KiB,MAX_ARG_STRLEN); several such values may together exceed 128 KiB, up to the host'sARG_MAXless the inherited environment. See Troubleshooting.
On that older --set path, other local users can read the context through
ps or /proc/<pid>/cmdline while the run lasts. On the pinned runner they
cannot: the context file is 0600 in a 0700 folder, and the agent prompts the
runner builds from the task text go to the agent CLI by file and stdin rather
than on its argv. What remains readable by your own account is listed under
What this does and does not protect.
Do not use recipe context to carry secrets either way; let the step read them
from its own environment or a credential helper instead. See
Recipe Context Transport Reference.
Pass a whole context as JSON¶
Use --context-file PATH with a file holding one JSON object. Strings are used
as they are; other values become text, and arrays and objects become compact
JSON.
cat > /tmp/qa-context.json <<'EOF'
{
"target_path": "crates/amplihack-cli",
"min_cycles": 3,
"validation_threshold": 0.85,
"fix_all_per_cycle": true,
"categories": ["security", "reliability"]
}
EOF
amplihack recipe run quality-audit-cycle \
--context-file /tmp/qa-context.json \
-c repo_path=.
The recipe receives min_cycles=3, fix_all_per_cycle=true and
categories=["security","reliability"].
Combining sources¶
When a key is set more than once, the later source in this list wins:
--context-file--context-from-file-c
# task_description comes from the issue file; repo_path from -c overrides the JSON.
amplihack recipe run default-workflow \
--context-file /tmp/base-context.json \
--context-from-file task_description=/tmp/issue-1570.md \
-c repo_path=/home/you/src/amplihack-rs
Read a context value of any size in a bash step¶
The pinned recipe runner sets $RECIPE_VAR_<key> in every bash step at any
size. A value too large for the environment is a shell-local variable: the
step's own shell sees it, but bash other.sh, python3 tool.py and every
other child process the step starts do not. Never put the value back into
argv either; -c key="$RECIPE_VAR_key" and --arg body "$RECIPE_VAR_body"
fail with Argument list too long once the value passes 128 KiB.
Source recipe_context_value.sh and write the value to a file. The helper
reads RECIPE_VAR_<key> from the step's shell, falls back to
AMPLIHACK_CONTEXT_FILE when an older runner set that instead, and exits 3 if
neither holds the key:
set -euo pipefail
. "${AMPLIHACK_HOME:-${REPO_PATH:-$(pwd)}}/amplifier-bundle/tools/recipe_context_value.sh"
umask 077
HISTORY_FILE=$(mktemp)
trap 'rm -f -- "$HISTORY_FILE"' EXIT
write_context_value cycle_history "$HISTORY_FILE"
Nested values use a dotted key, for example
write_context_value final_requirements.summary "$REQ_FILE". The helper reads
the JSON in the base key RECIPE_VAR_final_requirements and writes its
summary field; it never reads RECIPE_VAR_final_requirements__summary. If
the base key is set but is not exactly one JSON object, or has no such field
(an empty value included), it exits 3 and writes nothing. It reads
AMPLIHACK_CONTEXT_FILE only when the base key is not set at all. See
Step outputs ignore inherited bare variables.
Source the helper with .; do not run it as bash recipe_context_value.sh.
A separate process cannot see a value the runner spilled, and the bundled
recipes are checked by a test for this.
Avoid copying a {{key}} placeholder into a quoted heredoc to get the same
effect. The runner pastes the value into the script, and a value that contains
the delimiter line ends the heredoc and runs the remainder as commands.
Re-invoke a recipe from a bash step¶
Write each large value to a private temporary file with write_context_value
and pass the path with --context-from-file:
- id: run-recursive-cycle
type: bash
command: |
set -euo pipefail
. "${AMPLIHACK_HOME:-${REPO_PATH:-$(pwd)}}/amplifier-bundle/tools/recipe_context_value.sh"
umask 077
HISTORY_FILE=$(mktemp)
TASK_FILE=$(mktemp)
trap 'rm -f -- "$HISTORY_FILE" "$TASK_FILE"' EXIT
write_context_value cycle_history "$HISTORY_FILE"
write_context_value task_description "$TASK_FILE"
timeout 900 amplihack recipe run quality-audit-cycle \
--context-from-file cycle_history="$HISTORY_FILE" \
--context-from-file task_description="$TASK_FILE" \
-c repo_path="$(write_context_value repo_path -)" \
-c cycle_number="$(write_context_value next_cycle -)"
output: final_report
An <OUT> of - writes the value to stdout, which suits short values such as
repo_path. Read short values through the helper too, so the step behaves
the same on a runner older than the pin, which moved the whole context to
AMPLIHACK_CONTEXT_FILE and unset RECIPE_VAR_next_cycle as well.
Do not write -c cycle_history="$(cat "$HISTORY_FILE")". The command
substitution puts the whole file back into one argv element.
Values too large for one environment entry reach the step intact: the runner spills them to private files and reads them back before the script runs. See Values the runner spills.
Give a nested recipe the context it needs¶
A nested amplihack recipe run does not inherit the parent's RECIPE_VAR_*
variables, their uppercase aliases or AMPLIHACK_CONTEXT_FILE. Pass every key
the nested recipe reads:
- id: run-nested-workflow
type: bash
command: |
set -euo pipefail
. "${AMPLIHACK_HOME:-${REPO_PATH:-$(pwd)}}/amplifier-bundle/tools/recipe_context_value.sh"
umask 077
TASK_FILE=$(mktemp)
trap 'rm -f -- "$TASK_FILE"' EXIT
write_context_value task_description "$TASK_FILE"
amplihack recipe run default-workflow \
--context-from-file task_description="$TASK_FILE" \
-c repo_path="$(write_context_value repo_path -)"
PATH, HOME and the other AMPLIHACK_* variables are still inherited. See
Nested recipe environment.
Pass every free-text value this way rather than with -c key="$VALUE". A
value given with -c is on the nested amplihack process's own command line,
where any account on the host can read it and a pattern kill can match it;
a path, a label or an exit code is short, is not agent text, and is fine there.
The bundled callers follow this rule, and
Bundled nested calls
lists which of their keys go by file.
Create an issue or pull request with agent text¶
Write the text with write_context_value, pass it through write_body_file
and publish with --body-file. Bodies over 60,000 bytes are truncated on a
UTF-8 boundary with a note, which keeps them under GitHub's
65,536-character limit.
set -euo pipefail
TOOLS="${AMPLIHACK_HOME:-${REPO_PATH:-$(pwd)}}/amplifier-bundle/tools"
. "$TOOLS/recipe_context_value.sh"
. "$TOOLS/workflow_body_file.sh"
umask 077
RAW_FILE=$(mktemp)
BODY_FILE=$(mktemp)
trap 'rm -f -- "$RAW_FILE" "$BODY_FILE"' EXIT
write_context_value pr_body "$RAW_FILE"
write_body_file "$BODY_FILE" "the publish step log" < "$RAW_FILE"
gh pr create --title "$PR_TITLE" --body-file "$BODY_FILE" --base main
The same pattern applies to gh issue create --body-file and
gh pr edit --body-file.
Commit with an agent-written message¶
Write the message to a temporary file and use git commit -F:
set -euo pipefail
. "${AMPLIHACK_HOME:-${REPO_PATH:-$(pwd)}}/amplifier-bundle/tools/recipe_context_value.sh"
umask 077
MSG_FILE=$(mktemp)
trap 'rm -f -- "$MSG_FILE"' EXIT
write_context_value commit_message "$MSG_FILE"
git commit -F "$MSG_FILE"
Commit messages are not truncated; git has no length limit.
Pass agent text to jq¶
jq --arg name "$VALUE" places the value in argv. For text of unknown size,
write it to a file and use --rawfile, which reads the file as one string:
set -euo pipefail
. "${AMPLIHACK_HOME:-${REPO_PATH:-$(pwd)}}/amplifier-bundle/tools/recipe_context_value.sh"
umask 077
TASK_FILE=$(mktemp)
trap 'rm -f -- "$TASK_FILE"' EXIT
write_context_value task_description "$TASK_FILE"
jq -n --rawfile task "$TASK_FILE" '{task: $task, status: "merged"}' > summary.json
jq -n '{task: $ENV.TASK_DESCRIPTION}' is not a substitute. It removes the
second copy that --arg would add to argv, but the value is still one
environment string, which has the same 131,072-byte limit, and $ENV can only
read a variable that is already set.
Start auto mode from a prompt file¶
gh issue view 1570 --json body --jq .body > /tmp/issue-1570.md
amplihack claude --auto --max-turns 20 --prompt-file /tmp/issue-1570.md
--prompt-file is a subcommand option, so it goes before any --, and it
requires --auto. Each turn's prompt is then delivered on stdin for Claude
and by file reference for Copilot and Amplifier. There is no prompt-file form
for --ultrathink, --analyze or --fix.
Troubleshooting¶
| Message or symptom | Cause | Fix |
|---|---|---|
Argument list too long (os error 7) |
A large value is still in argv or the environment | Find the -c, --body, -m, --arg or -p that carries it and use the matching pattern above |
A helper script or tool started by the step sees an empty $RECIPE_VAR_cycle_history |
The runner spilled the value, and spilled values are not exported to child processes | Source the helper instead of running it, or pass the value on stdin or in a file written with write_context_value |
A step aborts with RECIPE_VAR_cycle_history: unbound variable |
A runner older than the pin moved the context to AMPLIHACK_CONTEXT_FILE |
Read the value with write_context_value, or install the pinned runner |
Dropping env var <NAME> (<N> bytes) from bash step |
A large value's uppercase alias is a name bash treats specially, such as BASH_ENV from the key bash_env |
Read $RECIPE_VAR_<key>, which still holds the value, or rename the key. See Names the runner drops |
field 'max_env_value_bytes' is retired and ignored |
The recipe still declares the old step field | Delete the field |
write_context_value: context key 'cycle_history' is not available (...) |
The key is not in this run's context | Pass it to the run, or, in a nested run, pass it explicitly from the parent step |
--context-file /tmp/ctx.json: top-level JSON value must be an object |
The file holds an array or a scalar | Wrap the values in { ... } |
--context-from-file: key 'AMPLIHACK_HOME' is reserved |
File sources cannot set AMPLIHACK_* keys |
Use a recipe context key instead |
--context-from-file: expected KEY=PATH |
The = is missing |
Write task_description=/tmp/issue.md |
A nested recipe fails with unbound variable |
It relied on an inherited parent alias | Pass the key with -c or --context-from-file |
recipe context value for key "<KEY>" is <N> bytes; ... cannot exceed 131072 bytes |
One context value is larger than a single argument may be, and the runner does not report context_file_v1, so the whole context goes on argv as --set arguments. Only an override runner older than v0.7.0 does that |
Pass a file path in the context and read the file in the step, or produce the value inside the run, for example as a step output |
failed to write recipe context file <path>: <io error> |
The runner supports --context-file, but amplihack could not write the file in the run's runtime folder (disk full, read-only folder, or an existing context entry) |
Free space or fix the runtime folder's permissions. The run does not fall back to --set. |
error: unexpected argument '--prompt-file' found |
The amplihack release on this machine or VM predates --prompt-file |
Update amplihack there |
remote command 'ultrathink' is not supported: only 'auto' accepts --prompt-file |
Only auto mode can take a prompt file | Run the remote command as auto |
Related¶
- Large Payload Delivery Reference - Options, validation and constants
- Large Payload Delivery to Child Processes - Background and design
- Recipe Context Transport Reference -
--context-fileto the runner, the--setpath for an older runner, and cleanup - Recipe CLI Reference - All
amplihack recipe runoptions - Quality Audit Cycle Recipe - The
run-recursive-cyclestep