/delegation:delegating-to-claude-pfrom delegation
Use when authoring a non-interactive `claude -p` invocation or designing a delegation prompt for autonomous Claude on the consumer side. Provides the empirically-validated flag set, prompt template, steers-vs-needs-naming map, failure-mode catalog, recipe templates, and cost reference distilled from 22 sub-experiments (S1 → S22) in the agentic-harness-lab v0.8.0 dogfood arc. Trigger phrases include "delegate to claude -p", "claude -p flags", "autonomous claude", "one-shot claude", "claude -p prompt", "headless claude". Do NOT use for interactive Claude Code sessions, brainstorming, or genuine multi-turn work - `claude -p` is a one-shot contract; pick interactive Claude for those.
Ships in delegation. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
claude -pInvoke this skill any time you are about to write a claude -p invocation or design a delegation prompt for autonomous Claude on the consumer side. It captures the empirically-validated flag set + prompt template from paired trials S6 → S16 of the agentic-harness-lab v0.8.0 dogfood arc, plus the failure modes that surfaced across S1 → S22. Source evidence: docs/retrospectives/023-harness-dogfood-claude-p-steering.md in agentic-harness-lab.
The single guiding finding: hard gates and explicit prompt verbs are what steer claude -p. Soft documentation (CLAUDE.md content, skill indices, advisory rules) is largely inert in non-interactive mode unless the user prompt names it explicitly.
When AGENTIC_SESSION_STORE_PROVIDER=local, use the installed structured shim:
syn-delegate claude --prompt "$TASK_PROMPT" --timeout 600
Use --model when selecting a model explicitly. Run from the intended working
directory. The shim never grants more than the caller has. The delegated Claude
inherits its parent's grant, passed explicitly as flags:
--tools, --allowedTools and --disallowedTools. A parent
started with --dangerously-skip-permissions --tools Bash,Read gets a child
with --permission-mode bypassPermissions --tools Bash,Read. Settings-file
permission rules apply to both because both read the same files. If the
parent's grant cannot be read exactly, the launch is refused (exit 70,
launch_failed / parent_permissions_unavailable). That includes a call
from a native subagent, whose own tool list the hook cannot see.--permission-mode dontAsk with Bash, Read, Edit,
Write, Glob and Grep allowed (what Codex itself can do); anything else
is denied, never prompted for. The child also runs inside the Codex
parent's own OS sandbox.Claude below Claude needs a credential Claude reads itself. Claude Code
removes CLAUDE_CODE_OAUTH_TOKEN from the environment of its Bash
subprocesses (measured at 2.1.281; ANTHROPIC_API_KEY is kept). So with OAuth
only, a Claude started from a Claude Bash call, directly or through a Codex in
between, has no credential. The shim asks claude auth status first and
refuses (exit 69, launch_failed / claude_nested_auth_unavailable) rather
than start a child that fails with "Not logged in". It never copies a token
back in. Claude -> Claude works when the workspace supplies ANTHROPIC_API_KEY
or a Claude credentials file; Codex -> Claude works with OAuth.
It records intent before launch, binds the delegate's own
native session ID, and preserves its actual exit status even when a caller uses
|| true or a pipeline. Claude's shell hook supplies exact parent context;
Codex supplies its native CODEX_THREAD_ID. Missing parent context or durable
storage denies launch. Do not fabricate these context values or fall back to a
raw CLI to bypass a capture failure.
The raw CLI examples below describe uncaptured use and underlying harness options. In captured workflows, use the shim so the run can discover this launch.
claude -p --verbose \
--permission-mode bypassPermissions \
--append-system-prompt-file ./CLAUDE.md \
--output-format stream-json --include-hook-events --include-partial-messages \
--max-budget-usd <N> \
"$TASK_PROMPT"
--verbose + --output-format stream-json - required together. Text mode hides tool calls and is unscoreable (S7 footgun: stream-json with --print errors without --verbose). If you only set one, the transcript is useless for triage.--permission-mode bypassPermissions - the realistic-autonomy mode. The default mode is read-only (S4 returned no-go because Claude could not write files). acceptEdits auto-approves Edit/Write but denies Bash (S5 no-go). Only bypassPermissions opens both, which you need for fmt/test/commit loops.--append-system-prompt-file ./CLAUDE.md - injects project context. CWD
auto-discovery also works (verified S11). Note what this does NOT do: the
path is relative, so it resolves from wherever the caller happens to be, and
Claude works relative to that directory too. It is not a way to point a run
at a project from outside it. cd into the project root first, or pass an
absolute path AND cd, if the wrapper's working directory is not guaranteed.--include-hook-events - lefthook firings become parseable events in the JSONL stream. Without this, gate-bounce-and-retry behavior (S7) is invisible.--include-partial-messages - richer tool-call detail; useful when scoring or debugging a transcript.--max-budget-usd <N> - the built-in SPEND cap, and the only bound the
CLI enforces itself. It does not bound wall-clock time: a hung local tool
burns no budget and stops nothing. macOS lacks timeout (G-19), so for an
unattended run pair this with an external bound (gtimeout, a CI step
limit). Pick the value from the cost reference below.--no-session-persistence - omitted deliberately. It suppresses the
child's on-disk session, which is what a session-store sweep collects. Use it
for throwaway trials on a laptop, where the rationale was "clean one-shot
trials do not pollute interactive history". Do NOT use it when delegating
inside a disposable container: there is no interactive history to pollute
there, and it is the difference between a delegated child that downstream
tooling can find and one it cannot. See the note below.A delegated run's transcript is the durable record that the run occurred. The parent's tool output holds a truncated preview; the child's own JSONL holds what it was asked, what it read, what it decided, and its token usage.
Be precise about what the flag does and does not destroy. It suppresses the
PERSISTED session on disk. It does not silence the stream-json on stdout, so a
caller that pipes or redirects that stream still has telemetry. What it removes
is the resumable harness session, and with it anything that finds runs by
sweeping session directories rather than by capturing stdout.
That distinction matters because of how capture usually works. WHEN THE
SESSION-STORE CAPABILITY IS ENABLED AND INITIALISED, it links the harness
session roots into an export partition, so a child that persists a session is
collected automatically with no extra wiring. A child invoked with
--no-session-persistence writes nothing there, and nothing collects it
afterwards - the stdout stream is the only remaining copy, and only if somebody
chose to keep it. This is a property of that capability, not of every
orchestrated workspace.
That asymmetry has already been measured: a codex leader delegating to Claude was priced and recorded, while its Claude child left no trace, because the canonical recipe here carried the flag and the codex-side recipe did not. The cost of the delegated leg was simply absent from the execution total.
The flag was correct for the laptop trials this skill was written from. It is wrong wherever the delegate's work needs to be attributable.
<TASK DESCRIPTION>
Before extending: WebSearch <topic> and CITE >=N sources in the commit message.
Use conventional commits. N commits total (Part 1 then Part 2 if applicable).
| Surface | Effect | Activation |
|---|---|---|
| Lefthook + cog-verify hard gates | ✅ Deterministic | Always-on; zero agent buy-in needed (S7 confirmed gate-bounce-and-retry; no --no-verify attempts) |
| Plugin skills | ✅ Task-shape dispatch | Auto-dispatches on relevant tasks (S8: superpowers:test-driven-development fired on a TDD-shaped JWT task without being named) |
Project-local .claude/skills/ | ✅ Dispatchable | Must name in prompt; bare unnamespaced names work (S9 verified) |
| CLAUDE.md rules | ⚠️ Advisory | Bind only when the user prompt uses matching action verbs (G-49: Claude silently ignored a CLAUDE.md rule mandating "verify" even when the rule was present) |
| Skills index in CLAUDE.md | ❌ Inert in -p | Useful only for human / interactive Claude Code use (S10 found zero behavioral delta from adding the index vs. S6 baseline) |
| Symptom | Cause | Fix |
|---|---|---|
| Exits without committing despite finishing work | Missing explicit commit directive in prompt | Add "Use conventional commits. N commits total." (S13 → S14) |
| Zero WebSearch despite CLAUDE.md mandating it | Soft-doc rules do not bind autonomously in -p | Use strong action verbs in the user prompt itself (G-49) |
| Reads default Anthropic system prompt only; ignores project context | CLAUDE.md not at CWD AND no --append-system-prompt-file | Either cd into project root OR pass --append-system-prompt-file ./CLAUDE.md explicitly |
| Auth / read-only / cannot-edit failures | Default permission mode is read-only | Set --permission-mode bypassPermissions explicitly |
| Unscoreable transcript (no tool calls visible) | Default --output-format text hides tool detail | Use all three together: --output-format stream-json, --verbose, --include-hook-events |
| Hung past budget | macOS lacks timeout; no time-based bound | --max-budget-usd is the only hard cap |
| Project-local skill never dispatched | .claude/skills/ is NOT auto-enumerated in -p | Name the skill explicitly in the task prompt (bare unnamespaced name dispatches local files) |
tee-style epilogue lines break JSONL parsing | `echo ... | tee -a transcript.jsonl` writes plain text into JSONL |
Five task families with complete invocations, sample prompts, and expected behavior.
claude -p --verbose \
--permission-mode bypassPermissions \
--append-system-prompt-file ./CLAUDE.md \
--output-format stream-json --include-hook-events --include-partial-messages \
--max-budget-usd 1.00 \
"Add a /version endpoint to the example-rust axum server. Return JSON {\"version\": CARGO_PKG_VERSION}. Add tests. Use conventional commits."
Expected: one commit, fmt/clippy/cog-verify all clean, <60s wall-clock. S6 reference.
claude -p ... --max-budget-usd 3.00 ... \
"Part 1: add a JWT bearer-token middleware to the axum server. Part 2: add a DELETE /todos/:id endpoint that requires the middleware.
Before extending: WebSearch axum 0.8 middleware patterns and CITE >=2 sources in the commit message.
Use conventional commits. 2 commits total (Part 1 then Part 2)."
Expected: 2 commits, ≥2 cited URLs in commit bodies. S14 reference.
claude -p ... --max-budget-usd 2.00 ... \
"Use the running-experiments skill to produce a hypothesis-first mapping probe for self-hosted Postgres alternatives to Supabase. WebSearch the current state of 4-6 candidates. Recommend one with sourced reasoning. Don't write integration code yet. Commit only the probe README under experiments/<date>--supabase-alternatives/."
Expected: 1 commit, probe README only, broad WebSearch usage. S11 reference.
claude -p ... --max-budget-usd 2.00 ... \
"Refactor the todos handler in src/handlers/todos.rs to follow the error-handling convention used in src/handlers/users.rs. Don't add unrelated cleanup. Use conventional commits."
Expected: 1 commit, no scope creep, style matches reference file.
claude -p ... --max-budget-usd 3.00 ... \
"Wire the Tasks page in the Vite frontend to call the GET /tasks endpoint on the Rust API. Use the existing /api/* Vite proxy (don't add CORS). Match conventions in existing fetcher helpers.
Before extending: WebSearch SWR vs TanStack Query for axum-backed APIs and CITE >=2 sources in the commit message.
Use conventional commits."
Expected: 1-2 commits across frontend, no CORS additions, cited library choice. S15 reference.
| Task shape | Cost | Wall-clock | Turns | Trial |
|---|---|---|---|---|
| /version endpoint (trivial) | $0.41 | 34s | 6 | S6 |
| /todos CRUD (Rust-only, ~4× S6) | $0.60 | 81s | 12 | S7 |
| sqlx + migrations + tests | $1.14 | 195s | 25 | S12 |
| JWT middleware + DELETE (2 commits) | $1.43 | 154s | 29 | S14 |
| Frontend tasks wire-up (cross-stack) | $1.63 | ~10 min | - | S15 |
| Supabase mapping probe (research) | $0.90 | 131s | 11 | S11 |
| JWT frontend auth wiring | $2.89 | 6m20s | 53 | S16 |
--max-budget-usd recommended settings1.003.002.004.00The most expensive trial in the arc (S16, JWT frontend auth wiring) ran $2.89; 4.00 covers it with margin. Below 1.00 is dangerous - even trivial tasks can spike if cog-verify rejects multiple commit messages.
claude -pclaude -p is one prompt → one output stream. If you need clarification cycles, pick interactive.claude -p output quality is uncalibrated.bypassPermissions - production credentials, shared filesystems, untrusted dependencies. Run those interactively with explicit human approval per Bash call.agentic-harness-lab/docs/retrospectives/023-harness-dogfood-claude-p-steering.md) - full S1 → S22 synthesis + addendum. Canonical evidence base for every claim in this skill.sdlc:security-hardening - the CI-side supply-chain controls that claude -p retries against (not against). The two skills are complementary: this one tells you how to dispatch; that one tells you what gates to dispatch into.experiments:running-experiments - the discipline that produced this skill's evidence. Use it when designing your own paired trial to extend or contest these findings.templates/polyglot-monorepo/files/CLAUDE.md in agentic-harness-lab ships a condensed version of this recipe in scaffolded projects (v0.8.3+, commit 006036d).What SKILL.md sets; muted values are Claude Code's defaults
3 skills in this plugin
/delegating-to-codexUse when authoring a non-interactive `codex exec` invocation or deciding whether to hand a task from Claude Code to OpenAI Codex CLI. Provides the validated autonomous invocation, the sandbox/approval ladder, the JSON event schema for triage, a when-to-delegate framework, failure modes, and one empirical trial. Trigger phrases include "delegate to codex", "codex exec", "hand this to codex", "run codex", "codex --full-auto", "ask codex", "second opinion from codex", "have codex use a skill", "run a skill in codex", "codex pr-review". Do NOT use for interactive pair-programming in the Codex TUI, or for trivial CRUD/UI/first-attempt tasks where a model handoff adds no value. For autonomous Claude (not Codex), use `delegating-to-claude-p` instead./writing-handoffsUse when you need to compact the current conversation into a handoff document so a fresh session or agent can continue a branch or task with full context. Trigger phrases include "write a handoff", "hand this off", "compact this for a fresh agent", "handoff doc", "summarize this branch's context", "I'll pick this up later", "create a handoff for the next session". Produces a structured Markdown doc (from a template) capturing purpose, current state, files affected, rationale, do's-and-don'ts learned, and suggested skills. Do NOT use to author PRDs, ADRs, plans, or specs — those are separate durable artifacts that a handoff references by path, not reproduces. Do NOT use for a routine end-of-task summary message; a handoff is a written file for a different session to load.Other plugins' skills for the same job
delegation@agentic-skills is listed by agentparadise/agentic-skills — review the source before installing
npx claudepluginhub agentparadise/agentic-skills --plugin delegation