Progress will not be saved. This browser is blocking storage (often private browsing). You can still learn, but closing the tab loses your progress.
Practice needs JavaScript. The reading works without it.Back to the reading
Add -p (or --print) to the claude command: Claude does the work, prints the result to stdout and exits.
claude -p "What does src/routes/todos.js do?"Three things make -p usable in scripts:
- Exit codes: 0 on success and non-zero on failure, so scripts can branch on it.
- Reading stdin:
cat build-error.txt | claude -p "explain the root cause". The limit is 10MB; for more, write to a file and name the file in the prompt. - Output format:
--output-format text(the default),json(with the session ID, the turn count, andtotal_cost_usd, an estimated cost), orstream-json(event by event).
You've seen -p throughout the course: every "when we tried it…" was claude -p running on a copy of todo-api.
In an interactive session, a command that needs permission asks you. With -p nobody answers, so by default (Manual mode) everything that would prompt is denied. You have to say up front what Claude may do:
--allowedTools, using the permission-rule syntax from lessons 1.3 and 5.3:"Read,Edit","Bash(npm test *)","mcp__github__list_issues". Mind the space before*:Bash(git diff *)matchesgit diff, whileBash(git diff*)also matchesgit diff-index.--permission-mode:acceptEditsallows file edits,dontAskrefuses everything that would ask (good for locked-down CI),autolets the classifier review each action.--permission-prompts none: tells Claude nobody can approve anything, so it shouldn't retry what was refused.--max-turns: caps the number of turns, so a run that goes wrong doesn't run forever.
While building this course we ran into every kind of refusal: npm test not yet allowed, compound commands needing separate approval. The fix is always to list exactly the tools needed, no more.
Without --bare, claude -p loads everything an ordinary session does: hooks, skills, subagents, plugins, MCP servers, and the CLAUDE.md of the repo and of the machine it runs on. Two problems follow:
- Not repeatable: results on your machine differ from results in CI, because the configuration differs.
- Not safe with unfamiliar repos: as lessons 5.2 and 6.1 showed,
-pruns a repo's hooks and connects its MCP servers without asking.
--bare skips all of that and loads only what you pass with flags: --append-system-prompt, --settings, --mcp-config, --agents, --plugin-dir. The docs recommend --bare for scripts and CI, and say it will become the default for -p.
One important thing we confirmed: --bare doesn't use your subscription login. On a machine signed in with a Claude account, claude --bare -p … exits at once with Not logged in · Please run /login. You need to set ANTHROPIC_API_KEY, with a key created in the Claude Console, and then you pay per API use.
A script needs data, not a paragraph. Use --output-format json with --json-schema:
claude -p "List every HTTP route in src/routes/todos.js with its status codes" \
--output-format json --allowedTools "Read" \
--json-schema '{"type":"object","properties":{"routes":{"type":"array","items":{"type":"object","properties":{"method":{"type":"string"},"path":{"type":"string"},"statuses":{"type":"array","items":{"type":"integer"}}},"required":["method","path","statuses"]}}},"required":["routes"]}' \
| jq '.structured_output.routes'In our test, structured_output returned exactly todo-api's five routes, each with its list of status codes, and the run cost about 0.21 USD according to total_cost_usd. Remember to check that structured_output exists before using it: if Claude declines the request, the field is missing.
A small but useful pattern from the docs, in package.json:
"lint:claude": "git diff main | claude -p \"you are a typo linter. for each typo in this diff, report filename:line on one line and the issue on the next. return nothing else.\""The diff arrives on stdin, so Claude needs no Bash permission. We planted the typo "requried" in an error message; npm run lint:claude returned exactly two lines: the location src/routes/todos.js:21 and the word to fix.
The official route is the anthropics/claude-code-action@v1 action. Install quickly with /install-github-app inside Claude Code (needs the GitHub CLI and admin rights on the repo), or add the workflow and secret yourself. The action has two modes:
- Interactive: no
prompt. Claude waits for someone to write@claudein an issue or PR and responds with a comment. - Automation: with a
prompt. Claude runs as soon as the event happens, for example whenever a PR opens; by default the results go to the workflow run log.
An @claude workflow for todo-api, from the docs' example, with a time limit and a turn cap added:
name: Claude Code
on:
issue_comment:
types: [created]
pull_request_review_comment:
types: [created]
jobs:
claude:
if: contains(github.event.comment.body, '@claude')
runs-on: ubuntu-latest
timeout-minutes: 20
permissions:
contents: write
pull-requests: write
issues: write
id-token: write
actions: read
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 1
- uses: anthropics/claude-code-action@v1
with:
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
claude_args: "--max-turns 10"To review every PR automatically, the docs have an example that installs the code-review plugin and runs prompt: "/code-review:code-review --comment …". A skill in the repo's .claude/skills/ works too: run actions/checkout first, then prompt: "/skill-name".
Two protections are built in: only people with write access to the repo can trigger it, and bots are refused unless you allow them, to avoid bots triggering each other in a loop. On public repos, GitHub doesn't give secrets to PRs from forks, so automatic reviews only run on PRs from branches in the repo itself.
Each run costs two things: GitHub Actions minutes and tokens. The docs suggest keeping both in check:
- Set
--max-turnsinclaude_args,timeout-minuteson the job, andconcurrencyso runs don't pile up. - Keep
CLAUDE.mdshort, since it's read on every run. - Make
@clauderequests specific so Claude needs fewer turns.
For safety, apply everything you've learned:
- Keys live only in GitHub Secrets, never in the repo.
- Minimal workflow permissions: a review-only workflow needs only
readaccess. - Review before merging: Claude opens the PR, a person approves it.
- The hooks and deny rules from levels 5 and 6 live in the repo, so a run without
--bareloads them. Check the log of the first run to be sure they actually take effect in CI.
The next lesson, 8.2, handles the last piece: how to take the whole toolkit you've built during the course (skills, subagents, hooks, MCP) to another repo, and give it to the whole team with a single install command.