Skip to content

Connect Claude Code

Claude Code connects to Hivemind through one MCP entry. The same endpoint serves short, mid and long memory; never add a separate graph server. This page covers the two ways to authenticate, verification, and the project instructions that ask Claude Code to use the memory on every task. The complete client guide with troubleshooting is CLAUDE_CODE_INTEGRATION.md.

Written for Claude Code 2.1.286.

Prerequisite: Claude Code 2.1 or newer (claude --version) and an instance that passed the readiness checkpoint.

1. Give Claude Code its identity

Each agent gets its own identity; never share one between assistants. Two options, chosen by the operator of the instance.

For your own agent, open Account → Agents in the Portal and select Create agent with Read and write on the target space. Then select Manage → Issue API token and choose 1, 7, 30, 90 or 365 days, or a custom whole number from 1 to 365. The hm_… token is shown once; it acts with the agent's current grants. An operator can instead issue a credential for a standalone agent in Identity & Groups → Agents and credentials → Issue credential, with an optional UTC expiry (one day by default, seven days at most); see Identity and access. A token imported from 1.6 (lm_…) is used the same way.

Create .mcp.json at the project root with an environment reference only:

{
  "mcpServers": {
    "hivemind": {
      "type": "http",
      "url": "https://hivemind.example.org/mcp",
      "headers": {
        "Authorization": "Bearer ${HIVEMIND_TOKEN}"
      }
    }
  }
}

Set the secret in the environment that launches Claude Code, without recording it in shell history:

printf 'Hivemind token: '
IFS= read -r -s HIVEMIND_TOKEN
printf '\n'
export HIVEMIND_TOKEN
claude

Claude Code asks for approval before loading a project-scoped server; review the file before approving it. Never add a default value for HIVEMIND_TOKEN: a missing secret must fail visibly.

When the operator has enabled the OAuth policy on the instance, no token is needed:

claude mcp add --transport http hivemind https://hivemind.example.org/mcp
claude mcp login hivemind     # opens the browser: sign in, choose the agent, Allow
claude mcp get hivemind       # Status: ✔ Connected
claude mcp logout hivemind    # revokes the connection at Hivemind

The consent page shows which spaces the connection may use and which agent acts; OAuth grants read and write only, never manage. The connection ends at the operator's absolute lifetime and asks you to sign in again. Claude.ai and Claude Desktop custom connectors are a different path that needs a publicly reachable HTTPS instance. See native OAuth for MCP clients.

2. Verify the connection

claude mcp list        # hivemind … ✔ Connected

Then, in a Claude Code session in the project, ask:

Call system_whoami on hivemind and show me the result.

Expected: "status": "ok", auth_type: auth17, a client_name that is the agent's UUID, not its display name, and the tutorial space under allowed_spaces, which lists the spaces the agent can read. Compare client_name with the Agent ID shown in the agent's details in the Portal. The permissions list is empty: that legacy field does not describe 1.7 grants, so it proves neither read and write nor the absence of manage. Check the rights in the Portal instead: the agent's Space access under Account → Agents, or, for an operator, the credential's Effective rights under Identity & Groups → Agents and credentials. Ask it to call space_rules, mid_read_all and short_read on that space next.

If memory bank writes such as mid_consolidate fail with auth17_commit_unqualified, the instance's storage failed Core's startup write witness; the operator fixes it as described in Install in production.

To avoid a permission prompt on every memory call, allow the Hivemind tools in .claude/settings.local.json (tool names are mcp__hivemind__<tool>), or use /permissions in the session. The client guide lists the recommended set.

3. Install the project instructions

Claude Code reads CLAUDE.md at startup. Put this block in the project's CLAUDE.md and replace the space name:

# Project memory — Hivemind MCP

Hivemind is the canonical shared memory across agents and sessions: MCP server
`hivemind`, space `<space-id>`. One space owns short, mid and long
memory. Local history or product memory is non-authoritative and never
bypasses this startup gate. Repository files remain the final authority.

## Start of every task

Before changing anything, call all three and read the results:
1. `space_rules(space_id="<space-id>")`
2. `mid_read_all(space_id="<space-id>")`
3. `short_read(space_id="<space-id>")`
If any call fails, times out or returns non-OK, stop before mutation.

## During work

Write concise atomic notes only for durable facts:
`short_note(space_id="<space-id>", category="<category>", content="...")`
Categories: observation, decision, progress, issue, todo, insight, question.
Agent identity comes from the credential; never pass or invent one. Record
every human decision and every blocking question as a note in the same turn.
Use `long_query` for historical context, then re-read the canonical source.
Never run `long_push` or change long bindings as routine work.

## End of a meaningful work block

Write one summary note, confirm with the user, then call
`mid_consolidate(space_id="<space-id>")` at most once and return
without polling. `bank_consolidation_status` is for an explicit status check.
Never edit memory bank files directly. Never put tokens or endpoints here.

The block is guidance to the model, not an access control: only the agent's grants limit what it can read or write. The reusable, vendor-neutral version of this contract, with the reasoning behind each rule, is in the agent memory setup guide.

Next

With both agents connected, run the tutorial. For the other assistants, see Connect an assistant.