← Claude Docs

Customize sessions in self-hosted environments - Claude Code Docs

Claude Docs · August 12, 2026
Self-hosted Claude Code environments use runner processes that can be extended through wrapper scripts for per-session setup like credential provisioning and resource management. Lifecycle hooks such as checkout and post-session customize repository handling and preserve uncommitted work by replacing stages of the runner's pipeline. Configuration occurs through command-line flags and environment variables that provide session identity and workspace information to these extension points.

Detailed Analysis

Anthropic's documentation for self-hosted Claude Code environments reveals a maturing enterprise infrastructure play: platform engineers can now deploy their own "runners" — processes that execute Claude Code cloud sessions on customer-controlled infrastructure rather than solely on Anthropic-managed servers. The default behavior is simple (clone a repo, spawn Claude Code, clean up), but the documentation focuses on the extension points available when that default isn't sufficient — wrapper scripts that intercept the Claude Code binary launch, and lifecycle hooks that replace individual stages of the per-session pipeline, such as the "checkout" step that handles repository cloning. This is infrastructure-level tooling aimed squarely at engineering teams running Claude Code at scale inside regulated or security-conscious organizations, not at individual developers.

The technical depth here signals how seriously Anthropic is treating enterprise deployment concerns around credential management, process isolation, and auditability. Wrapper scripts allow organizations to provision short-lived, session-scoped credentials (e.g., exchanging a session JWT for temporary AWS credentials tied to the specific user who created the session), inject environment-specific secrets, or enforce resource limits — all before handing off execution to Claude Code itself via an `exec` call that preserves signal handling and exit codes. The documentation is unusually precise about failure modes: it warns that backgrounding the child process with a bare `&` severs stdin, causing sessions to silently fail after the roughly 30-minute OAuth token lifetime expires, manifesting as opaque 401 errors. This level of operational specificity — down to file descriptor handling (keeping fd 3 open for activity signals that drive idle/timeout detection) — indicates Anthropic has encountered and is proactively addressing real production pitfalls reported by early enterprise adopters.

The identity and credential model described is particularly notable. Session JWTs carry claims distinguishing human-created sessions (`user:` subject) from bot or agent-initiated sessions (`agent:` subject), and the docs explicitly flag that organizations must decide whether automated agent sessions should be granted default credentials or rejected outright. This reflects a broader industry challenge: as AI coding agents increasingly act autonomously — triggered by bots, CI pipelines, or other agents rather than direct human input — access control systems built around human identity assumptions need explicit extension to handle non-human actors safely. The emphasis on scoping credentials to "the session creator" and verifying tokens against a JWKS endpoint mirrors zero-trust and least-privilege patterns already standard in cloud-native security, now being adapted for AI agent execution contexts.

More broadly, this documentation is a marker of Claude Code's evolution from a developer CLI tool into a platform product with pluggable, self-hosted execution — a trajectory similar to how CI/CD systems (GitHub Actions runners, GitLab runners) matured from hosted-only services into hybrid systems supporting customer-managed compute. As coding agents move from experimental assistants toward systems that autonomously execute in production-adjacent environments, the infrastructure requirements around credential scoping, git checkout customization, and lifecycle hardening become as important as the underlying model capabilities. This positions Anthropic to compete for enterprise customers who need Claude Code to operate within existing security perimeters, air-gapped networks, or custom compliance regimes — a necessary step for AI coding agents to move beyond individual productivity tools into governed, organization-wide software development infrastructure.

Read original article →