{
  "schemaVersion": "1",
  "revision": "22ce5d34dbcb5a78",
  "id": "codex-prompt-composition-practice",
  "slug": "prompt-composition-practice",
  "title": "Prompt Builder composition and handoff: practice drills",
  "summary": "Sixteen exercises cover Prompt Builder identity and installation, prompt/command/JSON inspection, stdin composition, named threads, argument-safe handoffs, zsh wrappers, file and skill selection, launch toggles, binary overrides, debugging,…",
  "category": "Planning",
  "tags": [
    "prompt-builder",
    "prompts",
    "preflight",
    "practice"
  ],
  "sources": [
    {
      "label": "Portable Codex workflow resources",
      "url": "https://lapis-fossil-vsbc.here.now/downloads/codex-power-user-workshop-2026-06-27.bundle"
    }
  ],
  "sourceUnits": [
    "downloads/codex-power-user-workshop-2026-06-27.bundle!/exercises/05-prompt-builder.md",
    "downloads/codex-power-user-workshop-2026-06-27.bundle!/exercises/05-prompt-builder.md#Exercises: 05. Prompt Builder",
    "downloads/codex-power-user-workshop-2026-06-27.bundle!/exercises/05-prompt-builder.md#Exercises: 05. Prompt Builder/Exercise 1: Identity Check",
    "downloads/codex-power-user-workshop-2026-06-27.bundle!/exercises/05-prompt-builder.md#Exercises: 05. Prompt Builder/Exercise 2: Print A Prompt",
    "downloads/codex-power-user-workshop-2026-06-27.bundle!/exercises/05-prompt-builder.md#Exercises: 05. Prompt Builder/Exercise 3: Compare Prompt, Command, And Launch JSON",
    "downloads/codex-power-user-workshop-2026-06-27.bundle!/exercises/05-prompt-builder.md#Exercises: 05. Prompt Builder/Exercise 4: Stdin Plus Prefill",
    "downloads/codex-power-user-workshop-2026-06-27.bundle!/exercises/05-prompt-builder.md#Exercises: 05. Prompt Builder/Exercise 5: Named Thread Manifest",
    "downloads/codex-power-user-workshop-2026-06-27.bundle!/exercises/05-prompt-builder.md#Exercises: 05. Prompt Builder/Exercise 6: Handoff Final Arg",
    "downloads/codex-power-user-workshop-2026-06-27.bundle!/exercises/05-prompt-builder.md#Exercises: 05. Prompt Builder/Exercise 7: Handoff With Newlines And Quotes",
    "downloads/codex-power-user-workshop-2026-06-27.bundle!/exercises/05-prompt-builder.md#Exercises: 05. Prompt Builder/Exercise 8: Shell Function Handoff",
    "downloads/codex-power-user-workshop-2026-06-27.bundle!/exercises/05-prompt-builder.md#Exercises: 05. Prompt Builder/Exercise 9: Map `xfl` / `xfc` To `p-f` / `p-c`",
    "downloads/codex-power-user-workshop-2026-06-27.bundle!/exercises/05-prompt-builder.md#Exercises: 05. Prompt Builder/Exercise 10: File Selector Drill",
    "downloads/codex-power-user-workshop-2026-06-27.bundle!/exercises/05-prompt-builder.md#Exercises: 05. Prompt Builder/Exercise 11: Skills And Slash Commands Drill",
    "downloads/codex-power-user-workshop-2026-06-27.bundle!/exercises/05-prompt-builder.md#Exercises: 05. Prompt Builder/Exercise 12: Preview Wrapper Toggles",
    "downloads/codex-power-user-workshop-2026-06-27.bundle!/exercises/05-prompt-builder.md#Exercises: 05. Prompt Builder/Exercise 13: Override The Codex Binary",
    "downloads/codex-power-user-workshop-2026-06-27.bundle!/exercises/05-prompt-builder.md#Exercises: 05. Prompt Builder/Exercise 14: Debug A Broken Prompt Builder Flow",
    "downloads/codex-power-user-workshop-2026-06-27.bundle!/exercises/05-prompt-builder.md#Exercises: 05. Prompt Builder/Exercise 15: Create A Section 6 Seed Prompt",
    "downloads/codex-power-user-workshop-2026-06-27.bundle!/exercises/05-prompt-builder.md#Exercises: 05. Prompt Builder/Exercise 16: Write A Better Implementation Prompt",
    "downloads/codex-power-user-workshop-2026-06-27.bundle"
  ],
  "collection": "codex",
  "categoryId": "planning",
  "wordCount": 1581,
  "url": "/topics/codex-prompt-composition-practice/",
  "markdownUrl": "/markdown/codex-prompt-composition-practice.md?raw=1&v=22ce5d34dbcb5a78",
  "jsonUrl": "/api/v1/documents/codex-prompt-composition-practice.json",
  "headings": [
    {
      "id": "exercise-1-identity-check",
      "text": "Exercise 1: Identity Check",
      "level": 2
    },
    {
      "id": "exercise-2-print-a-prompt",
      "text": "Exercise 2: Print A Prompt",
      "level": 2
    },
    {
      "id": "exercise-3-compare-prompt-command-and-launch-json",
      "text": "Exercise 3: Compare Prompt, Command, And Launch JSON",
      "level": 2
    },
    {
      "id": "exercise-4-stdin-plus-prefill",
      "text": "Exercise 4: Stdin Plus Prefill",
      "level": 2
    },
    {
      "id": "exercise-5-named-thread-manifest",
      "text": "Exercise 5: Named Thread Manifest",
      "level": 2
    },
    {
      "id": "exercise-6-handoff-final-arg",
      "text": "Exercise 6: Handoff Final Arg",
      "level": 2
    },
    {
      "id": "exercise-7-handoff-with-newlines-and-quotes",
      "text": "Exercise 7: Handoff With Newlines And Quotes",
      "level": 2
    },
    {
      "id": "exercise-8-shell-function-handoff",
      "text": "Exercise 8: Shell Function Handoff",
      "level": 2
    },
    {
      "id": "exercise-9-map-xfl-xfc-to-p-f-p-c",
      "text": "Exercise 9: Map `xfl` / `xfc` To `p-f` / `p-c`",
      "level": 2
    },
    {
      "id": "exercise-10-file-selector-drill",
      "text": "Exercise 10: File Selector Drill",
      "level": 2
    },
    {
      "id": "exercise-11-skills-and-slash-commands-drill",
      "text": "Exercise 11: Skills And Slash Commands Drill",
      "level": 2
    },
    {
      "id": "exercise-12-preview-wrapper-toggles",
      "text": "Exercise 12: Preview Wrapper Toggles",
      "level": 2
    },
    {
      "id": "exercise-13-override-the-codex-binary",
      "text": "Exercise 13: Override The Codex Binary",
      "level": 2
    },
    {
      "id": "exercise-14-debug-a-broken-prompt-builder-flow",
      "text": "Exercise 14: Debug A Broken Prompt Builder Flow",
      "level": 2
    },
    {
      "id": "exercise-15-create-a-section-6-seed-prompt",
      "text": "Exercise 15: Create A Section 6 Seed Prompt",
      "level": 2
    },
    {
      "id": "exercise-16-write-a-better-implementation-prompt",
      "text": "Exercise 16: Write A Better Implementation Prompt",
      "level": 2
    },
    {
      "id": "related-resources",
      "text": "Related resources",
      "level": 2
    }
  ],
  "markdown": "# Prompt Builder composition and handoff: practice drills\n\nThese exercises practice composing, inspecting, naming, and handing off prompts before launching agents.\n\nUse a real software project when possible. Prefer dry-runs and print modes until the prompt is specific enough to submit.\n\n## Exercise 1: Identity Check\n\nRun:\n\n```bash\nwhich -a prompt-builder p\nprompt-builder --version\np --version\n```\n\nFill out:\n\n```markdown\n# Prompt Builder Identity\n\n- `prompt-builder` path:\n- `p` path:\n- versions match? yes/no\n- expected install location:\n- action needed:\n```\n\nIf working from a local Prompt Builder checkout, run:\n\n```bash\ncargo install --path . --locked --force\nwhich -a prompt-builder p\np --version\n```\n\n## Exercise 2: Print A Prompt\n\nCreate a prompt for a real software task.\n\n```bash\nmkdir -p artifacts/prompt-builder\n\np --print-prompt \\\n  \"Review the checkout flow for saved payment method regressions. Identify the smallest safe implementation slice and the tests to run.\" \\\n  > artifacts/prompt-builder/checkout.prompt.md\n\ntest -s artifacts/prompt-builder/checkout.prompt.md && echo \"prompt:OK\"\ncat artifacts/prompt-builder/checkout.prompt.md\n```\n\nFill out:\n\n```markdown\n# Printed Prompt\n\n- command:\n- output path:\n- prompt non-empty? yes/no\n- software goal:\n- files or subsystems named:\n- verification command named:\n- one improvement before launch:\n```\n\n## Exercise 3: Compare Prompt, Command, And Launch JSON\n\nRun:\n\n```bash\nmkdir -p artifacts/prompt-builder\n\np --print-prompt \"hello checkout\" \\\n  > artifacts/prompt-builder/hello.prompt.txt\n\np --dry-run --print-command \"hello checkout\" \\\n  > artifacts/prompt-builder/hello.command.txt\n\np --print-launch-json \"hello checkout\" \\\n  > artifacts/prompt-builder/hello.launch.json\n\ncat artifacts/prompt-builder/hello.prompt.txt\ncat artifacts/prompt-builder/hello.command.txt\njq '.mode, .command, .argv, .env, .prompt' artifacts/prompt-builder/hello.launch.json\n```\n\nFill out:\n\n```markdown\n# Inspection Mode Comparison\n\n| Mode | What It Shows | When To Use |\n| --- | --- | --- |\n| `--print-prompt` | | |\n| `--print-command` | | |\n| `--print-launch-json` | | |\n| `--dry-run` | | |\n\n- direct launch mode:\n- final argv:\n- prompt value:\n```\n\n## Exercise 4: Stdin Plus Prefill\n\nRun a small stdin test:\n\n```bash\nprintf 'failing test output\\nline two\\n' \\\n  | p --stdin --print-prompt \\\n  \"Debug this checkout test failure.\" \\\n  > artifacts/prompt-builder/stdin-prefill.prompt.md\n\ncat artifacts/prompt-builder/stdin-prefill.prompt.md\n```\n\nThen try with a project command:\n\n```bash\npnpm test checkout -- --runInBand 2>&1 \\\n  | p --stdin --print-prompt \\\n  \"Debug this checkout test failure. Identify the smallest safe fix and the command to confirm it worked.\" \\\n  > artifacts/prompt-builder/checkout-test.prompt.md\n```\n\nFill out:\n\n```markdown\n# Stdin Plus Prefill\n\n- prefill instruction:\n- stdin producer:\n- separator present? yes/no\n- final prompt starts with:\n- final prompt includes command output? yes/no\n- would you submit this as-is? yes/no\n- what to trim or add:\n```\n\n## Exercise 5: Named Thread Manifest\n\nRun:\n\n```bash\np --print-launch-json \\\n  --name \"Billing webhook review\" \\\n  \"Review duplicate billing webhook processing and propose the smallest safe fix.\" \\\n  > artifacts/prompt-builder/named-thread.launch.json\n\njq '.mode, .env, .app_server' artifacts/prompt-builder/named-thread.launch.json\n```\n\nFill out:\n\n```markdown\n# Named Thread Manifest\n\n- mode:\n- `CODEX_THREAD_NAME`:\n- app-server create method:\n- app-server name method:\n- where `thread/name/set` appears:\n- why this is different from direct Codex launch:\n```\n\n## Exercise 6: Handoff Final Arg\n\nRun:\n\n```bash\np --print-launch-json \\\n  --handoff-command /bin/echo \\\n  --handoff-arg wrapper \\\n  --fork-from last \\\n  --compact \\\n  \"fix this and keep \\$HOME literal\" \\\n  > artifacts/prompt-builder/handoff.launch.json\n\njq '.mode, .handoff, .argv' artifacts/prompt-builder/handoff.launch.json\n```\n\nFill out:\n\n```markdown\n# Handoff Final Arg\n\n- mode:\n- command:\n- static handoff args:\n- toggled args:\n- final argv element:\n- does `$HOME` stay literal? yes/no\n- why `Command::arg` matters:\n- shell eval used? yes/no\n```\n\n## Exercise 7: Handoff With Newlines And Quotes\n\nRun:\n\n```bash\np --print-launch-json \\\n  --handoff-command /bin/echo \\\n  \"Fix the billing webhook.\nKeep \\\"invoice paid\\\" idempotent.\nDo not shell-eval \\$HOME or pipes | here.\" \\\n  > artifacts/prompt-builder/handoff-multiline.launch.json\n\njq '.argv' artifacts/prompt-builder/handoff-multiline.launch.json\n```\n\nFill out:\n\n```markdown\n# Multiline Handoff\n\n- number of argv elements:\n- final argv element contains newlines? yes/no\n- final argv element contains quotes? yes/no\n- final argv element contains `$HOME` literally? yes/no\n- what would break if a wrapper re-split the final argument:\n```\n\n## Exercise 8: Shell Function Handoff\n\nProve the functions exist when the zsh helper file is sourced:\n\n```zsh\nzsh -lc 'source \"$HOME/.config/zsh/conf.d/40-ai.zsh\" >/dev/null 2>&1; whence -w p-f p-c p-cm xfl xfc'\n```\n\nThen preview a handoff to `xfc`:\n\n```bash\np --submit --dry-run --print-command \\\n  --handoff-command zsh \\\n  --handoff-arg -lc \\\n  --handoff-arg 'source \"$HOME/.config/zsh/conf.d/40-ai.zsh\" >/dev/null 2>&1; xfc \"$@\"' \\\n  --handoff-arg xfc \\\n  \"Continue from this compact fork and focus only on the failing checkout test.\"\n```\n\nFill out:\n\n```markdown\n# Zsh Function Handoff\n\n- sourced file:\n- function called:\n- why `zsh -lc` is required:\n- prompt position:\n- dry-run command:\n- what would fail with `--handoff-command xfc`:\n```\n\n## Exercise 9: Map `xfl` / `xfc` To `p-f` / `p-c`\n\nInspect:\n\n```bash\nrg -n 'xfl|xfc|p-f|p-c|p-cm|_p_handoff_zsh|_codex_prompt_builder_fork' zsh/conf.d/40-ai.zsh\n```\n\nFill out:\n\n```markdown\n# Section 4 To Section 5 Bridge\n\n| Helper | Direct action or compose-first? | Fork? | Compact? | Uses Prompt Builder? |\n| --- | --- | --- | --- | --- |\n| `xfl` | | | | |\n| `xfc` | | | | |\n| `p-f` | | | | |\n| `p-c` | | | | |\n| `p-cm` | | | | |\n\n- when to use `xfl`:\n- when to use `xfc`:\n- when to use `p-f`:\n- when to use `p-c`:\n```\n\n## Exercise 10: File Selector Drill\n\nOpen:\n\n```bash\np\n```\n\nType:\n\n```text\nReview @\n```\n\nSelect a file from the popup. Use a project example such as:\n\n```text\nReview @src/checkout/CheckoutForm.tsx for saved payment method regressions.\n```\n\nFill out:\n\n```markdown\n# @ File Selector\n\n- cwd:\n- selected path:\n- why this path matters:\n- did the inserted path match the real file? yes/no\n- why selecting beats typing from memory:\n```\n\n## Exercise 11: Skills And Slash Commands Drill\n\nOpen:\n\n```bash\np\n```\n\nTry the skills popup:\n\n```text\n$\n```\n\nThen try a slash command at the prompt start:\n\n```text\n/re\n```\n\nAccept `/review`.\n\nFill out:\n\n```markdown\n# Composer Vocabulary\n\n- skill mention inserted:\n- slash command inserted:\n- what triggered skills:\n- what triggered slash commands:\n- why slash commands belong at the prompt start:\n- what `Shift+Enter` does:\n- what `Ctrl+C` does with text:\n- what `Ctrl+C` does when empty:\n```\n\n## Exercise 12: Preview Wrapper Toggles\n\nRun:\n\n```bash\np --print-launch-json \\\n  --handoff-command /bin/echo \\\n  --handoff-arg wrapper \\\n  --fork-from last \\\n  --compact \\\n  --launch-option \"trace=--trace-app-server\" \\\n  --launch-option \"debug=--debug\" \\\n  \"Continue the auth/session review.\" \\\n  > artifacts/prompt-builder/toggles.launch.json\n\njq '.handoff.enabled_launch_options, .argv' artifacts/prompt-builder/toggles.launch.json\n```\n\nFill out:\n\n```markdown\n# Wrapper Toggles\n\n- enabled launch options:\n- argv order:\n- where static handoff args appear:\n- where toggle args appear:\n- where prompt appears:\n- why options are ignored without `--handoff-command`:\n```\n\n## Exercise 13: Override The Codex Binary\n\nRun:\n\n```bash\nPROMPT_BUILDER_CODEX_BIN=/bin/echo \\\n  p --submit --dry-run --print-command \\\n  \"hello override\" \\\n  > artifacts/prompt-builder/override-command.txt\n\ncat artifacts/prompt-builder/override-command.txt\n```\n\nFill out:\n\n```markdown\n# Codex Binary Override\n\n- env var:\n- command used:\n- output:\n- why this is useful for safe demos:\n- how to remove the override:\n```\n\n## Exercise 14: Debug A Broken Prompt Builder Flow\n\nPick one failure and write the debug commands.\n\n| Failure | Useful Checks |\n| --- | --- |\n| `p: command not found` | `which -a prompt-builder p`, symlink check |\n| wrong Prompt Builder version | `--version`, `cargo install --path . --locked --force` |\n| wrong Codex binary | `PROMPT_BUILDER_CODEX_BIN`, `--codex-bin`, `--print-command` |\n| named thread missing | `--print-launch-json --name ...`, check `.mode` |\n| `xfc: command not found` | `zsh -lc 'source ...40-ai.zsh; whence -w xfc'` |\n| prompt split into args | `--print-launch-json`, inspect `.argv` |\n| fork/compact ignored | check whether `--handoff-command` is present |\n\nFill out:\n\n```markdown\n# Debug Notes\n\n- failure chosen:\n- first proof command:\n- expected output:\n- likely cause:\n- smallest fix:\n- confirmation command:\n```\n\n## Exercise 15: Create A Section 6 Seed Prompt\n\nUse Prompt Builder to save one deliberate prompt for controlled variations.\n\n```bash\nRUN_ID=\"checkout-seed\"\nROOT=\"artifacts/variations/$RUN_ID\"\nmkdir -p \"$ROOT/prompts\" \"$ROOT/launch\"\n\np --print-prompt \\\n  \"Generate three controlled implementations for saved payment methods in checkout. Keep the database contract and provider API fixed. Vary only the UI integration strategy. Each option must include files to edit, tests to run, risks, and rollback notes.\" \\\n  > \"$ROOT/prompts/base.prompt.md\"\n\np --print-launch-json \\\n  \"Generate three controlled implementations for saved payment methods in checkout. Keep the database contract and provider API fixed. Vary only the UI integration strategy. Each option must include files to edit, tests to run, risks, and rollback notes.\" \\\n  > \"$ROOT/launch/base.launch.json\"\n\ntest -s \"$ROOT/prompts/base.prompt.md\" && echo \"base-prompt:OK\"\njq '.mode, .prompt' \"$ROOT/launch/base.launch.json\"\n```\n\nFill out:\n\n```markdown\n# Section 6 Seed\n\n- prompt path:\n- launch JSON path:\n- software goal:\n- invariant 1:\n- invariant 2:\n- variable under test:\n- required verification:\n- ready for controlled variations? yes/no\n- what would make this prompt stronger:\n```\n\n## Exercise 16: Write A Better Implementation Prompt\n\nBad prompt:\n\n```text\nfix checkout\n```\n\nRewrite it for Prompt Builder:\n\n```markdown\nImplement saved payment methods in checkout.\n\nScope:\n- inspect:\n- change:\n- do not change:\n\nConstraints:\n- invariant:\n- security concern:\n- migration concern:\n\nVerification:\n- command:\n- what passing means:\n\nReturn:\n- first shippable slice:\n- files changed:\n- risks:\n```\n\nThen print it:\n\n```bash\ncat artifacts/prompt-builder/better-checkout.prompt.md \\\n  | p --stdin --print-prompt \\\n  \"Use this implementation prompt as the final composed prompt.\" \\\n  > artifacts/prompt-builder/better-checkout.final.prompt.md\n```\n\nFill out:\n\n```markdown\n# Better Prompt Review\n\n- original was weak because:\n- rewritten prompt names files/subsystems? yes/no\n- rewritten prompt names verification? yes/no\n- rewritten prompt limits scope? yes/no\n- final prompt path:\n```\n\n## Related resources\n\n- [Companion reference](https://lapis-fossil-vsbc.here.now/downloads/codex-power-user-workshop-2026-06-27.bundle)\n- [Resource directory and portable download](/topics/codex-resources/)"
}
