Headless & CI
A CI job has no person at the keyboard to answer prompts. This page shows how to run Claude Code from a script with claude -p, read its answer as JSON, keep the run repeatable and locked down, cap its cost, and sign in from a pipeline, with a failing-test triage job as the running example.
9 min read9 মিনিটে পড়া যায় · 9 sections9টি সেকশন · 6 sources6টি সোর্স · updated Nov 2026আপডেট: Nov 2026
A CI run that cannot askযে CI রান জিজ্ঞেস করতে পারে না
Watch a claude -p call meet the permission gate with nobody to answer a prompt.দেখুন একটা claude -p কল পারমিশন গেটে পৌঁছায়, অথচ প্রম্পটের উত্তর দেওয়ার কেউ নেই।
You’ll learnআপনি শিখবেন
- Why a CI job cannot answer a promptCI জব কেন প্রম্পটের উত্তর দিতে পারে না
- What --bare turns off--bare কী বন্ধ করে
- How a scoped allow rule keeps a call runningস্কোপড অ্যালাও রুল কীভাবে কল চালু রাখে
- The 10 MB stdin limit and the file fix10 MB stdin সীমা আর ফাইলের সমাধান
What headless mode is
Add the -p (or --print) flag to any claude command to run it non-interactively. Source 1সোর্স 1 An example from the docs: Source 1সোর্স 1
claude -p "Find and fix the bug in auth.py" --allowedTools "Read,Edit,Bash"This example allows the bare Bash tool. In CI, prefer a scoped rule such as Bash(npm test). See Permissions in unattended runs.
claude -puses the Agent SDK through the CLI. The SDK is also available as Python and TypeScript packages for full programmatic control. Source 1সোর্স 1- Claude Code exits with code 0 on success and a non-zero code when the run fails, so a CI step can branch on the exit status. Source 1সোর্স 1
- If you pass an invalid flag, Claude Code reports the error on stderr before the run starts. A failure inside the run, such as missing authentication, is printed as the result on stdout. Source 1সোর্স 1
- Not every CLI option combines with
-p. For example, Claude Code rejects--bgwith-p. Source 1সোর্স 1
--help does not list every flag
The CLI reference says that claude --help does not list every flag, so a flag that is missing from --help can still be available. Source 2সোর্স 2 This page states each flag as the CLI reference documents it.
সহজ English
A headless run has no person to answer questions. To start one, add the -p flag (or --print) to a claude command. Source 1সোর্স 1 claude -p uses the Agent SDK through the CLI. The SDK is also available as Python and TypeScript packages. Source 1সোর্স 1
When the run is successful, Claude Code exits with code 0. When the run fails, the exit code is not 0. Thus, a CI step can make a decision from the exit code. Source 1সোর্স 1
If a flag is not valid, Claude Code shows the error on stderr before the run starts. If the run fails after it starts, for example because authentication is missing, Claude Code shows the failure as the result on stdout. Source 1সোর্স 1
Some options do not work with -p. For example, Claude Code does not accept --bg with -p. Source 1সোর্স 1 Also, claude --help does not show all flags. Source 2সোর্স 2
The example in the docs allows the full Bash tool. In CI, use a smaller rule, such as Bash(npm test).
বাংলা ব্যাখ্যা
Headless mode-এ prompt-এর উত্তর দেওয়ার জন্য কেউ থাকে না। যেকোনো claude command-এ -p (অথবা --print) flag যোগ করলে command-টি non-interactive mode-এ চলে। Source 1সোর্স 1 claude -p CLI-এর মাধ্যমে Agent SDK ব্যবহার করে। পুরো programmatic control-এর জন্য SDK-টি Python এবং TypeScript package হিসেবেও পাওয়া যায়। Source 1সোর্স 1
Run সফল হলে Claude Code exit code 0 দেয়, আর run fail করলে একটি non-zero code দেয়। তাই একটি CI step exit status দেখে সিদ্ধান্ত নিতে পারে। Source 1সোর্স 1
ভুল flag দিলে Claude Code run শুরু হওয়ার আগেই stderr-এ error দেখায়। Run-এর ভেতরের কোনো failure, যেমন authentication না থাকা, stdout-এ result হিসেবে দেখায়। Source 1সোর্স 1
সব CLI option -p-এর সাথে চলে না। যেমন, Claude Code -p-এর সাথে --bg গ্রহণ করে না। Source 1সোর্স 1 আর claude --help সব flag দেখায় না, তাই --help-এ না থাকা একটি flag-ও থাকতে পারে। Source 2সোর্স 2
Docs-এর উদাহরণে পুরো Bash tool-কে allow করা হয়েছে। CI-তে Bash(npm test)-এর মতো একটি scoped rule ব্যবহার করুন।
Pipe a test log into Claude
Print mode reads stdin, so you can pipe data in and redirect the answer out. The docs pipe a build log like this: Source 1সোর্স 1
cat build-error.txt | claude -p 'concisely explain the root cause of this build error' > output.txtPiped stdin is capped at 10MB. For a larger log, write it to a file and name the file in your prompt. Source 1সোর্স 1
Example: explain the failures of the last test run in plain text.
npm test > test-output.txt 2>&1
cat test-output.txt | claude -p 'list each failing test, the root cause, and the file to fix' > triage.txtসহজ English
In print mode, Claude Code reads stdin. Thus, you can send data into Claude with a pipe and send the answer to a file. The docs send a build log this way. Source 1সোর্স 1
The limit for piped stdin is 10MB. If your log is larger, write the log to a file. Then give the file name in your prompt. Source 1সোর্স 1
In the example, npm test writes its output to test-output.txt. Then a pipe sends that file to Claude. Claude writes each failing test, the root cause, and the file to fix into triage.txt.
বাংলা ব্যাখ্যা
Print mode stdin থেকে পড়ে। তাই আপনি pipe দিয়ে data পাঠাতে পারেন এবং উত্তর একটি file-এ redirect করতে পারেন। Docs এভাবে একটি build log pipe করে। Source 1সোর্স 1
Piped stdin-এর সীমা 10MB। এর চেয়ে বড় log হলে log-টি একটি file-এ লিখুন এবং prompt-এ সেই file-এর নাম দিন। Source 1সোর্স 1
উদাহরণে npm test তার output test-output.txt-এ লেখে। তারপর file-টি pipe করে Claude-কে দেওয়া হয়, আর Claude প্রতিটি failing test, তার root cause এবং কোন file ঠিক করতে হবে তা triage.txt-এ লেখে।
Output formats
--output-format works only in print mode. Source 2সোর্স 2 It has three values: Source 1সোর্স 1
| Value | What you get |
|---|---|
text (default) | Plain text output Source 1সোর্স 1 |
json | Structured JSON with the result, the session ID, and metadata Source 1সোর্স 1 |
stream-json | Newline-delimited JSON for real-time streaming Source 1সোর্স 1 |
- With
json, the text answer is in theresultfield.jq -r '.result'extracts it. Source 1সোর্স 1 - The
jsonpayload also includestotal_cost_usdand a per-model cost breakdown. These are client-side estimates and can differ from your bill. Source 1সোর্স 1 - The docs use
stream-jsonwith--verboseand--include-partial-messagesto receive tokens as Claude generates them. A successfulresultmessage holds the final text, the running cost total, and session metadata. Find it bytype, because a message such as a task notification can follow a result. Source 1সোর্স 1
claude -p "Summarize this project" --output-format json | jq -r '.result'Validate the answer with a JSON Schema
Use --output-format json with --json-schema to get output that matches a schema. The validated output is in the structured_output field. Source 1সোর্স 1
- If the value is not a valid JSON Schema,
claudeexits withError: --json-schema is not a valid JSON Schema. Source 1সোর্স 1 - Claude Code accepts the
formatkeyword, such as"format": "email", but treats it as an annotation and does not enforce it. Source 1সোর্স 1
QA example: triage a failing test in CI
Example
This CI step sends the test log to Claude and gets back one JSON object that later steps can read. The schema and the prompt are the tutorial's example. The flags are documented. Source 1সোর্স 1 Source 2সোর্স 2
cat test-output.txt | claude --bare -p "Classify the first failing test in this log. Do not change any files." \
--permission-mode dontAsk \
--output-format json \
--json-schema '{"type":"object","properties":{"test":{"type":"string"},"category":{"type":"string","enum":["product-bug","test-bug","flaky","environment"]},"root_cause":{"type":"string"},"suspected_file":{"type":"string"}},"required":["test","category","root_cause"]}' \
> triage.json
jq '.structured_output' triage.json
jq -r '.structured_output.category' triage.json--bareneedsANTHROPIC_API_KEYor anapiKeyHelperin the job. See Authenticate in CI. Source 6সোর্স 6- Save
triage.jsonas a CI artifact, so a reviewer sees the same answer that the pipeline used. - Use the
categoryvalue to route the failure, for example to post a comment only forproduct-bug. - Treat the classification as a first guess. A person confirms a product bug before anyone files it.
সহজ English
The --output-format flag works only in print mode. Source 2সোর্স 2 It sets how the answer looks. It has three values:
textis the default. It gives plain text. Source 1সোর্স 1jsongives the answer as structured data. The data holds the result, the session ID, and some extra details. Source 1সোর্স 1stream-jsongives one line of data at a time, so you can read it live. Source 1সোর্স 1
With json, the text answer is in the result field. Source 1সোর্স 1 The output also has total_cost_usd. This is a cost guess made on your side. It can differ from your bill. Source 1সোর্স 1
You can also make the answer follow a set shape. This shape is called a JSON Schema. Add --json-schema to --output-format json. The checked answer is in the structured_output field. Source 1সোর্স 1
- If the schema is not valid,
claudestops with an error. Source 1সোর্স 1 - Claude Code accepts the
formatkeyword, such as"format": "email". Source 1সোর্স 1 - It treats that keyword as a note only. It does not enforce it. Source 1সোর্স 1
The QA example sends a test log to Claude. Claude puts the first failing test into one group, such as product-bug or flaky. It returns one JSON object. Later CI steps can read that object. The schema and the prompt are the tutorial's own example. The flags are documented. Source 1সোর্স 1 Source 2সোর্স 2
Some notes for that example:
--bareneedsANTHROPIC_API_KEYor anapiKeyHelperin the job. Source 6সোর্স 6- Keep
triage.jsonas a CI artifact. Then a reviewer sees the same answer that the pipeline used. - You can use the
categoryvalue to route the failure. One way is to post a comment only forproduct-bug. - The group is only a first guess. A person confirms a product bug before anyone files it.
বাংলা ব্যাখ্যা
--output-format শুধু print mode-এ কাজ করে। Source 2সোর্স 2 এর তিনটি value আছে: text (default) plain text দেয়, json result, session ID এবং metadata সহ structured JSON দেয়, আর stream-json real-time streaming-এর জন্য newline-delimited JSON দেয়। Source 1সোর্স 1
json-এ উত্তরটি result field-এ থাকে, আর jq -r '.result' দিয়ে তা বের করা যায়। Payload-এ total_cost_usd-ও থাকে। এটি client-side estimate, তাই আপনার bill-এর সাথে না-ও মিলতে পারে। Source 1সোর্স 1
একটি schema মেনে output পেতে --output-format json-এর সাথে --json-schema দিন। Validated output structured_output field-এ থাকে। Schema valid না হলে claude একটি error দিয়ে exit করে। Claude Code format keyword গ্রহণ করে, কিন্তু enforce করে না। Source 1সোর্স 1
QA উদাহরণে CI step test log-টি Claude-কে পাঠায় এবং একটি JSON object ফেরত পায়, যা পরের step-গুলো পড়তে পারে। Claude প্রথম failing test-কে product-bug, test-bug, flaky অথবা environment category-তে ভাগ করে। --bare-এর জন্য job-এ ANTHROPIC_API_KEY অথবা একটি apiKeyHelper লাগবে। Source 6সোর্স 6 triage.json-কে CI artifact হিসেবে রাখুন, আর category value দিয়ে failure-টি route করুন। এই classification শুধু একটি প্রথম অনুমান। কেউ product bug file করার আগে একজন মানুষ তা নিশ্চিত করবেন।
Make CI runs repeatable with --bare
Add --bare to skip auto-discovery of hooks, skills, custom commands, subagents, installed plugins, MCP servers, auto memory, and CLAUDE.md. Source 1সোর্স 1 Without it, claude -p loads the same context as an interactive session. Source 1সোর্স 1
- Bare mode is useful for CI and scripts where you need the same result on every machine. It also starts faster. Source 1সোর্স 1
- In bare mode, Claude has the Bash, file read, and file edit tools. Source 1সোর্স 1
- Only MCP servers that you give on the command line connect, for example with
--mcp-config. Bare mode runs no background tasks. These limits hold fully from v2.1.286. Source 1সোর্স 1 - The docs call
--barethe recommended mode for scripted and SDK calls. It will become the default for-pin a future release. Source 1সোর্স 1
Pass the context that the job needs with flags: Source 1সোর্স 1
| To load | Use |
|---|---|
| System prompt additions | --append-system-prompt, --append-system-prompt-file |
| Settings | --settings <file-or-json> |
| MCP servers | --mcp-config <file-or-json> |
| Custom agents | --agents <file-or-json> |
| A plugin | --plugin-dir <path>, --plugin-url <url> |
--append-system-prompt adds instructions and keeps the default prompt. --system-prompt replaces the default prompt. Source 1সোর্স 1 Source 2সোর্স 2 Use the append form for test-review rules, so Claude keeps its default tool guidance.
A repository can decide what runs
Without --bare, a -p session runs the hooks in the project's .claude/settings.json and connects the servers in its .mcp.json. This happens even in a folder that you never trusted. A -p session shows no workspace trust dialog and no per-server approval prompt. Source 1সোর্স 1
With --bare, Claude Code reads no hooks, skills, custom commands, subagents, plugins, or .mcp.json servers from the project. The project's env block and helpers such as awsAuthRefresh in its settings files still apply. Source 3সোর্স 3 So --bare alone does not block everything from a repository that you did not write. Another control is --setting-sources user, so Claude Code reads neither the project's settings files nor its .mcp.json. Source 3সোর্স 3
Bare mode does not use your subscription login. Set ANTHROPIC_API_KEY, or give an apiKeyHelper in the --settings JSON. Source 1সোর্স 1 See Authenticate in CI.
সহজ English
Without --bare, claude -p loads the same context as an interactive session. With --bare, Claude Code does not look for hooks, skills, custom commands, subagents, plugins, MCP servers, auto memory, or CLAUDE.md. Thus, bare mode is useful when you need the same result on every machine. The run also starts faster. Source 1সোর্স 1
In bare mode, Claude has Bash and can read and edit files. From v2.1.286, only the MCP servers that you give on the command line connect. Source 1সোর্স 1 Give the job its context with flags, such as --settings or --append-system-prompt. The append flag keeps the default prompt. --system-prompt replaces it. Source 1সোর্স 1 Source 2সোর্স 2
Be careful with a repository that you did not write. Without --bare, a -p session runs the project's hooks and connects its MCP servers. It shows no trust dialog and no approval prompt. Source 1সোর্স 1 With --bare, the project's env block still applies. To stop Claude Code from reading the project's settings files and .mcp.json, use --setting-sources user. Source 3সোর্স 3
Bare mode does not use your subscription login. Set ANTHROPIC_API_KEY, or give an apiKeyHelper. Source 1সোর্স 1
বাংলা ব্যাখ্যা
--bare ছাড়া claude -p একটি interactive session-এর মতোই একই context load করে। --bare দিলে Claude Code hooks, skills, custom commands, subagents, installed plugins, MCP servers, auto memory এবং CLAUDE.md auto-discover করে না। Source 1সোর্স 1 তাই যেখানে প্রতিটি মেশিনে একই result দরকার, সেখানে bare mode কাজে লাগে। এছাড়া run দ্রুত শুরু হয়। Docs scripted এবং SDK call-এর জন্য --bare-কে recommended mode বলে, এবং ভবিষ্যতের একটি release-এ এটি -p-এর default হবে। Source 1সোর্স 1
Bare mode-এ Claude-এর কাছে Bash, file read এবং file edit tool থাকে। v2.1.286 থেকে শুধু command line-এ দেওয়া MCP server-গুলো connect হয়, যেমন --mcp-config দিয়ে। Source 1সোর্স 1 Job-এর দরকারি context flag দিয়ে দিন, যেমন --settings, --agents অথবা --append-system-prompt। Source 1সোর্স 1 --append-system-prompt default prompt রেখে নির্দেশ যোগ করে, আর --system-prompt default prompt-কে replace করে। Source 1সোর্স 1 Source 2সোর্স 2
সাবধান: --bare ছাড়া একটি -p session project-এর .claude/settings.json-এর hooks চালায় এবং .mcp.json-এর server-গুলো connect করে, এমনকি যে folder-কে আপনি কখনো trust করেননি সেখানেও। কোনো workspace trust dialog বা per-server approval prompt আসে না। Source 1সোর্স 1 --bare দিলেও project-এর env block এবং awsAuthRefresh-এর মতো helper কাজ করে। তাই --bare একাই সব কিছু block করে না। --setting-sources user দিলে Claude Code project-এর settings file বা .mcp.json কোনোটিই পড়ে না। Source 3সোর্স 3
Bare mode আপনার subscription login ব্যবহার করে না। ANTHROPIC_API_KEY set করুন, অথবা --settings JSON-এ একটি apiKeyHelper দিন। Source 1সোর্স 1
Permissions in unattended runs
Nobody answers a permission prompt in a CI job. Decide before the run what Claude may do. The Permission Modes page explains each mode.
Allow, deny, and restrict tools
| Flag | What it does |
|---|---|
--allowedTools (alias --allowed-tools) | Tools that run without a prompt. It uses permission rule syntax. Source 2সোর্স 2 |
--disallowedTools (alias --disallowed-tools) | Deny rules. A bare tool name such as "Edit" removes the tool from Claude's context. A scoped rule such as Bash(rm *) denies only the matching calls. Source 2সোর্স 2 |
--tools | Restricts the built-in tools: "" disables all, "default" gives the default set, or list names such as "Bash,Edit,Read". It does not affect MCP tools. To deny those, use --disallowedTools "mcp__*". Source 2সোর্স 2 |
In a rule, a trailing space and star is a prefix match: Bash(git diff *) allows any command that starts with git diff. Source 1সোর্স 1
Set the permission mode
--permission-mode accepts default, acceptEdits, plan, auto, dontAsk, bypassPermissions, or manual as an alias for default. Source 2সোর্স 2 For CI, the useful modes are these:
dontAsk: Claude Code denies every call that would otherwise prompt. File reads in your working directories, the read-only command set, and calls that your--allowedToolsentries orpermissions.allowrules cover still run. Source 1সোর্স 1acceptEdits: Claude writes files without a prompt. Common filesystem commands such asmkdir,touch,mv, andcpare approved. Other shell commands and network requests still need an--allowedToolsentry or apermissions.allowrule. Source 1সোর্স 1
The docs show this command to run the tests in CI with an exact allowlist: Source 4সোর্স 4
claude -p "run the test suite" --permission-mode dontAsk --allowedTools "Bash(npm test)" "Read"Always pass --permission-mode in CI
With Claude Code v2.1.302 or later, a run where nothing sets a permission mode starts in Manual mode, and calls that need approval are denied. Pass the mode you want. Source 4সোর্স 4 Source 1সোর্স 1
When nobody can answer a prompt
--permission-prompts none denies prompts without asking a permission host, and tells Claude not to retry. Source 1সোর্স 1 The choices are host (the default) and none. The flag needs Claude Code v2.1.259 or later. Source 2সোর্স 2
--dangerously-skip-permissions is the same as --permission-mode bypassPermissions. Source 2সোর্স 2 Use it only inside a container, a VM, or a sandbox runtime. On Linux and macOS, run Claude Code as a non-root user. Source 4সোর্স 4
সহজ English
In a CI job, nobody can answer a permission prompt. Thus, decide before the run what Claude can do.
--allowedTools gives the tools that run without a prompt. --disallowedTools gives the deny rules. --tools limits the built-in tools, but it does not change MCP tools. Source 2সোর্স 2 A rule such as Bash(git diff *) allows each command that starts with git diff. Source 1সোর্স 1
In dontAsk mode, Claude Code denies each call that would show a prompt. File reads in your working directories, read-only commands, and calls that your allow rules cover still run. In acceptEdits mode, Claude writes files without a prompt, but other shell commands and network requests still need an allow rule. Source 1সোর্স 1
Always give --permission-mode in CI. From Claude Code v2.1.302, if nothing sets a mode, the run starts in Manual mode and calls that need approval are denied. Source 4সোর্স 4 Source 1সোর্স 1
--permission-prompts none denies prompts and tells Claude not to try again. Source 1সোর্স 1 It needs Claude Code v2.1.259 or later. Source 2সোর্স 2 --dangerously-skip-permissions is the same as --permission-mode bypassPermissions. Source 2সোর্স 2 Use it only in a container, a VM, or a sandbox runtime. On Linux and macOS, run Claude Code as a user that is not root. Source 4সোর্স 4
বাংলা ব্যাখ্যা
CI job-এ permission prompt-এর উত্তর দেওয়ার কেউ থাকে না। তাই run-এর আগেই ঠিক করুন Claude কী কী করতে পারবে।
--allowedTools সেই tool-গুলো দেয় যেগুলো prompt ছাড়া চলে। --disallowedTools deny rule দেয়: "Edit"-এর মতো একটি bare tool name tool-টিকে Claude-এর context থেকে সরিয়ে দেয়, আর Bash(rm *)-এর মতো একটি scoped rule শুধু মিলে যাওয়া call-গুলো deny করে। --tools built-in tool-গুলো সীমিত করে, কিন্তু MCP tool-এ এর কোনো প্রভাব নেই। MCP tool deny করতে --disallowedTools "mcp__*" ব্যবহার করুন। Source 2সোর্স 2 Bash(git diff *)-এর মতো rule git diff দিয়ে শুরু হওয়া যেকোনো command allow করে। Source 1সোর্স 1
dontAsk mode-এ যে call-এ prompt আসত, Claude Code তা deny করে। তবে working directory-র file read, read-only command set এবং --allowedTools বা permissions.allow rule-এ থাকা call-গুলো চলে। acceptEdits mode-এ Claude prompt ছাড়া file লেখে, আর mkdir, touch, mv, cp-এর মতো command approved থাকে। অন্য shell command এবং network request-এর জন্য এখনও allow rule লাগে। Source 1সোর্স 1
CI-তে সবসময় --permission-mode দিন। Claude Code v2.1.302 বা তার পরের version-এ কিছুই mode set না করলে run Manual mode-এ শুরু হয়, এবং যে call-এ approval লাগে তা deny হয়। Source 4সোর্স 4 Source 1সোর্স 1
--permission-prompts none permission host-কে জিজ্ঞেস না করেই prompt deny করে এবং Claude-কে retry না করতে বলে। Source 1সোর্স 1 এর জন্য Claude Code v2.1.259 বা তার পরের version লাগে। Source 2সোর্স 2 --dangerously-skip-permissions আর --permission-mode bypassPermissions একই। Source 2সোর্স 2 এটি শুধু container, VM অথবা sandbox runtime-এর ভেতরে ব্যবহার করুন। Linux এবং macOS-এ Claude Code একটি non-root user হিসেবে চালান। Source 4সোর্স 4
Limits and budgets
| Flag | What it does |
|---|---|
--max-turns <n> | Limits the number of agentic turns, in print mode only. There is no limit by default. Source 2সোর্স 2 |
--max-budget-usd <amount> | Stops the run once the estimated spend on API calls reaches the amount, in print mode only. Source 2সোর্স 2 |
--max-budget-usduses the client-side cost estimate, which can differ from your bill. Spend from subagents counts. Spend can pass the cap, so leave headroom. Source 2সোর্স 2- Your
claude --helpoutput may not show--max-turns. The CLI reference documents it, and--helpdoes not list every flag. Source 2সোর্স 2 The CLI reference does not say what exit code Claude Code gives at the limit, so check the exit status in your own pipeline. Source 2সোর্স 2 - The GitLab CI/CD docs advise appropriate
--max-turnsand jobtimeoutvalues. Source 5সোর্স 5 - If you stop a
claude -prun with SIGTERM, Claude Code exits with code 143 and leaves the current turn unfinished. To end the turn first, send SIGINT. Source 1সোর্স 1
Example: cap one triage run.
claude --bare -p "Explain why the checkout tests failed" --permission-mode dontAsk --max-turns 5 --max-budget-usd 1.00সহজ English
--max-turns sets a limit on the number of agentic turns. By default, there is no limit. --max-budget-usd stops the run when the estimated spend on API calls gets to the amount. Both flags work only in print mode. Source 2সোর্স 2
The budget uses a cost estimate, which can be different from your bill. Spend from subagents counts. The spend can go above the limit, so leave some space. Source 2সোর্স 2
Your claude --help output may not show --max-turns, but the CLI reference documents it. The CLI reference gives no specific exit code for the turn limit. Source 2সোর্স 2 The GitLab CI/CD docs advise appropriate --max-turns and job timeout values. Source 5সোর্স 5
If you stop a run with SIGTERM, Claude Code exits with code 143, and the current turn does not finish. To end the turn first, send SIGINT. Source 1সোর্স 1
বাংলা ব্যাখ্যা
--max-turns <n> agentic turn-এর সংখ্যা সীমিত করে। Default-এ কোনো সীমা নেই। --max-budget-usd <amount> API call-এর estimated খরচ ওই amount-এ পৌঁছালে run থামিয়ে দেয়। দুটি flag-ই শুধু print mode-এ কাজ করে। Source 2সোর্স 2
--max-budget-usd client-side cost estimate ব্যবহার করে, যা আপনার bill-এর সাথে না-ও মিলতে পারে। Subagent-এর খরচও গোনা হয়। খরচ cap ছাড়িয়ে যেতে পারে, তাই কিছুটা headroom রাখুন। Source 2সোর্স 2
আপনার claude --help output-এ --max-turns না-ও থাকতে পারে, কিন্তু CLI reference এটি document করে। এই ক্ষেত্রের জন্য CLI reference কোনো নির্দিষ্ট exit code দেয় না। Source 2সোর্স 2 GitLab CI/CD docs উপযুক্ত --max-turns এবং job timeout value দেওয়ার পরামর্শ দেয়। Source 5সোর্স 5
SIGTERM দিয়ে একটি claude -p run থামালে Claude Code code 143 দিয়ে exit করে এবং চলতি turn অসম্পূর্ণ থাকে। আগে turn শেষ করতে চাইলে SIGINT পাঠান। Source 1সোর্স 1
Sessions in scripts
--continue(-c) continues the most recent conversation in the current directory. With-p, it includes-pand SDK sessions. Source 1সোর্স 1 Source 2সোর্স 2--resume(-r) resumes a session by its ID or name. Source 2সোর্স 2 Since v2.1.223, Claude Code finds a session ID in any project on the machine. Source 2সোর্স 2--fork-session, with--resumeor--continue, creates a new session ID instead of reusing the original. Source 2সোর্স 2--no-session-persistencedoes not save the session, so you cannot resume it. It works in print mode only. Source 2সোর্স 2
The docs capture the session ID from JSON output and resume it: Source 1সোর্স 1
session_id=$(claude -p "Start a review" --output-format json | jq -r '.session_id')
claude -p "Continue that review" --resume "$session_id"Example for QA: the first call triages the failures, and the second call asks for a fix plan in the same session, so Claude does not read the log again.
সহজ English
--continue (-c) continues the most recent conversation in the current directory. With -p, this includes -p and SDK sessions. Source 1সোর্স 1 Source 2সোর্স 2 --resume (-r) resumes a session from its ID or name. Source 2সোর্স 2 Since v2.1.223, Claude Code finds a session ID in any project on the machine. Source 2সোর্স 2
With --resume or --continue, --fork-session makes a new session ID. It does not use the original ID again. --no-session-persistence does not save the session, so you cannot resume it. It works only in print mode. Source 2সোর্স 2
In a script, get the session ID from the JSON output. Then give the ID to --resume. Source 1সোর্স 1 For QA, the first call triages the failures. The second call asks for a fix plan in the same session, so Claude does not read the log again.
বাংলা ব্যাখ্যা
--continue (-c) current directory-র সবচেয়ে সাম্প্রতিক conversation চালিয়ে যায়। -p-এর সাথে এতে -p এবং SDK session-ও থাকে। Source 1সোর্স 1 Source 2সোর্স 2 --resume (-r) ID অথবা নাম দিয়ে একটি session resume করে। Source 2সোর্স 2 v2.1.223 থেকে Claude Code মেশিনের যেকোনো project-এ একটি session ID খুঁজে পায়। Source 2সোর্স 2
--resume অথবা --continue-এর সাথে --fork-session দিলে আগের session ID আবার ব্যবহার না করে একটি নতুন session ID তৈরি হয়। --no-session-persistence session save করে না, তাই পরে resume করা যায় না। এটি শুধু print mode-এ কাজ করে। Source 2সোর্স 2
Script-এ JSON output থেকে session ID নিন, তারপর --resume দিয়ে সেই session resume করুন। Source 1সোর্স 1 QA-র জন্য প্রথম call failure-গুলো triage করে, আর দ্বিতীয় call একই session-এ একটি fix plan চায়। তাই Claude-কে log আবার পড়তে হয় না।
Authenticate in CI
| Method | How | Notes |
|---|---|---|
| API key | Set ANTHROPIC_API_KEY in the job environment. | In -p mode, Claude Code always uses the key when it is present. Source 6সোর্স 6 |
| Subscription token | Run claude setup-token on your machine, and store the token as the CLAUDE_CODE_OAUTH_TOKEN secret. | The token is valid for one year. The command prints it and does not save it. Source 6সোর্স 6 |
claude setup-tokenneeds a Pro, Max, Ultra, Team, or Enterprise plan. Source 6সোর্স 6- The setup-token token can only make model requests. It cannot start Remote Control sessions or fetch claude.ai connectors. MCP servers that you configure locally still work. Source 6সোর্স 6
- Bare mode does not read
CLAUDE_CODE_OAUTH_TOKEN. If your job passes--bare, useANTHROPIC_API_KEYor anapiKeyHelper. Source 6সোর্স 6 - In the credential order,
ANTHROPIC_API_KEYranks aboveCLAUDE_CODE_OAUTH_TOKEN. Source 6সোর্স 6 Set only one of them in a job.
Store the value as a CI secret, never in the repository. To check the sign-in before the real step, run claude auth status. It exits with code 0 if you are signed in and 1 if not. --text gives readable output. Source 2সোর্স 2
claude auth status --textThe Install Claude Code page covers sign-in on your own machine.
সহজ English
You can sign in from CI in two ways: Source 6সোর্স 6
- API key: set
ANTHROPIC_API_KEYin the job environment. In-pmode, Claude Code always uses this key when it is there. - Subscription token: run
claude setup-tokenon your computer. Keep the token as theCLAUDE_CODE_OAUTH_TOKENsecret. The token is valid for one year. The command shows the token, but it does not save it. You need a Pro, Max, Ultra, Team, or Enterprise plan.
The token can only make model requests. Bare mode does not read CLAUDE_CODE_OAUTH_TOKEN, so with --bare, use ANTHROPIC_API_KEY or an apiKeyHelper. ANTHROPIC_API_KEY comes before CLAUDE_CODE_OAUTH_TOKEN in the credential order. Source 6সোর্স 6 Set only one of the two in a job.
Keep the value as a CI secret. Do not put it in the repository. Before the real step, run claude auth status to check the sign-in. It exits with code 0 if you are signed in, and 1 if you are not. Source 2সোর্স 2
বাংলা ব্যাখ্যা
CI-তে sign in করার দুটি উপায় আছে: Source 6সোর্স 6
- API key: job environment-এ
ANTHROPIC_API_KEYset করুন।-pmode-এ key থাকলে Claude Code সবসময় সেটিই ব্যবহার করে। - Subscription token: নিজের মেশিনে
claude setup-tokenচালান, আর token-টিCLAUDE_CODE_OAUTH_TOKENsecret হিসেবে রাখুন। Token এক বছর valid থাকে। Command-টি token print করে, কিন্তু save করে না। এর জন্য Pro, Max, Ultra, Team অথবা Enterprise plan লাগে।
Setup-token-এর token শুধু model request করতে পারে। এটি Remote Control session শুরু করতে বা claude.ai connector আনতে পারে না, তবে locally configure করা MCP server কাজ করে। Bare mode CLAUDE_CODE_OAUTH_TOKEN পড়ে না, তাই --bare দিলে ANTHROPIC_API_KEY অথবা একটি apiKeyHelper ব্যবহার করুন। Credential order-এ ANTHROPIC_API_KEY-এর স্থান CLAUDE_CODE_OAUTH_TOKEN-এর উপরে। Source 6সোর্স 6 একটি job-এ এদের মধ্যে শুধু একটি set করুন।
Value-টি CI secret হিসেবে রাখুন, কখনো repository-তে নয়। আসল step-এর আগে sign-in check করতে claude auth status চালান। Sign in করা থাকলে এটি code 0 দিয়ে exit করে, না থাকলে 1 দিয়ে। --text পড়ার মতো output দেয়। Source 2সোর্স 2
Where to go next
- GitHub Actions: run Claude Code in a GitHub workflow with
@claudeand automated PR review. - Claude Code for GitLab CI/CD is in beta and GitLab maintains it. Source 5সোর্স 5
- For full programmatic control, the Agent SDK has Python and TypeScript packages. Source 1সোর্স 1
- Browser Testing with Playwright: generate and heal browser tests that your CI job then runs.
সহজ English
To run Claude Code in a GitHub workflow with @claude and automated PR review, read GitHub Actions. Claude Code for GitLab CI/CD is in beta, and GitLab maintains it. Source 5সোর্স 5 For full programmatic control, use the Agent SDK. It has Python and TypeScript packages. Source 1সোর্স 1 To make and repair the browser tests that your CI job runs, read Browser Testing with Playwright.
বাংলা ব্যাখ্যা
GitHub workflow-এ @claude এবং automated PR review দিয়ে Claude Code চালাতে GitHub Actions পড়ুন। GitLab CI/CD-এর জন্য Claude Code এখন beta-তে আছে, আর GitLab এটি maintain করে। Source 5সোর্স 5 পুরো programmatic control-এর জন্য Agent SDK-এর Python এবং TypeScript package আছে। Source 1সোর্স 1 আপনার CI job যে browser test চালাবে, সেগুলো generate এবং heal করতে Browser Testing with Playwright পড়ুন।