Virtual agents run claude -p (headless mode) inside Apple Containers. This mode requires an OAuth token that is only available with an active Claude Pro or Claude Max subscription on claude.ai.
Without an active subscription, the CLI cannot authenticate the headless session and the agent will fail immediately with an authentication error.
Make sure you have an active Pro or Max subscription on claude.ai. You can verify your plan under Settings → Subscription.
claude loginThis command opens an OAuth flow in your default browser. Authorize access when prompted.
Once the OAuth flow is complete, the token is automatically stored in ~/.claude/. You can verify it exists:
ls ~/.claude/You should see the credential files generated by the CLI.
The system uses two distinct environment variables for the OAuth token, one on the host and one inside the container:
| Context | Variable | Purpose |
|---|---|---|
| Host | CLAUDE_CONTAINER_OAUTH_TOKEN |
Token stored as an environment variable in your shell |
| Container | CLAUDE_CODE_OAUTH_TOKEN |
Token injected into the container, consumed by claude -p |
In the Makefile, the host variable is defined as:
HOST_TOKEN_VAR := CLAUDE_CONTAINER_OAUTH_TOKENAnd mapped to the container via the -e flag:
-e CLAUDE_CODE_OAUTH_TOKEN=$${$(HOST_TOKEN_VAR)}This takes the value of CLAUDE_CONTAINER_OAUTH_TOKEN on the host and injects it as CLAUDE_CODE_OAUTH_TOKEN inside the container. The Claude CLI reads this variable automatically on startup.
- Session isolation: The container session is independent from the host session. If an agent fails or its token expires, your local Claude Code session is not affected.
- Credential collision prevention: Prevents the container from overwriting or interfering with the credential files in
~/.claude/on the host.
Add the following variables to your ~/.zshrc or ~/.bashrc:
# OAuth token for agent authentication in containers
export CLAUDE_CONTAINER_OAUTH_TOKEN=<your-oauth-token>
# Directory where agent worktrees will be stored
export AGENTS_HOME=~/agentsApply the changes:
source ~/.zshrc # or source ~/.bashrcVerify the variables are set:
echo $CLAUDE_CONTAINER_OAUTH_TOKEN
echo $AGENTS_HOMERun the following command in your terminal:
claude setup-tokenThis generates the OAuth token and displays it in the output. Copy it and export it:
export CLAUDE_CONTAINER_OAUTH_TOKEN=<obtained-token>To make it persistent, add the line above to your ~/.zshrc or ~/.bashrc.