Advanced · Optional lab · about 30 minutes · Scripter Badge
Script Claude Code with claude -p
The job
Sam wants a review of every commit before it lands, even at 2am when nobody's looking. With nobody at the keyboard, the review may only read, its answer must come back in a shape a script can check, and a review that didn't finish must stop the commit.
After this Lesson you can
- run Claude Code from a script with nobody at the keyboard
- bound what the run may do: its tools, its turns and its spend
- get Claude's answer in a shape you define, with a JSON Schema
- make a failed or stopped run fail loudly, so nothing lands unreviewed
What you practise
jq -c '.permission_denials[] | {tool_name, command: .tool_input.command}' .practice/a-4-denied.json: lists each calldontAskdeniedjq '{subtype, has_result: has("result")}' .practice/a-4-capped.json: a run stopped at its cap has noresultgit diff --cached | claude -p "<prompt>" --output-format json ...: sends the staged diff to one Claude Code run on stdinchmod +x scripts/review-staged.sh: makes the script executable before you commit itgit diff --cached: shows the whole staged change the review is given
Intermediate and Advanced open with a free Account.