Claude headless p invocation
Skill bokuwalily/claude-code-skills/skills/claude-headless-p-invocation
75 battle-tested Claude Code skills from shipping 20+ apps solo — macOS, Next.js, Vercel, iOS/Expo, Cloudflare, Phaser, local AI media & more
npx -y skills add bokuwalily/claude-code-skills --skill claude-headless-p-invocationAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
What its author says it does
Copied from the file, not written here
claude -p ヘッドレス実行で system prompt 全ロード + macOS perl alarm timeout + token 制限考慮した実行パターン。発火: 非対話的に claude を呼ぶ自動化スクリプト / cron で claude を回す時 / シェルから 1-shot 実行する時
SKILL.md
1.5 KB, as published. Nobody here has run it
Procedure
- 基本形:
claude -p "<prompt>" --output-format textで stdout に結果 - timeout 付き (macOS は gtimeout 推奨, なければ perl alarm):
perl -e 'alarm shift; exec @ARGV' 300 claude -p "..." || echo "timeout"
- MAX_THINKING_TOKENS 抑制: 大型 prompt なら
MAX_THINKING_TOKENS=10000 claude -p ... - stderr 分離:
claude -p "..." 2> /tmp/claude-err.logで error trace 別保存 - stdin pipe:
cat input.md | claude -p "summarize"でファイル入力
Pitfalls
- system prompt 全ロードで cost 高 → 短プロンプトでも 5-50 cents / call
- session 切れ (8:50am reset) で中断 → claude --resume <session-id> で復旧
--output-format text指定しないと JSON 返ってきて parse 必要- macOS
timeoutコマンドは GNU coreutils 必要 →brew install coreutilsでgtimeout提供 - 並列 claude -p は token block を急速消費 → 5h 800k cap 注意
Verification
- exit 0 + stdout 非空 = 成功
- exit 124 (timeout) または非ゼロ = 失敗
ccusage blocks --active --jsonで block 残量を呼び出し後に確認