TwinDocs
Connect your AI

Connect Claude Code

Use the Twin CLI from Claude Code, with MCP as an optional integration.

Claude Code can call the Twin CLI directly. This is the recommended setup: it keeps credentials in the operating system's credential store and does not add organisation details to a repository.

Copy this into Claude Code

Ask Claude Code to set up my Twin
Connect this Claude Code user to my organisation's Twin for approved questions.

Read the live Claude Code and CLI guides before setup:
- https://docs.mlx.systems/docs/connect/claude-code
- https://docs.mlx.systems/docs/connect/cli
Use those guides if installation, sign-in, or a command is unclear. After
installation, treat `twin help --json` as the exact contract for that installed
CLI version.

First run `command -v twin`. If it is missing, follow the official Twin CLI
guide and install the public GitHub Release globally. Do not request a GitHub
account or token, use `npx`, add the CLI to this repository, install a similarly
named package, or use `sudo`.

Verify the global command with `command -v twin` and `twin help --json`. It must
work outside this repository. If npm installed it but the command is not on
`PATH`, fix the current user's persistent shell `PATH` without overwriting
unrelated configuration, then tell me to restart Claude Code so it inherits the
new `PATH`. Do not continue until the global command works.

Run `twin login` and let me complete browser sign-in. Do not request SSH,
Tailscale, a tenant or organisation ID, an API key, or a token. Never read,
print, log, commit, or place a credential in shell history.

Use the `twin help --json` result as the current command contract. List accessible
organisations with `twin organisations --json`, run `twin status --json`, and
tell me which organisation is current. If several are available, ask me which
one to use; never guess. Switch with `twin organisations --use` without logging
in again, confirm with `twin status --json`, then list channels with `twin
channels --json` and inspect the relevant one.

Verify with one real routed `twin query --stream --client-app claude-code`, explaining its queued and
running status before presenting the terminal result and retaining its
query/task/session IDs. Use a
deterministic intent only with fields returned by channel inspection, and never
submit raw SQL or guess product or relation names. Read channel feeds and flat
threads in small pages when useful. List channel members before using canonical
mention IDs. Add a channel post, comment, reaction, record, view update, or
artifact creation/update only after I approve the exact mutation and content,
and use `--allow-write`. Use
`eyes` for seen and `check` for handled; reading alone does not mark activity
seen. Posts and comments can mention people, accessible channels, Data Sets in
the current channel, and active saved Views by their canonical IDs. Pass
`--client-app claude-code` on queries, posts, and artifacts so the
web app can show where the action started. Do not configure MCP unless I explicitly ask. If a human OAuth or
administrator step is required, stop and state that boundary clearly.

If I provide or confirm feedback, submit it with `twin feedback` and attach
the routed query ID when relevant. Never infer feedback on my behalf.

See Use the Twin CLI for the manual commands.

Optional MCP configuration

Use MCP only when you specifically want Twin tools exposed as native Claude Code tools. It is not required for Claude Code to run twin commands.

Claude Code expands environment variables in remote-server URLs and headers. Use the following shape in your user-level MCP configuration:

User-level Claude Code MCP configuration
{
  "mcpServers": {
    "twin": {
      "type": "http",
      "url": "https://<gateway>/mcp",
      "headers": {
        "Authorization": "Bearer ${MLX_TWIN_OAUTH_ACCESS_TOKEN}"
      }
    }
  }
}

Run claude mcp list and inspect /mcp after Claude Code starts. Preserve unrelated user-level servers and do not add this to project .mcp.json unless you explicitly want project-scoped configuration.

Avoid a literal command-line token

Claude Code supports --header, but passing a literal bearer token on a command line can leave it in shell history. Use environment expansion in user-level configuration for this controlled connection.

See Anthropic's current Claude Code MCP guide for configuration scope and environment-variable expansion.

On this page