Claude Code headless: claude -p, cron — हिंदीClaude Code headless: claude -p, cron
Script से एक-एक काम, JSON output, तय समय परOne job per script call, JSON output, on a schedule
क्या चाहिएWhat you needClaude Code (Claude Code शुरू करना — install, /init, CLAUDE.md, permissions, plan mode), Mac/Linux पर cron (Windows: Task Scheduler), jqClaude Code (Start with Claude Code — install, /init, CLAUDE.md, permissions, plan mode), cron on Mac/Linux (Windows: Task Scheduler), jq
7 आसान कदम7 simple steps
- claude -p "काम" = बिना chat खोले एक काम, जवाब print, फिर बंद। Pipe भी चलता है: cat error.txt | claude -p "इसकी वजह बताओ"।claude -p "task" runs one job without a chat, prints the answer and exits. Pipes work: cat error.txt | claude -p "explain the cause".
- Script के लिए --output-format json — जवाब result field में, साथ में session_id; jq -r '.result' से निकालिए।For scripts use --output-format json — the answer is in result, plus session_id; extract it with jq -r '.result'.
- -p में जिन कामों पर अनुमति चाहिए वो अपने आप मना होते हैं — ज़रूरी tools --allowedTools से दीजिए, जैसे "Read,Edit,Bash(npm test *)"। बिना निगरानी वाले काम में bypassPermissions कभी नहीं।In -p mode, anything that needs approval is denied — grant the tools you need with --allowedTools, e.g. "Read,Edit,Bash(npm test *)". Never use bypassPermissions for unattended jobs.
- पिछली बात आगे बढ़ानी हो: --continue (आख़िरी बातचीत) या --resume SESSION_ID।To continue: --continue (latest conversation) or --resume SESSION_ID.
- तय समय पर: पहले एक बार claude setup-token चलाइए और मिला token crontab में सबसे ऊपर CLAUDE_CODE_OAUTH_TOKEN=… लाइन में रखिए (cron को आपका login नहीं मिलता, और आगे के versions में -p login के बिना ही चलेगा)। फिर crontab -e में नीचे वाली cron लाइन (claude का पूरा path "which claude" से)। Log file देखते रहिए।On a schedule: first run claude setup-token once and put the token at the top of your crontab as CLAUDE_CODE_OAUTH_TOKEN=… (cron can't see your login, and future versions run -p without it). Then add the cron line below with crontab -e (full path to claude from "which claude"). Check the log file.
- GitHub पर: repo में Claude Code खोलकर /install-github-app — फिर issue/PR में @claude लिखिए। Action: anthropics/claude-code-action@v1।On GitHub: open Claude Code in the repo and run /install-github-app — then mention @claude in an issue/PR. Action: anthropics/claude-code-action@v1.
- Computer चालू रखे बिना रोज़ का काम: Claude app के Scheduled tasks (Pro और ऊपर, cloud में चलते हैं)।Daily jobs without keeping a computer on: Scheduled tasks in the Claude app (Pro and up, they run in the cloud).
Copy करने वाला promptPrompt to copy
[ ] वाली जगह अपनी बात भरिए। Claude या Gemini — दोनों में चलता है।Fill in the [ ] parts. Works in Claude or Gemini.
# एक बार का काम claude -p "इस folder की README का 5 लाइन हिंदी सार दो" # Script के लिए JSON claude -p "Summarize this project" --output-format json | jq -r '.result' # सिर्फ़ चुने हुए tools की अनुमति claude -p "Run the test suite and fix any failures" --allowedTools "Read,Edit,Bash(npm test *)" # पिछली बात आगे claude -p "अब सिर्फ़ database वाले हिस्से देखो" --continue # cron: हर सुबह 8 बजे (crontab -e में; path अपना डालें) # सबसे ऊपर एक बार: CLAUDE_CODE_OAUTH_TOKEN=<claude setup-token से मिला token> 0 8 * * * cd "$HOME/Desktop/MyShop" && "$HOME/.local/bin/claude" -p "orders.csv का आज का सार report.md में लिखो" --allowedTools "Read,Write" >> "$HOME/claude-cron.log" 2>&1
# एक बार का काम claude -p "इस folder की README का 5 लाइन हिंदी सार दो" # Script के लिए JSON claude -p "Summarize this project" --output-format json | jq -r '.result' # सिर्फ़ चुने हुए tools की अनुमति claude -p "Run the test suite and fix any failures" --allowedTools "Read,Edit,Bash(npm test *)" # पिछली बात आगे claude -p "अब सिर्फ़ database वाले हिस्से देखो" --continue # cron: हर सुबह 8 बजे (crontab -e में; path अपना डालें) # सबसे ऊपर एक बार: CLAUDE_CODE_OAUTH_TOKEN=<claude setup-token से मिला token> 0 8 * * * cd "$HOME/Desktop/MyShop" && "$HOME/.local/bin/claude" -p "orders.csv का आज का सार report.md में लिखो" --allowedTools "Read,Write" >> "$HOME/claude-cron.log" 2>&1Claude में खोलेंOpen in Claude
पाठशाला में ✓ लगाकर सीखिएLearn it in the AI School with ✓ ticks