claude-headless-p-invocation
Skill0 starsChanged 5 months agoMITView on GitHub
claude -p ヘッドレス実行で system prompt 全ロード + macOS perl alarm timeout + token 制限考慮した実行パターン。発火: 非対話的に claude を呼ぶ自動化スクリプト / cron で claude を回す時 / シェルから 1-shot 実行する時
- Installs packages
In this repository99 other files it gives its agents.
- agents-tools-quoted-jsonSkill
- asc-api-app-store-submitSkill
- asd-ste100Skill
- automation-bool-selector-pitfallsSkill
- automation-stale-cooldown-flagSkill
- autonomous-build-verifySkill
- book-to-skillSkill
- ccusage-cli-cost-trackingSkill
- chrome-ext-mv3-programmatic-injectSkill
- chrome-ext-store-assetsSkill
- claude-plugin-context-auditSkill
- claude-session-log-to-kbSkill
- cloudflare-workers-do-deploySkill
- codebase-to-courseSkill
- codesign-keychain-prompt-fixSkill
- codex-cli-setupSkill
- codex-delegation-handoffSkill
- content-factory-grounding-dedupSkill
- conversation-log-append-patternSkill
- cron-to-launchd-macosSkill
- cross-automation-shared-resource-killSkill
- design-token-migration-rnSkill
- discord-bot-image-to-claudeSkill
- discord-gateway-resume-dedupSkill
- excel-filtered-url-http-auditSkill
- execution-budget-vs-capsSkill
- expo-free-local-ios-testflightSkill
- ga4-connect-projectsSkill
- gcal-oauth-desktop-setupSkill
- git-commit-helperSkill
- git-prepush-secret-remote-checkSkill
- gsc-cli-automationSkill
- hatena-blogsync-autopostSkill
- hook-latency-wrapSkill
- hook-log-append-patternSkill
- html-to-pdf-slide-deckSkill
- humanizerSkill
- human-review-gate-shellSkill
- implementation-model-routingSkill
- insights-to-claude-mdSkill
- ios-permission-key-security-matrixSkill
- ios-sim-store-screenshotsSkill
- launchd-exit78-exconfig-debugSkill
- llm-content-pipeline-quality-gateSkill
- local-ai-video-pipelineSkill
- local-flux-mflux-image-genSkill
- local-llm-slow-diagnosisSkill
- local-music-generationSkill
- lottie-skottie-authoring-pitfallsSkill
- machine-wide-api-ratelimit-latchSkill
- macos-hook-path-timeoutSkill
- md-to-docx-reportSkill
- memory-md-inject-bloat-auditSkill
- message-display-secrets-maskSkill
- metric-source-attributionSkill
- migrate-icloud-desktop-assetsSkill
- nextauth-local-e2e-sessionSkill
- nextjs-rsc-payload-slimSkill
- nothing-designSkill
- openclaw-ollama-setupSkill
- The first 60 shown.
The file
Files
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"でファイル入力 - launchd / 自動化から呼ぶなら MCP と hook を切る(必須): 文章生成・判定だけならツールは要らない。
claude -p --model haiku --strict-mcp-config --mcp-config '{"mcpServers":{}}' --allowedTools ''--mcp-config '{}' は mcpServers: Invalid input で即死する。必ず {"mcpServers":{}}。
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 注意
- launchd 下で毎回タイムアウトする(自前 timeout の SIGTERM = exit 143)のは MCP サーバ/hook の起動待ちが原因。 対話セッションでは10秒で終わる同じ生成が、細い env + 高負荷だと数分かかる。stderr は空なので原因が見えない。 上の Procedure 6 で殺す+タイムアウト自体も余裕を持たせる(90秒→180秒)。実測 6.5 秒に短縮(2026-07-25 note/social 自動返信の全滅を根治)
Verification
- exit 0 + stdout 非空 = 成功
- exit 124 (timeout) または非ゼロ = 失敗
ccusage blocks --active --jsonで block 残量を呼び出し後に確認
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

