Guide · Claude Code for a team
How do you run Claude Code headless for a team?
Claude Code's headless mode is claude -p: it takes one prompt, runs the agent with
no interactive screen, prints the result and exits. Anthropic now calls it non-interactive
mode. A run signed in with a Claude plan draws that person's subscription limits. A job the
team shares needs a credential of its own and a cap on what it spends.
What does claude -p do?
It runs the same agent loop, tools and context handling as an interactive session, then
exits. Add -p, or --print, to any claude command.
claude -p "Find and fix the bug in auth.py" --allowedTools "Read,Edit,Bash"
git diff main | claude -p "list every typo in this diff" > typos.txt
claude -p "Summarize this project" --output-format json | jq -r '.result'
- Exit codes: 0 on success and non-zero when the run fails, so a script can branch on it.
- Output:
textby default,jsonwith the result, session ID and metadata, orstream-json, one event per line. - A schema:
--json-schemawithjsonoutput puts the answer in astructured_outputfield. A run that ends without valid output has no such field, so check for it. - Piped input is capped at 10MB. For more, write a file and name it in the prompt.
- Follow-ups:
--continueresumes the latest conversation, and--resumetakes thesession_idfrom the JSON.
What can a headless run do without asking?
Only what needs no approval, unless you allow more. From Claude Code v2.1.302, a
claude -p run starts in Manual mode when nothing sets a permission mode, and a
call that needs approval is denied.
--allowedToolsapproves named tools, in permission rule syntax:Bash(git diff *)matchesgit diffwith or without arguments.--permission-modesets a baseline:acceptEditswrites files,dontAskdenies everything that would prompt, andautohas a classifier review most actions.--permission-prompts none(v2.1.259 and later) denies anything still waiting on an answer, so an unattended run never waits.
--bare,
it runs the hooks in the project's .claude/settings.json and connects the
servers in its .mcp.json, even in a folder you have never trusted, with no trust
dialog. In CI, that is whatever the runner checked out.
Turning every prompt off is a bigger step, and skipping permissions safely covers where it is safe to run.
What does --bare change?
It starts faster by skipping auto-discovery: hooks, skills, custom commands, subagents,
plugins, MCP servers, auto memory and CLAUDE.md. Settings files and their
permission rules are still read. You pass what the run needs with flags such as
--settings, --mcp-config and --append-system-prompt.
Bare mode never reads a subscription sign-in. It skips OAuth credentials, the keychain and
CLAUDE_CODE_OAUTH_TOKEN, so it needs ANTHROPIC_API_KEY or an
apiKeyHelper. Bedrock, Google Cloud's Agent Platform and Foundry read their own
credentials as usual.
--bare for scripted calls and
says it will become the default for -p in a future release. A script that relies
on a subscription sign-in is worth testing with --bare before that happens.
Which credential should a headless job use?
For a job the team shares, one that belongs to the job, not to a person. Claude Code picks the first credential it finds, in this order:
- A cloud provider, when
CLAUDE_CODE_USE_BEDROCK,CLAUDE_CODE_USE_VERTEXorCLAUDE_CODE_USE_FOUNDRYis set. ANTHROPIC_AUTH_TOKEN, sent as a bearer token to a gateway.ANTHROPIC_API_KEY. In a-prun, the key is always used when present.- An
apiKeyHelperscript. CLAUDE_CODE_OAUTH_TOKEN, fromclaude setup-token.- Anthropic profile and federation credentials.
- The subscription sign-in from
/login.
claude setup-token makes a one-year token on a Pro, Max, Ultra, Team or
Enterprise plan. It can only make model requests. It authenticates with the subscription of
the person who made it, and signed in with a plan, claude -p still draws from that plan's
subscription limits.
On Max, Ultra and Team plans, monthly API credits cover claude -p run with an
API key from the linked Claude Console organization.
A token from claude setup-token is one person's, and so is every limit it draws.
How do you cap what a headless run spends?
--max-turnslimits the agentic turns. There is no limit by default.--max-budget-usdstops the run once its estimated spend reaches the amount. Subagents count toward it. It checks a client-side estimate, and spend can pass the cap, so leave headroom.total_cost_usdin the JSON output is the same kind of estimate, and can differ from the bill.- Background work: a run waits for its background subagents and workflows, and stops them after 10 minutes of idle waiting by default (
CLAUDE_CODE_PRINT_BG_WAIT_CEILING_MS).
Every one of these bounds a single run. None adds up the runs, so the hundredth run of a nightly job is capped exactly as the first was, and nothing stops the hundred and first.
How does Selan run Claude Code headless?
Selan is a hosted gateway that runs Claude Code and Codex on the accounts your company
already pays for. selan claude passes every argument through, so
-p, --output-format and the permission flags work as they do on
claude. An unattended job signs in with an API token an owner mints for it:
export SELAN_TOKEN=selanct_...
selan claude -p "review this diff" --output-format json
- No sign-in and nothing on disk. With the token set there is no browser and nothing written, so a container image holds no credential.
- The job spends as itself, under an address like
ci-nightly@tokens.selan.ai, so Usage and Logs show the job, not whoever set it up. - A limit across every run. The company's per-person spend limit applies to a token as it does to a person, and a token can have a limit of its own. Spend limits covers how they bind.
- API keys only, if you want. An owner can switch a token to API only, so Selan serves it from the company's own API keys and skips every connected subscription account.
- A pinned version.
selan claudechecks for a new release once a day and installs it; setSELAN_NO_AUTO_UPDATEon a build machine to pin the version.
selan whoami names the token in use and prints only its last four characters,
so it is safe in a CI log. The setup is in running unattended, and
Agents in CI runs an agent from .claude/agents/ the
same way.
seland claude -p skips every permission prompt. Piped or in
CI it starts at once, with no confirmation. What the job can reach is the boundary; the
details are in running without prompts.
Free for up to three seats, and the Free plan needs no card. A CI token takes no seat: Free holds up to 10, and every paid plan any number.
When is plain claude -p the better answer?
For one developer scripting on their own machine and their own plan, plain
claude -p is all it takes. One job with one Console API key in one secret is
simple and enough too. To build Claude Code into your own program, the Agent SDK's Python
and TypeScript packages give you callbacks and message objects;
the Agent SDK page points them at company accounts.
A gateway earns its place once several jobs share the bill and each should show and be capped on its own. Claude Code in GitHub Actions and Claude Code on a schedule cover the two places headless runs usually live.
The short version
claude -pruns one prompt with no interactive screen, prints the result and exits with a status a script can read.- From v2.1.302 a headless run starts in Manual mode, so a call that needs approval is denied unless a flag or rule allows it.
--bareskips hooks, MCP servers andCLAUDE.md, and reads no subscription sign-in.- Signed in with a plan,
claude -pdraws that person's subscription limits. --max-turnsand--max-budget-usdcap one run; through Selan, a job's own token has a limit across all its runs.
How claude -p, its flags, bare mode and credentials work is as Anthropic's pages on
running Claude Code programmatically, the CLI reference and authentication
(code.claude.com/docs/en/headless, /cli-reference and /authentication) stated it on 25 November
2026. How a plan's limits and API credits cover claude -p is as Anthropic's help
centre article "Use the Claude Agent SDK with your Claude plan" stated it on that date. These
change: check the date before relying on them. What Selan does is as its command line, gateway
and docs stated it then.