Skip to main content
Self-hosted environments are in public beta on Team and Enterprise plans; an Owner enables them by turning on Allow self-hosted environments on the Cloud environments admin page. This page assumes a working runner; see the quickstart for setup and Deploy to production for the fleet recipes.
A self-hosted environment runs Claude Code cloud sessions on your own infrastructure, executed by a runner process you deploy. With no configuration, that runner clones the session’s repository, spawns Claude Code, and cleans up. This page is for the platform engineer operating the runners: it covers the extension points for when those defaults don’t fit, from per-session credential provisioning to replacing checkout entirely. Wrappers and hooks run as executable files on the runner host, which is Linux or macOS, and the examples on this page assume a POSIX shell. A few hook environment variables on this page still use pool, such as CLAUDE_RUNNER_POOL_ID; the CLI flag and env var names use environment, such as --environment-secret-file.

Wrapper scripts

Use a wrapper script when each session needs setup the runner can’t do on its own:
  • Provisioning short-lived credentials scoped to the session creator
  • Exporting environment-specific secrets
  • Preparing language toolchains
  • Applying resource limits around the child process
The runner starts your wrapper in place of the Claude Code binary each time it starts a session, including when a session resumes or is requeued. End the wrapper by exec-ing into $CLAUDE_RUNNER_CLAUDE_BIN, the runner’s own binary, so signals and exit codes propagate correctly. Point --exec-path, or SELF_HOSTED_RUNNER_EXEC_PATH, at the wrapper when you start the runner, replacing <writable-dir> as the quickstart describes:
The runner sets the following in the wrapper’s environment: The wrapper also inherits the rest of the child’s managed environment, including any server-provided environment variables. exec propagates all of it automatically; if your wrapper spawns the child another way, forward the full environment. You can read the CLAUDE_CODE_REMOTE_SLACK_* variables in your wrapper or command hook, and in what the session runs, such as shell commands, git hooks, and Claude Code hooks. The checkout, post-session, and spawn-runner hooks don’t receive them.

Give a default to variables that can be unset

If your script uses set -u, expand CCR_SESSION_ACCOUNT_EMAIL, CLAUDE_RUNNER_CLIENT_PLATFORM, CLAUDE_CODE_REMOTE_SLACK_THREAD_URL, CLAUDE_CODE_REMOTE_SLACK_THREAD_TS, and CLAUDE_CODE_REMOTE_SLACK_CHANNEL_ID with a default, such as "${CCR_SESSION_ACCOUNT_EMAIL:-}". Each can be unset, and under set -u Bash stops with unbound variable when it expands an unset one.

Quote the arguments and variables your script expands

Quote every argument and variable that the runner passes to your wrapper or command hook. Some values contain characters a shell acts on, because they hold JSON, whole sentences, or a permission rule such as Bash(npm run test *).
  • Arguments: pass them on as "$@"
  • Variables: quote each one, as in "${CLAUDE_CODE_REMOTE_SLACK_THREAD_URL:-}". The Slack thread link, for example, can contain ? and &.
  • eval and sh -c strings: don’t substitute a value into a string that eval or sh -c runs, even inside quotes. Have that string reference the variable instead.

Keep stdin and file descriptor 3 attached

The child’s stdin is the runner’s control channel. Token rotations and session-end signals arrive on it. The runner also opens a pipe on file descriptor 3 and reads the child’s activity signals from it to drive idle and startup timeouts. A plain exec "$CLAUDE_RUNNER_CLAUDE_BIN" "$@" preserves both automatically. If your wrapper backgrounds the child with a bare &, it severs the child’s stdin. The session looks healthy until the initial OAuth token’s roughly 30-minute lifetime expires, and then every API call that uses the token fails with 401 authentication_error. If your wrapper must background the child, for example to keep a teardown trap alive, save stdin on file descriptor 9 and re-attach it explicitly:
You can redirect the child’s stdout. Keep file descriptor 3 and stderr attached to the runner:
  • File descriptor 3: carries the child’s activity signals to the runner. Don’t close it or reuse it in the wrapper.
  • File descriptors 4 and 5: runners on Claude Code v2.1.309 or later reserve them for the child. Don’t close or reuse them in the wrapper. If your wrapper uses either, for example to save stdin, move that use to a descriptor from 6 to 9, which earlier versions leave free too.
  • stderr: when the wrapper or the child exits non-zero, the runner posts the last lines of stderr to the session and prints them in its own log. The session’s user sees those lines, so don’t print secrets to stderr, and remove set -x before you deploy the wrapper. If you redirect stderr, sessions still run, but the runner reports a failure with the exit code alone.

Pass the system prompt flags through

The system prompt and appended system prompt that Anthropic’s control plane sends for a session reach your wrapper as file paths, not as inline text. The runner writes each prompt to a file in the session’s config directory, CLAUDE_CONFIG_DIR, and passes its path in the arguments your wrapper receives, as --system-prompt-file <path> or --append-system-prompt-file <path>. Runners on Claude Code v2.1.281 or later deliver the prompts as files. Before v2.1.281, the runner passed them as --system-prompt <text> and --append-system-prompt <text>. In your wrapper script or command hook, handle these flags as follows:
  • Pass them through: end the wrapper with exec "$CLAUDE_RUNNER_CLAUDE_BIN" "$@", which forwards the file flags along with every other argument. Don’t drop or rewrite them. If a session loses a prompt file flag, it runs without the instructions the control plane sent for it.
  • On a runner at v2.1.281 or later, a file flag you append replaces the server’s, never adds to it: each prompt file flag takes a single value and Claude Code keeps the last occurrence, so if you append --append-system-prompt-file <path> after "$@", your file’s contents replace the server’s appended instructions. To add instructions on top of the server’s, put them in the runner image’s CLAUDE.md, which the runner seeds into every session’s user-level config.

Fix Argument list too long at session start

On Linux, if you join the control plane’s prompt and your own text into one --append-system-prompt argument, the runner logs a line like this once the argument reaches 128 KB:
Linux limits each single argument to 32 memory pages, or 128 KB with the usual 4 KB pages. The figure from getconf ARG_MAX, often 2 MB, is a separate limit on all arguments and the environment together. On Claude Code v2.1.283 or later, leave the file flags in "$@" and pass only your own text as --append-system-prompt. Claude Code uses both, the control plane’s prompt first and then your own text:
On Linux, if your own text reaches 128 KB, move it to the runner image’s CLAUDE.md, because it’s still one argument. On v2.1.281 or v2.1.282, that command exits with Cannot use both --append-system-prompt and --append-system-prompt-file. On earlier versions, your text replaces the control plane’s prompt with no error. On any of them, update first, or move your own text to CLAUDE.md.

Provision credentials scoped to the session creator

Use the decode-token subcommand to read claims from the session JWT. It reads the token from an argument, from CLAUDE_CODE_SESSION_ACCESS_TOKEN, or from stdin, in that order; see Verify the token inside the session for what it checks. The example below decodes the creator identity, exchanges it for short-lived AWS credentials, and execs into Claude Code:
Use jq -re rather than jq -r when the extracted claim gates an auth decision, so an absent claim exits non-zero instead of passing the literal string null downstream. Sessions created by an organization service identity, such as bot and agent sessions, carry an agent: subject rather than user:, so this example refuses them; if your environment serves those sessions, decide explicitly whether the wrapper falls back to a default credential for them instead of exiting. When your credential exchange needs the email instead, read .act.email and handle its absence: the token carries it only when the creating surface recorded it, and a CLI-dispatched session can lack it. For the full claim reference and verification from services outside the runner, see Verify session identity.

Lifecycle hooks

Lifecycle hooks replace stages of the runner’s per-session pipeline with your own scripts. Point the runner at a directory of hooks with --hooks-dir <path>, or SELF_HOSTED_RUNNER_HOOKS_DIR. The runner looks for executable files with well-known names; any hook that isn’t present falls through to the built-in behavior, so you only write the ones you need. Hooks run with the runner’s own privileges, and session children share that UID, so mount the hooks directory read-only, or bake it into the image, so session code can’t modify it; see the hardening section. These hooks are distinct from Claude Code hooks, which run inside the session; lifecycle hooks run on the runner, around the session.

checkout

Runs for each repository each time the runner starts a session, including when the session resumes or is requeued, in place of the runner’s built-in clone and fetch. Use the hook to clone from a read-through mirror that you reach over HTTPS or SSH, seed a working tree from an archive, or apply per-session git auth. The runner sets these variables, and may set other CLAUDE_RUNNER_ variables that the table doesn’t list: The script must leave a working tree at CLAUDE_RUNNER_CHECKOUT_PATH checked out at the requested revision. A detached HEAD works, because the runner creates the session’s working branch on top. After your hook returns, the runner verifies that CLAUDE_RUNNER_CHECKOUT_PATH contains a .git. If your hook materializes a non-git source such as Perforce or an unpacked tarball, set CLAUDE_RUNNER_SKIP_GIT_VERIFY=1 in the runner’s environment to skip that check. Git-based flows such as working-branch creation and pushing results require a git checkout, so export outcomes from non-git trees with a post-session hook.

Get git credentials in the hook

The runner doesn’t pass a git credential to the hook. The decode-token subcommand isn’t available here either, because CLAUDE_RUNNER_CLAUDE_BIN isn’t set in the checkout-hook environment. Mint a per-session clone credential from the session’s identity instead, or fall back to the host’s own git authentication:
  • Per-session clone credential: verify CLAUDE_CODE_SESSION_ACCESS_TOKEN with a standard JWT library against the JWKS endpoint under CLAUDE_RUNNER_API_BASE_URL, as described in Verify the token from your service. Then have your credential service issue a short-lived clone credential for the identity in the token’s act claim. Key that credential on act.sub, and don’t require act.email.
  • Host git authentication: use whatever git authentication the host already has, such as an SSH agent, credential helper, or .netrc.

When the hook fails

The hook fails when it exits non-zero, or exits 0 without leaving a usable checkout behind:
  • A repository the session pushes results to: the runner fails the session, and on a non-zero exit surfaces the tail of the script’s stderr to the user. Write the reason to stderr as one short line, write it last, and then exit non-zero. Don’t print secrets to stderr, and remove set -x before you deploy the hook. If git’s couldn't find remote ref appears in roughly the last 4 KB of the hook’s stderr, the runner reports a deleted branch instead. The session’s error message then says the branch no longer exists on the remote and asks the user to restore it. If that branch exists, see A session fails with no longer exists on the remote or couldn't find remote ref.
  • A repository the session only reads from, such as a repository added to a running session: the runner skips it and continues with the remaining repositories. The runner posts a Skipped step to the session and removes whatever the hook left at the checkout path. When the Skipped step mentions the checkout hook, find the failure detail on the [runner:warn] checkout hook failed line in the runner’s log. When the step says a source ref no longer exists on remote, see A session fails with no longer exists on the remote or couldn't find remote ref. If skipping leaves the session with no repository at all, the runner fails the session anyway.
When the hook succeeds, the runner removes the checkout path after the session ends.

post-session

Runs after the Claude Code child has exited and before the runner tears the workspace down. This hook is your only chance to save uncommitted work, because uncommitted tracked changes don’t survive on either path:
  • At --capacity above one: the runner deletes per-session worktrees right after the hook returns
  • At --capacity 1: the reused canonical clone is hard-reset when the next session starts
Typical uses are pushing a snapshot branch of uncommitted changes, archiving logs, or emitting a session-ended event to your own systems. The hook fires on every session end where a child process was spawned, whatever the cause; the CLAUDE_RUNNER_EXIT_REASON values below enumerate the cases. It can’t fire when the runner terminates abruptly, such as a VM preemption or a power loss; if you need guarantees against abrupt termination, snapshot periodically from inside the session with a Claude Code PostToolUse hook instead. The runner sets: CLAUDE_RUNNER_EXIT_REASON takes one of four values:
  • completed: the session ended cleanly. The Claude Code process exited normally, or exited by itself after the session was archived or deleted.
  • failed: the Claude Code process crashed, or setup failed after it started.
  • interrupted: the runner stopped the session, in one of these cases:
    • The runner released the session to free the slot.
    • The session timed out at startup.
    • The server moved the session off this runner.
    • The runner’s poll noticed an archive or delete before the process exited.
    • The runner was draining.
    • The session outlasted its --kill-session-after-min limit.
  • abandoned: reserved for a session another runner claimed. The hook doesn’t currently fire in that case.
If you compare hook receipts with the session lifecycle counters, expect some interrupted receipts to count as completed there. The counters count a release, a startup timeout, a server move, and an archive or delete that the runner’s poll noticed first as completed, because the runner handed the slot back cleanly. The hook’s exit status never affects the session outcome; a failure is logged and ignored. The runner waits up to --post-session-hook-timeout-sec, 60 seconds by default, on every session end including runner shutdown. This example saves uncommitted work to a rescue branch:
The GIT_ALLOW_PROTOCOL line in the script limits git to HTTPS, HTTP, and SSH remotes. If the runner’s environment already sets a non-empty GIT_ALLOW_PROTOCOL list of its own, the script keeps that list. The hook pushes with whatever git credentials are available in its own environment on the runner host. Under the no-credentials-in-the-image posture, including when the built-in clone goes through the Anthropic git proxy, there are none, so mint a short-lived push credential inside the hook before pushing: exchange the session token the hook receives in CLAUDE_CODE_SESSION_ACCESS_TOKEN with your own token service, verifying it as Verify session identity describes. Treat any credential your hook gives git as one a session can obtain, and mint it so that it can do no more than this push. Git in your hook reads configuration files that a session can write, and a credential helper or filter driver named in one of them runs with your hook’s privileges. Settings in those files can also change where a push goes, whatever remote you name. For the git settings the runner fixes in your hook and the ones it leaves to those files, see Git configuration inside lifecycle hooks.

Hook timing when the runner releases a session

A released session can resume on another runner. On a runner on v2.1.236 or later, what the session was doing at release decides whether it can resume before this hook finishes:
  • Idle after a turn, or timed out at startup: the runner stops the child and runs this hook to completion. Only then does it release the session. A user message sent while the hook runs can’t resume the session on another runner before the hook finishes.
  • Waiting for the user to answer a prompt, such as a permission prompt: the runner releases the session first, then runs this hook. A user message sent while the hook runs can resume the session on another runner before the hook finishes.
This applies whenever the runner releases a session: at the idle timeout, at the --retire-at time, and, on a runner on v2.1.260 or later, at a session’s --kill-session-after-min limit. A session whose turn has ended and that holds only background tasks counts as idle here. Before v2.1.236, the runner released the session first and then ran this hook in both cases. During a SIGTERM drain, the runner holds the session lease until the hook finishes; see Shutdown timing.

Git configuration inside lifecycle hooks

The checkout and post-session hooks run with the session’s access token in their environment, and the git they run reads configuration files that sessions can write, such as ~/.gitconfig and a checkout’s .git/config. Before either hook runs, the runner sets git settings in the hook’s environment, including the ones below, as GIT_CONFIG_COUNT/GIT_CONFIG_KEY_n/GIT_CONFIG_VALUE_n pairs and git environment variables. Git ranks those above every configuration file, and they apply only to the git your hooks run, not to the session’s own git. At startup, the runner prints a [runner:git] lifecycle hooks: line that shows the hooks path, allowed protocols, gpg programs, and signing mode in effect. Requires Claude Code v2.1.280 or later.
  • Git hooks: unless you supply a value, core.hooksPath is /dev/null, so git skips the hooks in a repository’s .git/hooks and any hooks directory that ~/.gitconfig names. To supply one, export core.hooksPath as a GIT_CONFIG_KEY_n/GIT_CONFIG_VALUE_n pair in the runner’s environment. The runner also reads core.hooksPath from the system git configuration, and uses it only when the runner’s user can’t write that file, the directory it names, or the hook files in it. When the runner ignores a value, a [runner:warn] line at startup names the value and the reason.
  • File system monitor: core.fsmonitor is empty, so git in your hook doesn’t run a monitor program that a configuration file names.
  • Remote protocols: GIT_ALLOW_PROTOCOL is https:http:ssh. A clone, fetch, or push that uses a local path, a file:// URL, or a git:// URL fails with fatal: transport 'file' not allowed or fatal: transport 'git' not allowed.
  • SSH command and credential prompt: git in your hook ignores core.sshCommand and core.askPass from configuration files. To use your own SSH command, set GIT_SSH_COMMAND in the runner’s environment. To use a credential prompt program, set GIT_ASKPASS there. Sessions inherit the runner’s environment, so both variables also reach the session’s own git. Don’t put a credential in either.
  • gpg programs: gpg.program, gpg.openpgp.program, gpg.x509.program, and gpg.ssh.program are paths the runner sets, never values from a configuration file.
  • Commit signing: with --configure-git, commits you make from a hook are signed as the session. Without the flag, commit.gpgsign and tag.gpgsign are false.
To change one of these settings, use the runner’s environment or a git -c option inside the hook:
  • Configuration pairs: a GIT_CONFIG_KEY_n/GIT_CONFIG_VALUE_n pair you export in the runner’s environment replaces the runner’s value for the same key. Number your pairs from 0 and set GIT_CONFIG_COUNT to how many there are. When the last pair the count announces is missing, the runner ignores all of your pairs and logs a [runner:warn] line at startup.
  • Git environment variables: the runner leaves GIT_ALLOW_PROTOCOL, GIT_SSH_COMMAND, and GIT_ASKPASS as you set them in its environment.
  • git -c options: a git -c option inside the hook overrides a GIT_CONFIG_KEY_n pair, the runner’s or yours. It doesn’t change GIT_ALLOW_PROTOCOL, GIT_SSH_COMMAND, or GIT_ASKPASS, which git reads ahead of any configuration.
Git in your hook still reads every setting the runner doesn’t set, such as credential helpers, url.*.insteadOf rewrites, and filter drivers, from every configuration file, including the ones sessions can write. A credential helper or filter driver named in one of those files runs as a program with your hook’s privileges, and configuration in those files can still change where a push from your hook goes, including a push to a URL you pass on the command line. Before v2.1.280, the runner set none of these settings, and under --configure-git a commit made from a hook failed unless the hook passed -c commit.gpgsign=false.

command

Runs after checkout each time a session starts or resumes, in place of the built-in child spawn. The hook receives the same environment as a wrapper script and should exec into "$CLAUDE_RUNNER_CLAUDE_BIN" the same way. Use the command hook to keep all customization in one hooks directory; use --exec-path when the wrapper lives elsewhere. If --exec-path is also set, the flag takes precedence and the command hook is ignored. Always exec the runner’s own binary rather than a PATH-resolved claude; otherwise you defeat version pinning.

On-demand runners

Instead of running a fixed fleet, you can boot one runner per session. The orchestrator is a separate, stateless subcommand that polls Anthropic for spawn requests, one per session that’s queued with no runner available, and runs your spawn-runner hook for each. Your hook submits a workload to your platform: a Kubernetes Job, an EC2 instance, a Nomad dispatch. On-demand runners improve credential hygiene. On a fixed fleet, the environment secret lives on every runner host, which is the same host that runs user sessions. With the orchestrator, the environment secret stays only on the orchestrator host, which never runs user code; each spawned runner receives a single-use work order that registers exactly one runner and then expires. To start the orchestrator, pass the environment secret and a hooks directory containing an executable spawn-runner script:
The orchestrator keeps no state between polls, so you can run two or more replicas against the same environment for availability. Each spawn request is claimed server-side by exactly one replica. All replicas must use the same --expected-spawn-seconds value; see the hook contract.

The spawn-runner hook

The orchestrator runs ${hooks-dir}/spawn-runner once per spawn request. The hook must submit work asynchronously, without waiting for the runner to boot, and return within --hook-timeout, 60 seconds by default. The hook receives: The spawned runner registers with the work order in place of the environment secret:
  • Start it with the work order: point --environment-secret-file at a file containing the work-order JWT, or set SELF_HOSTED_RUNNER_ENVIRONMENT_SECRET to the JWT value.
  • Copy the JWT before the hook exits: the orchestrator deletes the work-order file after the hook exits, so copy the JWT into the workload you submit, such as a Kubernetes Secret on the spawned Job, rather than passing the file path through.
  • Use --capacity 1 on spawned runners: a session-bound work order registers exactly one runner bound to that session, so a higher capacity adds slots that never receive work, and the runner logs a warning at startup.
  • Pre-warming work orders register unbound: the standby runner isn’t bound to a session and claims queued work like a fixed-fleet runner.
The contract has four rules, whichever platform your hook provisions on:
  1. Be idempotent on CLAUDE_RUNNER_ORDER_ID. Redelivery of the same request must spawn at most one runner. Derive a deterministic resource name from the order ID and let your platform reject the duplicate. Don’t key on CLAUDE_RUNNER_SESSION_ID instead. Every re-request for a session carries the same session ID with a new order ID. A workload named or deduplicated by the session ID isn’t created again while the first one exists.
  2. Don’t retry the workload. One order ID means at most one created workload. If the runner never registers, Anthropic re-requests with a fresh order ID after --expected-spawn-seconds.
  3. Use the exit-code contract. Exit with the status that matches the outcome:
    • Exit 0: submitted.
    • Exit 1, or still running when --hook-timeout ends: retryable failure. The session backs off and is re-offered. After 10 failed requests in a row, it’s blocked as it is after exit 2 or higher.
    • Exit 2 or higher: non-retryable failure. The session is blocked from spawning again until a user sends it a new message or an Owner selects Retry on it in the environment’s Activity tab.
    While a session backs off, it shows Queued in the Activity tab with no spawn error, so read the hook’s output in the orchestrator’s log. Once blocked, the session shows Failed. Expand it to read the spawn error, taken from the last 512 characters of the hook’s stderr. Write an actionable error to stderr, and no secrets. In a shell hook, keep transient failures retryable. A pre-warming request has no session to fail: the orchestrator logs a non-zero exit locally only, and the server re-requests the spawn after the --expected-spawn-seconds lease expires.
  4. Set --expected-spawn-seconds to at least your p99 time from spawn request to runner registration. Measure from when the orchestrator receives the spawn request, and include any wait for capacity on your platform as well as boot time. This value is the server-side lease, and the work order expires with it, so a runner whose workload takes longer can’t register. All orchestrator replicas must use the same value.
Everything the hook writes to stdout or stderr appears in the orchestrator’s log with credentials automatically redacted. If sessions stay queued, check the orchestrator’s /healthz body for queue counts, then open your environment’s Activity tab on the Cloud environments admin page: expand a failed session there for its spawn error, and select Retry to re-request it.

Fix re-opened sessions that stay Queued or show Failed

If re-opened sessions stay Queued or show Failed, or your hook times out on them, one cause is a hook that names or deduplicates workloads by the session ID. A session is re-opened when its user sends it a message after its runner has exited. For example, take a hook that builds each workload’s name like this:
  1. At the session’s first spawn request, the hook creates a workload with that name, and a runner starts
  2. The runner exits, for example after --release-idle-session-min, and the user later re-opens the session
  3. The session’s next spawn request carries the same session ID and a new order ID, so the hook builds the same name
  4. If your platform still has the workload from the first request, because nothing removed it when its runner exited, the hook creates no new workload and no runner starts
  5. Each later spawn request for the session ends the same way
Open your own hook and read what it does when the workload already exists, for example when your platform rejects the duplicate name. Find that behavior in the first column to see what the re-opened session shows in the Activity tab: In the last row’s spawn error, 60000 is your --hook-timeout in milliseconds. When a hook waits until --hook-timeout ends, the orchestrator’s log also gets a timed out after line. To fix the hook, build each name or key from CLAUDE_RUNNER_ORDER_ID, as rule 1 of the hook contract requires. In the example, the name becomes:
If your hook waits, also make it exit once it has submitted the workload, because a waiting hook delays its orchestrator’s next hooks. After you change the hook, check each stuck session’s status in the Activity tab:
  • Queued: the session gets its next spawn request on its own
  • Failed: select Retry on it as an Owner, or have its user send it a new message

Make on-demand runners exit when idle

By default, a runner your hook starts doesn’t exit when its session’s turn finishes, so the workload you submitted keeps running. To make runners exit, have your hook pass these runner flags: Remove the workload when the runner exits, for example by setting ttlSecondsAfterFinished on a Kubernetes Job or by having the VM’s start script delete the VM afterwards.

Send a background process’s output to a file

If your spawn-runner hook leaves a process running in the background, send that process’s output to a file that the hook’s user can create. For example, append >> "$HOME/claude-runner.log" 2>&1 to the command that starts the process, ahead of any &. This hook line shows where the redirect goes, with your-background-command standing in for the command your hook backgrounds:
Without the redirect, the process writes to the hook’s stdout and stderr:
  • About a second after the hook exits, the orchestrator logs exited, but a process it started still has the hook's stdout or stderr open. From that line on, it logs up to 64 KB more of that output under [runner:hook:spawn-runner:after-exit jti=<order id>] and then drops the rest.
  • Once the orchestrator exits, the process’s writes there fail.
A runner your hook starts itself runs sessions on the orchestrator host, which holds the environment secret. Before v2.1.305, a hook that had exited still reached --hook-timeout while a process it started had the hook’s stdout or stderr open, shown as:
  • Activity tab, in a failed session’s spawn error: spawn-runner hook timed out after 60000ms, or the last lines on the hook’s stderr.
  • Orchestrator log: timed out after 60000ms, sending SIGTERM to process tree.

Exit the hook without waiting for the runner

If every on-demand runner stops about 60 seconds after its hook starts, and your hook runs again for the same session, check whether the hook waits for the runner. The 60 seconds are the default --hook-timeout, so if you set your own, runners stop that long after the hook starts. A hook that starts claude self-hosted-runner on the orchestrator’s host and waits for it, in the foreground or with wait, is still running when --hook-timeout ends. The orchestrator then stops the hook and the processes running under it, including that runner and the session’s Claude process, so a turn that’s still running is cut off.
  • To confirm that the timeout is what stops your runners: look in the orchestrator’s log for timed out after 60000ms, sending SIGTERM to process tree on every spawn request. The 60000 is your --hook-timeout in milliseconds.
  • To fix it: have the hook submit the runner to your platform and exit 0. If you raise --hook-timeout instead, the runner only stops later.

Keep transient failures retryable in a shell hook

In a shell hook that uses set -e, a failure that a retry could have cleared can block the session. The hook stops at the failing command and exits with that command’s own status, and the orchestrator applies the exit-code contract to that status. Many failures return a status of 2 or higher, such as 127 when a command isn’t installed and 22 from curl --fail on an HTTP error, so they block the session at its first failure. A session the hook has already blocked stays blocked until a user sends it a new message or an Owner selects Retry on it in the environment’s Activity tab. To turn such a failure into exit 1 instead, put these lines directly below the hook’s #! line, above anything that can fail:
These lines change how the rest of the hook behaves, so check it for each of these patterns after you add them:
  • Bare exit 2 or higher: with the trap set, it becomes exit 1. For an error that no retry can fix, call permanent with the reason instead, such as permanent "namespace claude-runners does not exist". Call it in the main shell, not inside $( ), ( ), or a pipe.
  • exec: don’t start the hook’s last command with exec, because exec replaces the shell and the trap doesn’t run.
  • Second EXIT trap: a second trap ... EXIT replaces the first, so merge the two into a single trap. Put your cleanup commands directly after rc=$?; and end each with || true;. Cleanup then runs on failure as well as on success, and a failing cleanup command doesn’t set the hook’s exit status. This merged trap shows the shape, with your-cleanup-command standing in for your own:
  • Commands that are allowed to fail: if the hook didn’t use set -e before, it now stops at the first command that returns non-zero, such as a lookup that finds nothing. If the hook acts on the result, make that command the condition of an if. If it ignores the result, follow the command with || true.
  • The command that submits the workload: don’t follow it with || true. With || true, the hook exits 0 even when your platform refuses the submit, for example over quota, and the session waits for a runner that was never started. Name the workload after CLAUDE_RUNNER_ORDER_ID, as the hook’s first rule says. An already-exists answer is then a redelivery of the same request, so treat that answer alone as success. For anything else, print the answer to stderr and exit 1, or call permanent if no retry can fix it. This example does that for kubectl create, with a job.yaml that holds only the workload:
    The orchestrator’s log then shows that message. If the hook creates other objects, name each after the order ID, give it its own command, and treat its already-exists answer as success in the same way. For an object that holds a secret, print a fixed message in place of the command’s output.
To confirm the trap works, add a line directly below the trap line that calls a command that doesn’t exist, such as no-such-command. Run the hook file from your shell and check that echo $? prints 1, then remove the line.

Stop or restart the orchestrator

To stop or restart the orchestrator without cutting off running spawn-runner hooks, start it with --shutdown-drain-sec. On SIGTERM it then gives running hooks up to the number of seconds you set to finish. To choose the value and set up your process supervisor to match, see Size --shutdown-drain-sec and the orchestrator’s stop timeout. This start command allows 70 seconds:
The orchestrator exits once the poll already sent and every hook have finished. When the --shutdown-drain-sec seconds are up, hooks still running get SIGTERM and the orchestrator exits. A second SIGTERM or any SIGINT does the same without waiting. The log line containing [runner:orchestrator] stop summary: counts hooks and spawn requests by how each one ended. Without --shutdown-drain-sec, the orchestrator stops immediately on SIGTERM or SIGINT. Each running hook gets SIGTERM, and Anthropic is told nothing. A session whose runner never got started can then sit in the queue until Anthropic re-requests it, which happens once --expected-spawn-seconds has passed, 120 seconds by default.
--shutdown-drain-sec requires Claude Code v2.1.299 or later. An older version exits at startup with error: unknown flag --shutdown-drain-sec.

Size --shutdown-drain-sec and the orchestrator’s stop timeout

At default settings, use --shutdown-drain-sec 70 with a stop timeout of 85 seconds, meaning terminationGracePeriodSeconds: 85 on Kubernetes or TimeoutStopSec=85 under systemd. If you changed --hook-timeout, scale both:
  • --shutdown-drain-sec: at least --hook-timeout plus 10 seconds, so a hook that started right before SIGTERM can still finish
  • Stop timeout: at least --shutdown-drain-sec plus 15 seconds. The orchestrator logs this figure at startup: look for the line that contains shutdown drain:.
Have your process supervisor send a single SIGTERM, to the orchestrator process alone, because a second one cuts the --shutdown-drain-sec wait short. If you leave systemd’s default KillMode=control-group in place, the hooks get SIGTERM too, and a hook can die before it submits its workload. Before you change KillMode, check how your spawn-runner hook starts runners:
  • If your hook submits its workload to a platform and exits: run the orchestrator as the unit’s main process and set KillMode=mixed, which sends SIGTERM to that process alone.
  • If your hook starts runners as processes in the orchestrator’s own unit: KillMode=mixed sends those runners no SIGTERM. Instead systemd later sends them SIGKILL, so they exit without draining their sessions or running their post-session hook.

Send model requests to Bedrock or Agent Platform

If your organization needs model requests to go through its own AWS or Google Cloud account, configure the runner for Amazon Bedrock or Google Cloud’s Agent Platform, formerly Vertex AI. Every session that runner starts then calls the model in your cloud account, with your cloud credentials. Without this configuration, sessions send model requests to the Anthropic API. The runner still polls Anthropic for sessions, and each session still sends its event stream to api.anthropic.com. The event stream carries prompts, responses, and tool results. The plan requirement and the Zero Data Retention exclusion in Availability and limitations still apply. Sessions are routed to an environment, not to a runner, and a requeued or resumed session can run on a different runner. Configure every runner in the environment the same way. Before you start, read what differs on these providers.
1

Prepare the cloud account and your egress rules

Set up model access, a narrowly scoped policy or role, and network access:
  • Amazon Bedrock: submit use case details, then create the policy in IAM configuration, limiting bedrock:InvokeModel and bedrock:InvokeModelWithResponseStream to the inference profiles your sessions use and the foundation models behind them
  • Agent Platform: enable the API and request model access, then create the custom role that IAM configuration describes, with only aiplatform.endpoints.predict
  • Egress: allow your provider’s endpoints through your egress rules. See Network requirements. If sessions can’t reach them, Claude Code can keep retrying for hours before the session shows an error.
2

Give sessions narrowly scoped credentials

Attach the policy or role from step 1 to an identity that can do nothing else. For the methods Claude Code accepts, see Configure AWS credentials and Configure GCP credentials.
Anyone who can get code to run in a session, including through prompt injection, can use these credentials at your cost for as long as the credentials are valid. Claude Code runs inside the session, so the credential it calls the model with has to be readable there.The shell commands Claude runs, your Claude Code hooks, and stdio MCP servers inherit the session’s environment and run as the same user as Claude Code. As a result, they can read credential variables and credential files.When you harden your deployment, you keep host credentials out of sessions, but you can’t keep this credential out. Give the identity behind it nothing beyond the policy or role from step 1.
Check the method you choose against these runner behaviors:
  • Metadata endpoint: if you deny sessions the cloud metadata endpoint outright, credentials served from it, such as an instance profile, don’t reach Claude Code either. A file-based web identity, such as IAM Roles for Service Accounts (IRSA) on Amazon EKS or a Workload Identity Federation credential file, doesn’t depend on it.
  • Renewal: a session can outlive a credential, so use a method that renews itself, such as a file-based web identity
  • Wrapper script: credential values your wrapper script exports aren’t renewed while Claude Code runs, so for a long session, use a method that renews itself. Claude Code reads AWS credentials from its environment, so if your wrapper already exports AWS credentials for other work, Claude Code can sign model requests with them.
3

Set one provider's variables in the runner's environment

Set exactly one provider’s variables where you set the runner’s other environment variables, such as the container spec or service unit, then restart the runner. The examples show them as shell exports. With on-demand runners, set them on the workload your spawn-runner hook starts.Start these runners with --confine-repo-settings enforce. It refuses sessions on repositories whose committed settings it flags, so run in the default warn mode first and clear what it logs.
Replace the region with your own:
For how Claude Code resolves the region, see Configure Claude Code. For which inference profile prefix Claude Code uses for your region, see Cross-region inference profile prefixes.
4

Check that the variables reached a session

Your own shell on the host is a different process, so check from inside a session. Start one in the environment and ask Claude to run this command:
A line that sets CLAUDE_CODE_USE_BEDROCK or CLAUDE_CODE_USE_VERTEX to 1 means the variable reached the session. If both appear, Claude Code uses Amazon Bedrock. No output means neither reached it.The command shows configuration, not traffic. To confirm the requests themselves, look for them in your cloud account’s own metrics or request logs. If the first message fails instead, see troubleshooting for Amazon Bedrock or Agent Platform.

What differs from sessions on the Anthropic API

A session that sends model requests to Amazon Bedrock or Google Cloud’s Agent Platform differs from a session on the Anthropic API in these ways:
  • Policy from claude.ai: server-managed settings don’t reach these sessions. Neither do the organization policies an Owner sets in Claude Code admin settings, so Claude Code doesn’t enforce them inside the session. Put the rules you rely on in the runner image’s managed settings file.
  • Account skills: these sessions don’t download the skills enabled for a person’s claude.ai account. See How each session’s config is assembled.
  • Files: files that people attach to a session in claude.ai or the mobile or desktop app don’t reach it, and Claude can’t send files back with the SendUserFile tool. Put input files in the repository or on the runner instead.
  • Model selection: Anthropic’s control plane sends each session’s model, and when a session starts without one, Claude Code uses its default for the provider. You can’t choose the model with ANTHROPIC_MODEL or ANTHROPIC_DEFAULT_MODEL in the runner’s environment, but you can pin what an alias resolves to:
    • ANTHROPIC_MODEL and ANTHROPIC_DEFAULT_MODEL: the runner removes them from the environment it passes to sessions, even though the provider pages’ examples set ANTHROPIC_MODEL.
    • Per-family pinning variables: the variables in Pin model versions for Amazon Bedrock and Agent Platform do reach sessions. They decide what an alias such as opus resolves to, not what a full model ID resolves to.
  • Models your account doesn’t serve: a session can fail on a message with an error that names the model. Enable the models your developers can choose, the background model described in Pin model versions, and the classifier model that auto mode uses. On Amazon Bedrock, allow each of them in your policy.
  • Web search and fast mode: web search isn’t available on Amazon Bedrock, and fast mode isn’t available on either provider. For other capabilities that differ by provider, see CLI capabilities that vary by provider.

MCP servers

To make MCP servers available in every session, add them at image build time with the same claude mcp add command used on a desktop install. If your runner is a bare process rather than a container, run the same command as the runner’s user on the host, then restart the runner: it reads host config once at startup. The --scope user flag is required; the default local scope writes under a per-directory key that the runner doesn’t seed into sessions. For example, in your Dockerfile:
The runner snapshots the host’s config once at startup. The snapshot captures the mcpServers key from the host’s .claude.json, which lives next to rather than inside ~/.claude/, and the runner seeds only that key into each session’s isolated config; account state and project history are dropped. To confirm the servers reached sessions, start a session on the environment and ask Claude to list its MCP tools; the runner also logs a startup warning for any captured entry whose type it doesn’t recognize and drops the entry, so you can see why that server is missing from sessions. When SELF_HOSTED_RUNNER_HOST_CONFIG_DIR is set, the runner reads .claude.json from that directory instead, so pointing the variable at an empty directory disables MCP seeding too. Claude Code also loads MCP servers from other sources:
  • The enterprise-scope managed MCP file at its standard system path: /etc/claude-code/managed-mcp.json on Linux runner hosts, /Library/Application Support/ClaudeCode/managed-mcp.json on macOS hosts. Use it for locked-down fleets where only administrator-listed servers may load. See exclusive control with managed-mcp.json for the precedence rules. When this file is on the runner host, Claude Code skips the MCP servers Anthropic’s control plane delivers to a session, including claude.ai connectors, and names them in a warning on the session child’s stderr, which the runner records at the debug log level. Before v2.1.229, those sessions exited at startup with You cannot dynamically configure MCP servers when an enterprise MCP config is present.
  • The managedMcpServers key in managed settings on the runner host: provides HTTP and SSE servers without taking exclusive control, so servers from the other sources still load. Requires Claude Code v2.1.259 or later.
  • <repo>/.mcp.json: project scope. Outside a project thread, commit the file to the repository, and its servers are auto-approved in cloud sessions. In a session with several repositories, at most one repository’s file loads.
  • A --mcp-config file from your wrapper script: append the flag after "$@", as in exec "$CLAUDE_RUNNER_CLAUDE_BIN" "$@" --mcp-config /etc/claude/mcp.json. To keep that file’s servers running when the session’s delivered servers are updated mid-session, have your wrapper pass the full environment to the child, as exec does. Before v2.1.299, the stdio, HTTP, and SSE servers in that file shut down at the first such update that didn’t name them.
When connector delivery is enabled for your organization, Anthropic’s control plane delivers the connectors you’ve configured on claude.ai to interactively-created sessions through server-provided MCP configuration, routed through api.anthropic.com. Sessions created programmatically, such as CLI dispatches, don’t receive connector delivery; give them MCP servers through any of the other sources this section lists instead. The child’s OAuth token doesn’t carry a scope for fetching connectors directly, so the child doesn’t attempt that fetch itself; delivery is server-driven.
In a session that received a connector, a server of the same name from the host’s .claude.json or a repository’s .mcp.json isn’t connected. To use both, give your server a different name.
settings.json doesn’t carry MCP server definitions, and there is no top-level mcpServers field in the settings schema. In managed settings, provide servers with the managedMcpServers key instead. Sessions inherit the runner’s environment, so set ENABLE_TOOL_SEARCH there to control MCP tool search for every session a runner spawns; the MCP page covers the values.

Wait for MCP servers before the first turn

A self-hosted session waits briefly for MCP servers that are still connecting, at two separate points. A server that misses a wait has its tools missing when the first turn starts, and they become available later with no action on your part. The two waits are:
  • Session startup: before the tool list is first taken, the session waits up to 5 seconds by default for an HTTP or SSE server whose entry sets alwaysLoad: true, or for all servers when you set MCP_CONNECTION_NONBLOCKING=0 in the runner’s environment. HTTP and SSE servers otherwise connect in the background. While the session waits here, it’s slower to initialize. MCP_CONNECT_TIMEOUT_MS changes the 5-second default.
  • First turn: after the message arrives, the first turn waits up to 2 seconds for stdio servers that are still connecting. While the session waits here, the first reply is slower. To change how long this wait lasts, set CLAUDE_CODE_MCP_STARTUP_WAIT_MS in the runner’s environment. It doesn’t change which servers the wait covers. Requires Claude Code v2.1.274 or later.
claude mcp add has no alwaysLoad flag. To set the key, add the server with claude mcp add-json instead, which takes it in the server’s JSON and writes it to .claude.json. In your Dockerfile:
If a server’s tools don’t appear on later turns either, check whether the server reached the session at all, as MCP servers describes.

Turn off built-in session tools

Anthropic’s control plane attaches its own MCP server, named Claude Code Remote, to cloud sessions. Claude uses the server’s tools to create cloud scheduled tasks, start and steer other cloud sessions, attach more repositories, and follow pull request activity. To turn off the whole server, add a server-level deny rule to your settings. The control plane registers the server under one of three names, depending on how the session was created. Claude Code matches the name in a rule exactly, including case, so write the rule once per name as shown:
A rule that names the whole server covers tools the server gains later too. To turn off one tool and keep the rest, append two more underscores and the tool name to each rule, as in mcp__Claude_Code_Remote__add_repo. To block the server from connecting at all rather than removing its tools, add the three names without the mcp__ prefix as serverName entries under deniedMcpServers instead. Put the rules in server-managed settings to reach sessions with no change to the runner, or in ~/.claude/settings.json on the runner. On a runner that sends model requests to Bedrock or Agent Platform, use that file, because server-managed settings don’t reach those sessions. Permissions and tool approval explains how settings on the runner reach sessions. To confirm the rules took effect, start a session on the environment and ask Claude to list its MCP tools. Claude Code removes a denied tool from Claude’s context, so the denied tools are absent from its answer.

Prompt sessions to push their work

Anthropic-hosted sessions run a Stop hook, the Claude Code hook that runs when Claude finishes responding, that prompts Claude to commit and push its work. The runner doesn’t install one. Without it, a session that ends with uncommitted changes leaves that work only on the runner’s disk, and the Create PR button in claude.ai/code stays inactive until the branch exists on the remote. The reference implementation below has two parts. Merge the settings block into ~/.claude/settings.json on the runner host, which the runner seeds into every session, and save the script as ~/.claude/hooks/stop-hook-nudge.sh on the runner host and make it executable:
The hook prompts Claude to commit and push before the session ends, and stays silent when the directory isn’t a git repository or has no remote. For a session with several repositories, see what $CLAUDE_PROJECT_DIR names. The Stop hook only prompts Claude. For the commit and push to work, set up: The Stop hook prompts at most once per turn. If the commit or push fails, the turn still ends. Look for git’s error in the session and fix what it names. On a large checkout, raise timeout in the Stop hook settings and restart the runners. The script’s git status skips core.fsmonitor, so it can take longer than the 10 seconds set there. A hook that times out ends the turn with no prompt.

Submodules and the Stop hook

The Stop hook checks which commit each submodule is on, not the files inside it:
  • A new commit in a submodule: Claude is prompted until the parent repository records it, even if .gitmodules sets ignore = all for that submodule
  • Uncommitted files in a submodule: Claude isn’t prompted, so that work stays only on the runner’s disk
  • Unpushed commits in a submodule: the Stop hook doesn’t check whether they’re pushed, so the parent can point at a commit that nobody else can fetch

Replace an earlier copy of the Stop hook script

Search your copy of stop-hook-nudge.sh for GIT_OPTIONAL_LOCKS. If it’s missing, you have an earlier copy. Replace it with the current script wherever you installed it, then restart the runners. Keep your Stop hook settings, except to raise timeout on a large checkout.
  • When: if your sessions run with the Bash sandbox on, replace it now. Otherwise, replace it at your next image build or runner restart.
  • What changes: uncommitted files in a submodule no longer prompt Claude. A new commit in a submodule that .gitmodules marks ignore = all now does.
Hooks run outside the Bash sandbox, so the current script’s git calls skip some git features that can start a program named in the checkout’s git settings. They don’t skip them all. Don’t count on the sandbox alone, and isolate sessions as Harden your deployment describes.

Permissions and tool approval

A self-hosted session has no terminal attached, so an unanswered permission prompt stalls the turn until the user responds in the UI. Anthropic’s control plane sends each session’s tool list and permission rules with the work payload; the default configuration pre-approves routine tool calls, including Bash, and cloud sessions pre-approve file edits regardless of mode. A call that nothing pre-approves prompts through the session UI.
Only pin auto mode on an environment whose session containers run with default-deny network egress and the rest of the hardening section in place. Routine tool calls, including Bash network requests, run without a human in the loop on both the default pre-approved tool set and in auto mode, so the network boundary is what limits where those calls can reach.
To keep prompts to a minimum regardless of what the control plane sends, pin auto mode from your wrapper script or command hook. Auto mode lets sessions run without routine permission prompts: a separate classifier model reviews actions before they run and blocks the ones it rejects, and explicit ask rules still force a prompt; the permission modes page covers what the classifier checks. The runner appends server-computed flags before invoking the wrapper, and for single-value flags such as --permission-mode the parser honors the last occurrence, so a flag you append after "$@" overrides the server-sent value:
To pre-approve specific tools instead, append --allowed-tools with your rules, for example --allowed-tools "Bash(bazel *) Bash(yarn *) mcp__internal__*". List flags such as --allowed-tools and --disallowed-tools accumulate across occurrences rather than overriding, so your rules apply on top of any rules the control plane sends. To narrow, append --disallowed-tools, which denies tools even if another rule allows them.

How each session’s config is assembled

The runner gives each session its own config directory, seeded from a snapshot of the host’s ~/.claude/ that the runner captures once at startup: settings.json, CLAUDE.md, hooks, agents, commands, and skills in your runner image apply to every session as the user-level baseline. If you change config on a running host, the change takes effect only after you restart the runner. Set SELF_HOSTED_RUNNER_HOST_CONFIG_DIR to seed from a different path, or point it at an empty directory to disable seeding. Sessions also read these settings files: For the order these sources apply in, see settings precedence. When Anthropic’s control plane supplies a session with Claude Code hooks, the runner installs them alongside, not over, your own configuration. Requires Claude Code v2.1.229 or later; older runners ignore supplied hooks. The supplied hooks run python3, so install python3 in your runner image.
  • Where they land: the runner writes each supplied hook script to a reserved hooks/.ccr-launcher/ subdirectory of the session’s config directory and registers the scripts in a separate settings file it passes to the session with --settings, leaving the seeded settings.json and your own scripts at hooks/<name> untouched. The runner recreates the reserved subdirectory for each session and doesn’t seed host content at ~/.claude/hooks/.ccr-launcher/ into sessions.
  • Who authors them: the control plane populates the scripts from fixed constants in its own deployment, never from per-session or third-party input.
  • What still governs them: hooks delivered through --settings enter the ordinary merged hook configuration, not the managed tier, so your managed settings still apply. disableAllHooks disables them, and they are not among the categories allowManagedHooksOnly keeps loaded.
When a person starts their own session, Claude Code downloads the skills enabled for their claude.ai account into that session’s config directory. A cloud scheduled task run doesn’t get its owner’s skills, and a session that sends model requests to Bedrock or Agent Platform doesn’t download any. For a skill those sessions need, add it to your runner image or, outside a project thread, commit it to the repository’s .claude/skills/. Outside Claude Tag sessions, a session in a self-hosted environment runs with auto memory off by default. For instructions that should carry across sessions, use the CLAUDE.md in your runner image or in the repository. The runner’s snapshot of the host’s ~/.claude/ leaves out the projects/ directory. Auto memory’s default storage location is under that directory. If you put memory files there, the runner doesn’t seed them into sessions, and they don’t turn auto memory on.

Stop sessions that fail to fetch server-managed settings

To keep a session that fetches server-managed settings from starting when that fetch fails, set forceRemoteSettingsRefresh to true in the managed-settings.json in your runner image. A reply from Anthropic’s API that your organization has no server-managed settings counts as a successful fetch. Before you add the key, check whether the environment runs Claude Tag channel sessions or sends model requests to Bedrock or Agent Platform:
  • Claude Tag channel sessions: leave the key out on runners in an environment that an Owner routes Claude Tag channels to. Anthropic’s API refuses these sessions’ request for server-managed settings, so with the key set they fail to start. Put their rules in the runner image’s managed-settings.json, which they still read. To use the key for your other sessions, run those in a separate environment.
  • Bedrock or Agent Platform: sessions on these providers don’t fetch server-managed settings, so they start whether or not you set the key. Enforce your rules from the same managed-settings.json instead.
This managed-settings.json sets the key:
managed-settings.json
Set the key in that file even if you also set it in the claude.ai admin console. A new session has no cached copy of your server-managed settings, so if you set the key only in the console, the session doesn’t have it yet. If its fetch then fails, the session runs without those settings until a later fetch succeeds. To confirm that a failed settings fetch is why a session didn’t start, look at Claude Code’s last output in the session or the runner’s log. It includes Your organization requires remote managed settings to load, but they could not be loaded.

Repository settings in sessions with several repositories

In a thread in a project, no repository’s .claude/settings.json takes effect as project settings and no repository’s .mcp.json or skills load, wherever the thread starts. To give those threads a skill, add it to your runner image. In any other session with several repositories, Claude Code reads project settings from the directory the session starts in, so at most one repository’s .claude/settings.json takes effect as project settings. A hook defined in another repository’s file doesn’t run, a deny rule in it doesn’t apply, and its env isn’t set.
  • --capacity 1, the default, with the built-in checkout: the session starts in the first repository in its list of repositories. That repository’s .claude/settings.json takes effect as project settings and its .mcp.json loads, and the other repositories’ don’t.
  • A --capacity above one, or a checkout hook: the session starts in a per-session directory that contains the checkouts. No repository’s .claude/settings.json takes effect as project settings, no repository’s .mcp.json loads, and $CLAUDE_PROJECT_DIR in a hook command is that directory, not a checkout.
Each repository’s CLAUDE.md loads wherever the session starts. Outside a project thread, its skills load too. The runner passes every repository to Claude Code as an additional directory, so Claude Code also reads the enabledPlugins and extraKnownMarketplaces keys from each repository’s .claude/settings.json. To run a hook or apply a permission rule in every session, put it in ~/.claude/settings.json on the runner host. The runner seeds the host file into every session, wherever the session starts. Write a path in a Read or Edit rule as a // absolute or ~/ home-relative pattern, because other patterns anchor at the settings source or the current directory.

Repository-committed permission rules

Don’t put a bare "Edit", "Write", or "NotebookEdit" entry in a repository-committed permissions.allow. A bare file-tool rule matches the tool regardless of path, granting writes anywhere on the host rather than only the workspace, so the runner’s write-scope confine guard flags the session; with --confine-repo-settings enforce it refuses to spawn the session instead of logging and continuing. See the hardening section. A repository needs no file-tool rule at all: cloud sessions pre-approve file edits regardless of mode. If you do commit a rule, scope it to the workspace, such as "Edit(/**)"; a single leading slash is relative to the project root, which is the session’s workspace. Bare file-tool rules are fine in the operator’s host-level settings.json, since that file isn’t repository-committed. A defaultMode of auto is only honored from the image-wide or user-level settings file, so a checked-out repository can’t grant itself auto mode. For which modes cloud sessions accept and the full rule syntax, see permission modes.

What’s next