/cc-authoring:claude-print-subprocess-error-streamsfrom cc-authoring
Fix for opaque `RuntimeError: Claude session failed: ` (or any wrapper-error with empty content) when wrapping `claude --print --output-format json` in Python subprocess. Use when: (1) you wrap `claude --print` (or any `claude` non-interactive CLI invocation) via `subprocess.run` / `subprocess.communicate` to drive batch automation; (2) the subprocess exits with non-zero returncode but `result.stderr` is empty so your error message is empty; (3) you suspect an error happened inside the Claude session but can't see it. Root cause: `claude --print --output-format json` writes its session result — including errors as `{"is_error": true, ...}` JSON — to STDOUT, not STDERR. Wrappers that surface only `result.stderr` lose the actual error. The fix is to surface BOTH streams in the wrapper's RuntimeError, with `result.stdout` taking the larger budget since errors are JSON there.
Ships in cc-authoring. 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.
A Python subprocess wrapper invokes claude --print --output-format json
to drive batch automation. The Claude session fails internally; the
subprocess exits non-zero. Your wrapper raises:
RuntimeError: Claude session failed:
Empty error content. You don't know what happened.
Code path looks like:
result = subprocess.run(
["claude", "--print", "--output-format", "json", prompt],
capture_output=True, text=True, timeout=...,
)
if result.returncode != 0:
raise RuntimeError(f"Claude session failed: {result.stderr[:400]}")
You see the empty-tail error message above.
Direct invocation of the same command at the shell succeeds (or fails with a visible error).
The actual error is inside result.stdout, which your wrapper threw
away.
claude --print --output-format json writes its session output —
including any error envelope as {"is_error": true, "result": "..."}
JSON — to STDOUT, not stderr. Stderr is reserved for
binary-launch errors (missing executable, permission denied, etc.).
Most actual session errors land on stdout.
Always surface both streams in the wrapper's error message, with stdout getting the larger budget since the JSON envelope is verbose:
if result.returncode != 0:
raise RuntimeError(
f"Claude session failed (rc={result.returncode}). "
f"stderr={result.stderr[:300]!r} stdout={result.stdout[:600]!r}"
)
If you parse JSON, also check the is_error flag explicitly even on
returncode==0:
import json
if result.returncode != 0 or not result.stdout.strip():
raise RuntimeError(
f"Claude session failed (rc={result.returncode}). "
f"stderr={result.stderr[:300]!r} stdout={result.stdout[:600]!r}"
)
try:
payload = json.loads(result.stdout)
except json.JSONDecodeError as e:
raise RuntimeError(f"non-JSON stdout: {e}; raw={result.stdout[:600]!r}")
if payload.get("is_error"):
raise RuntimeError(f"Claude session reported error: {payload!r}")
After patching the wrapper, trigger a failure deliberately (e.g., pass a prompt that asks Claude to immediately exit with an error, or break the auth token, or use a non-existent model). The new error message should now include the JSON envelope from stdout, e.g.:
RuntimeError: Claude session failed (rc=1).
stderr=''
stdout='{"type":"result","subtype":"error_during_execution",
"is_error":true,"duration_ms":...,
"result":"<actual error description>"}'
--output-format json (and --output-format stream-json) both put
session content on stdout. Stderr remains for hard-launch errors only.--output-format text (default), the same principle holds — the
text result and any internal errors go to stdout.stderr='' stdout='' — at least you can distinguish
"Claude responded with an error" from "Claude couldn't even start".result.stdout[:600]!r (with !r) so you see the literal repr
including \n escapes — important when the JSON spans multiple lines
in the terminal.capture_output=True, text=True, you've already bought into the
stdout-capture pattern — surfacing it on error is consistent.claude (no --print) prints errors to the user-visible TUI and
doesn't have this issue.A nautilus_competition team's entry.py:train(ctx) wrapped
claude --print --output-format json via the harness's
agent_runner.run_claude helper. A transient session failure produced:
RuntimeError: Claude session failed:
Logged to runs/<id>/round_NN/eval/<team>/FAILED.json with empty
error field. Direct re-invocation of the same prompt and cwd at the
shell succeeded. The wrapper had been hiding the failure detail by
surfacing only result.stderr (empty) and ignoring result.stdout.
Fix: changed every entry.py (7 teams in that workspace) to the
two-stream pattern shown above. The next failure surfaced the actual
JSON error envelope, which made root-cause diagnosis a one-step
operation.
--print and --output-format options).subprocess.CompletedProcess (Python stdlib) — both stdout and
stderr are populated separately when capture_output=True.What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub cajias/claude-skills --plugin cc-authoring16 skills in this plugin
/apm-marketplace-authoring-gotchasEight APM-marketplace-authoring gotchas discovered during real
migrations from hand-authored .claude-plugin/marketplace.json to
APM-managed and from CC-native plugin authoring.
Use when: (1) running APM's packaging step (with or without
`--dry-run`) or its marketplace-check command in a repo with an
`apm.yml`; (2) wiring CI for an APM
marketplace; (3) the CI staleness check (repack, then `git diff
--quiet`) fails despite a clean local; (4) prettier reformats
`marketplace.json` after APM's packer writes it; (5) APM exit code 1 on
local-path-only marketplaces; (6) confused by `packages:` in apm.yml
vs `plugins:` in marketplace.json; (7) commitlint rejects a commit
with `footer-leading-blank` despite no apparent footer; (8) `apm
compile -t claude` exits 0 with zero output and no compiled plugin
appears; (9) husky+lint-staged pre-commit blocks the FIRST marketplace
commit with markdownlint `MD040/fenced-code-language` errors on a
SKILL.md file copied verbatim from `~/.claude/skills/`. The gotchas
form a chain — fixing one usually surfaces the next.
/apm-plugin-distribution-pathsCanonical authoring layout for an APM (microsoft/apm)
package, plus the decision matrix for whether you need a `marketplace:` block.
Use when: (1) you've run `apm init` and are unsure where SKILL.md / agent .md
/ command .md files belong (answer: under `.apm/`, NOT at repo root); (2)
you've authored CC-native files at `commands/agents/skills/` at repo root and
wonder if that's "right" (it works as fallback layout #3 "Claude plugin", but
it's not the canonical authoring path); (3) you're trying to choose between
the three layouts APM recognizes (one-skill repo, multi-primitive `.apm/`,
Claude plugin); (4) `apm targets` fails with "No such command" in CLI 0.12.1
(subcommand doesn't exist); (5) `apm validate` fails with "No such command"
in CLI 0.12.1 (use APM's packaging command in dry-run mode instead); (6) wondering whether
`apm compile -t claude` will generate output for a hand-authored CC-native
plugin (it won't; it's a no-op for layout #3); (7) wondering if you need a
`marketplace:` block in apm.yml (you don't, for a single-plugin repo).
Covers the canonical `.apm/` source layout, the source-to-plugin remap
table, the three-layout choice, and the four distribution paths.