> ## Documentation Index
> Fetch the complete documentation index at: https://docs.crewship.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Claude Code

> Anthropic's coding agent (CLAUDE_CODE adapter)

`@anthropic-ai/claude-code` (v2.1.126+). Production-ready in Crewship since
day one; the canonical reference for what every other adapter targets for
parity.

## Install

Pre-installed in every seeded crew via the `ghcr.io/devcontainers-extra/features/claude-code:2` devcontainer feature. To pull manually:

```bash theme={null}
npm install -g @anthropic-ai/claude-code
```

## Auth

Two modes, both supported:

| Type                     | Env var                   | Format           |
| ------------------------ | ------------------------- | ---------------- |
| API key                  | `ANTHROPIC_API_KEY`       | `sk-ant-api03-…` |
| OAuth (Claude Pro / Max) | `CLAUDE_CODE_OAUTH_TOKEN` | `sk-ant-oat01-…` |

Crewship's sidecar reverse-proxy injects the API key into `api.anthropic.com` requests so the agent container never sees the raw token. OAuth tokens flow through the HTTPS CONNECT tunnel directly (sidecar passes through, Claude Code sets `Authorization: Bearer` itself).

## Models

| API string                  | Tier     | Notes                                              |
| --------------------------- | -------- | -------------------------------------------------- |
| `claude-opus-4-7`           | frontier | Default for complex reasoning                      |
| `claude-sonnet-4-6`         | frontier | Best speed/intelligence balance — Crewship default |
| `claude-haiku-4-5-20251001` | fast     | 200k ctx                                           |

Legacy `claude-opus-4-6 / 4-5 / 4-1`, `claude-sonnet-4-5`, `claude-opus-4-5` still selectable. Claude 4 (`claude-*-4-20250514`) retires 2026-06-15.

## Command shape

Crewship's adapter builds:

```bash theme={null}
claude --print --output-format stream-json --include-partial-messages \
       --dangerously-skip-permissions --verbose \
       [--bare] --setting-sources "" --strict-mcp-config --no-session-persistence \
       --model <model> --system-prompt <preamble+persona> \
       --tools <per-profile built-in allowlist> \
       --max-turns 50 \
       --mcp-config /crew/agents/<slug>/.mcp.json \
       -- <user message>
```

`--bare` disables auto-discovery of `~/.claude/CLAUDE.md`, plugins, hooks, skills, and MCP — Crewship sets all of those explicitly via flags. **It is appended only when the agent's credential is an API key.** Claude Code 2.x changed the `--bare` auth contract: it now strictly requires `ANTHROPIC_API_KEY` (or an `apiKeyHelper` via `--settings`) and IGNORES `CLAUDE_CODE_OAUTH_TOKEN`. To keep OAuth-seeded workspaces working (`AI_CLI_TOKEN` credentials with `sk-ant-oat*` values), the adapter drops `--bare` when it detects OAuth on the run, so the normal Claude auth flow can pick up `CLAUDE_CODE_OAUTH_TOKEN`. API-key runs keep the isolation win. See `internal/orchestrator/adapter_claude.go:21-50`.

`--tools` is **always** passed with the agent's per-profile built-in allowlist (`MINIMAL` → `Read,Glob,Grep,ToolSearch`; `CODING` → `+Write,Edit,Bash,WebFetch,WebSearch`; `FULL` → `+NotebookEdit`). This removes harness-internal tools (`TaskCreate`, `Agent`, `Workflow`, `Cron*`, …) that have no Crewship backing from the agent's context. `ToolSearch` is kept so deferred MCP tools (crewship-memory, Composio) stay discoverable; MCP tools themselves are not affected by `--tools`. See [Tool profiles & the built-in tool allowlist](/guides/cli-adapters#tool-profiles-the-built-in-tool-allowlist).

## MCP

Configured at `/crew/agents/<slug>/.mcp.json`. Standard schema:

```json theme={null}
{
  "mcpServers": {
    "linear": {
      "type": "http",
      "url": "https://mcp.linear.app/sse",
      "headers": {"Authorization": "Bearer ${LINEAR_TOKEN}"}
    },
    "fs": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-filesystem", "/work"],
      "env": {"FOO": "${FOO}"}
    }
  }
}
```

Env-var refs `${VAR}` resolve from the agent container's process env at MCP server spawn time. Crewship's `injectMCPCredentialEnvVars` populates them from workspace credentials.

## Memory

Same canonical memory file set as every other adapter — `AGENTS.md`, `CLAUDE.md`, `GEMINI.md`, `.cursor/rules/crewship.md`, `.factory/AGENTS.md` — written to `/output/<slug>/`. Even though `--bare` skips Claude Code's own `CLAUDE.md` discovery (system prompt arrives via `--system-prompt`), Crewship writes the file so a customer SSH-ing into the container sees the same context the agent operates on.

## Output stream

JSONL events documented at [code.claude.com/docs/en/cli-reference](https://code.claude.com/docs/en/cli-reference). Crewship parses every documented type:

* `system` (subtype `init` / `api_retry`)
* `stream_event` (text / thinking deltas)
* `assistant` (tool\_use, tool\_result blocks)
* `tool` / `user` (tool result blocks)
* `result` (terminal envelope with usage + cost)

## Troubleshooting

**`claude: not found`** — devcontainer feature didn't install; check crew `devcontainer_config` for `ghcr.io/devcontainers-extra/features/claude-code:2`.

**401 from Anthropic** — credential not assigned to agent. Check `crewship credential assign <name> <agent>` and verify the credential has `type=API_KEY` or `type=AI_CLI_TOKEN` with `provider=ANTHROPIC`.

**Model retires 2026-06-15** — UI shows a badge on retiring models (claude-3.5-*, claude-*-4-20250514). Migrate to `claude-sonnet-4-6` or `claude-opus-4-7`.
