---
title: Headless bots
lastModified: '2026-12-01T09:21:41.000Z'
description: A headless bot runs with no person to paste a token, notice a silent failure or say "remember this".
---

A headless bot runs with no person to paste a token, notice a silent failure or say
"remember this". This guide covers the bot's identity, a connection check, the runtimes
(a coding agent driven through its SDK or its headless command line, or the bot's own
process), what the bot writes, and how to diagnose a bot that has gone quiet.

1. **Give the bot an identity**

    The `loom` CLI ships in the server image and installs from a clone with `pip install -e .`.
    The SDK package (`clickhouse-loom`) has no CLI.

    **With self-signup.** On a server with `LOOM_SELF_SIGNUP=open` the bot signs itself up:

    ```bash
    loom init --agent nightly-triage --server-url https://<loom> --purpose "Files the nightly failures."
    ```

    `loom init`:

    1. Creates the namespace `agent-nightly-triage` (`--purpose` becomes its description).
    2. Grants a service-account subject `writer` on it.
    3. Writes the token to `~/.loom/token` (mode 0600) and the URL, namespace and org to
       `~/.loom/config.json` (`--token-path` and `--config-path` move them).
    4. Prints a claim code and the claim page's address (`/oauth/agent-claim`). A person enters
       the code there once, with a password of their own, and from then on signs in with the
       namespace name and that password as its admin. The code never signs in, and a second claim
       with it is refused. The bot's token keeps working.

    `--ttl-days` sets the token lifetime (default 365). `--org` picks an org other than the
    server's self-signup org.

    **In CI**, use `--no-files` to print the token rather than save the CLI's configuration
    files, then store it as a secret. The token is the first output line. Create the
    capture file with mode `600` before redirecting output:

    ```bash
    install -m 600 /dev/null token.txt &&
      loom init --agent ci-reviewer --server-url https://<loom> --no-files | head -n 1 > token.txt
    ```

    With `--json` the sign-up result is printed as JSON without the token; with
    `--json --no-files` the token rides inside that JSON, the only place it lands.

    **Without self-signup**, an operator mints the token, or a person creates one under
    **Settings → Tokens** that reads only the bot's namespaces:

    ```bash
    loom mint-token --subject ci-reviewer --org <org> --namespaces agent-ci --roles writer \
      --service-account --ttl-days 30 --save
    ```

    See [tokens and grants](/docs/guides/tokens-and-grants) for roles, lifetimes and rotation.

2. **Check the connection before the first run**

    ```bash
    LOOM_BASE_URL=https://<loom> LOOM_API_KEY="$(cat token.txt)" loom doctor --client
    ```

    `loom doctor --client` resolves the server and the token the way the plugin hooks and the SDK
    do, and says where each came from. It probes `/v1/health` and `namespace.list_mine`, and
    checks that the token can write the bot's namespace. Each problem is a `FAIL` line naming the
    fix, and the exit code is non-zero, so the command works as a CI gate:

    ```yaml
    - run: loom doctor --client --server-url ${{ vars.LOOM_BASE_URL }} --token ${{ secrets.LOOM_API_KEY }}
    ```

    `--json` emits the checks and the problem list as JSON for a pipeline that parses them.

3. **Connect the runtime**

    ### Claude Agent SDK or `claude -p`

    The Agent SDK and `claude -p` start the same agent. A session loads Loom in one of three
    ways:

    | Route                                                    | The session gets                                                                     | Needs                                                                           |
    | -------------------------------------------------------- | ------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------- |
    | [The plugin, loaded by path](#the-plugin-loaded-by-path) | the MCP tools, the hooks (capture, primer, recall, code shunt, gates) and the skills | a clone of the Loom repository, Node.js 18 or newer, a session that is not bare |
    | [The MCP entry alone](#the-mcp-entry-alone)              | the tools and the server's startup instructions                                      | the instruction block in the project's `CLAUDE.md`                              |
    | [Bare mode](#bare-mode)                                  | the tools, mounted by flag                                                           | the instruction block appended to the system prompt                             |

    These sessions load no skill from an MCP server, so Loom's skills reach them only as
    files: the plugin's, or a skills folder in the project
    ([coding agents](/docs/features/integrations#coding-agents)).

    #### The plugin, loaded by path

    A session takes a plugin from a local directory, with no install step. Loom's is
    `integrations/claude-code-plugin` in a clone of the repository. Loaded this way it works
    as it does installed: its MCP entry connects to `LOOM_BASE_URL` on the `coding` toolset
    with the token in the header, its hooks run and its skills are listed
    ([Claude Code plugin](/docs/features/integrations/claude-code)).

    ```bash
    export LOOM_BASE_URL=https://<loom> LOOM_API_KEY="$(cat token.txt)"
    claude -p "Fix the failing retry test." \
      --plugin-dir /srv/loom/integrations/claude-code-plugin \
      --setting-sources project \
      --allowedTools "mcp__plugin_loom_loom__*" "Skill" \
      --output-format stream-json --verbose
    ```

    The same session from the Python Agent SDK:

    ```python
    import asyncio
    import os

    from claude_agent_sdk import ClaudeAgentOptions, SystemMessage, query

    PLUGIN = "/srv/loom/integrations/claude-code-plugin"


    async def main() -> None:
        options = ClaudeAgentOptions(
            cwd="/work/repo",
            plugins=[{"type": "local", "path": PLUGIN}],
            setting_sources=["project"],
            skills=["loom:loom-code", "loom:loom-memory", "loom:loom-mentor"],
            allowed_tools=["mcp__plugin_loom_loom__*"],
            env={
                "LOOM_BASE_URL": "https://<loom>",
                "LOOM_API_KEY": os.environ["LOOM_API_KEY"],
            },
        )
        async for message in query(prompt="Fix the failing retry test.", options=options):
            if isinstance(message, SystemMessage) and message.subtype == "init":
                plugins = [p["name"] for p in message.data.get("plugins", [])]
                down = [
                    s["name"]
                    for s in message.data.get("mcp_servers", [])
                    if s["status"] in ("failed", "needs-auth")
                ]
                if "loom" not in plugins or down:
                    raise RuntimeError(f"Loom did not load: plugins={plugins}, failed={down}")


    asyncio.run(main())
    ```

    And from the TypeScript Agent SDK, where `env` replaces the inherited environment:

    ```typescript
    import { query } from "@anthropic-ai/claude-agent-sdk";

    const plugin = "/srv/loom/integrations/claude-code-plugin";

    for await (const message of query({
      prompt: "Fix the failing retry test.",
      options: {
        cwd: "/work/repo",
        plugins: [{ type: "local", path: plugin }],
        settingSources: ["project"],
        skills: ["loom:loom-code", "loom:loom-memory", "loom:loom-mentor"],
        allowedTools: ["mcp__plugin_loom_loom__*"],
        env: { ...process.env, LOOM_BASE_URL: "https://<loom>" },
      },
    })) {
      if (message.type === "system" && message.subtype === "init") {
        const loaded = message.plugins.some((p) => p.name === "loom");
        const down = message.mcp_servers.filter(
          (s) => s.status === "failed" || s.status === "needs-auth",
        );
        if (!loaded || down.length > 0) {
          throw new Error(`Loom did not load: ${JSON.stringify(down)}`);
        }
      }
    }
    ```

    | Setting                       | Why                                                                                                                                                                                                                               |
    | ----------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
    | The plugin's path             | Absolute. The SDK does not expand `~` and skips a path that does not exist, so the check on `plugins` above is what catches a wrong one.                                                                                          |
    | `mcp__plugin_loom_loom__*`    | The plugin's server is `plugin:loom:loom`, so its tools are `mcp__plugin_loom_loom__<tool>`. Without the rule the agent sees the tools and cannot call them.                                                                      |
    | The Skill tool                | `Skill` in `--allowedTools`; in the SDK the `skills` option allows the skills it names. A harness that restricts the session's tool list keeps `Skill` and `ToolSearch` in it.                                                    |
    | The `project` setting source  | Loads the project's `CLAUDE.md`, which holds [the instruction block](/docs/features/integrations/claude-code#the-instruction-block). An empty list drops it; leaving the option out also loads the user's and the local settings. |
    | No `--bare`                   | A bare session runs no hook, a plugin's included ([bare mode](#bare-mode)).                                                                                                                                                       |
    | No `--strict-mcp-config`      | It drops the plugin's MCP entry (`strict_mcp_config` and `strictMcpConfig` in the SDKs); the hooks still run. A harness that needs it mounts [the MCP entry](#the-mcp-entry-alone) beside the plugin, as `mcp__loom__*`.          |
    | `--output-format stream-json` | The first message is the session's `system/init`. `claude -p` needs `--verbose` with it.                                                                                                                                          |

    > **Warning:** gate on the load. The `system/init` message lists `plugins`, `plugin_errors`
    > and `mcp_servers[]` with a `status` each. Trust the run only when `loom` is among the
    > plugins and `plugin:loom:loom` is `connected`, or `pending` while it still connects;
    > with `failed` or `needs-auth` the model ran without memory.

    **The token and the server.** The plugin's MCP entry takes the server from `LOOM_BASE_URL`
    in the environment the session starts in, else `http://localhost:7777`; it never reads
    `~/.loom/config.json`. So export `LOOM_BASE_URL` in every run, or set the plugin's
    `server_url` option (below): a bot that has only the files `loom init` wrote runs its
    hooks against the server saved there and sends its token to localhost from the tools. The
    hooks read the token from `LOOM_API_KEY`, then `~/.loom/config.json`, then
    `~/.loom/token`; the header helper, which authenticates the tools, reads only the two
    files. So the token comes from `loom init` (section 1), run as the user the session runs
    as, which writes both files, or from `LOOM_API_KEY`: the session's first hook then saves
    the token and the URL to `~/.loom/config.json`, with mode 0600, for the header helper. A
    saved token is never replaced, so a runner that keeps
    its home directory between bots keeps sending the first bot's token from the tools
    ([the MCP entry and its header helper](/docs/features/integrations/claude-code#the-mcp-entry-and-its-header-helper)).

    **The plugin's options.** A path-loaded plugin has no install dialog, so its options take
    their defaults. To set one, such as the
    [mode](/docs/features/integrations/claude-code#modes), pass `pluginConfigs` under the
    plugin's ID, `loom@inline`, in `--settings` (`settings` in the SDKs):

    ```json
    { "pluginConfigs": { "loom@inline": { "options": { "mode": "code" } } } }
    ```

    The MCP entry's listing and the hooks both follow it. `LOOM_MODE` alone moves the hooks
    and leaves the listing on `both`.

    **Stop gates.** Two of the plugin's Stop hooks can hold the end of a session once: the
    validate gate, on findings about the memory keys the session wrote; and the
    namespace-health line. A held stop is one more model turn. A harness that caps the
    session's turns sets `LOOM_VALIDATE_GATE=off` and `LOOM_NAMESPACE_HEALTH=off` in the
    session's environment. The test gate holds no stop unless the install turns it on
    (`stop_test_gate`, or `LOOM_TEST_GATE=stop`): then it holds a session that changed code
    and ran no test since. Mode `memory` runs no test gate, and mode `code` runs no gate at
    a Stop without it
    ([what the hooks do](/docs/features/integrations/claude-code#what-the-hooks-do)).

    **The session's end.** The plugin's SessionEnd hook hands the session's close (the run's
    close, the last turns, session memory, the brief) to a detached process and returns, so
    the client does not wait for it and cannot cancel it. A harness that removes the machine
    or container the moment the client exits ends that process too. Set
    `LOOM_SESSION_END_WAIT=true` in such a session's environment: the hook then sends the
    close itself and returns when the run's close is answered, inside the 1.5 s the client
    gives the event (`CLAUDE_CODE_SESSIONEND_HOOKS_TIMEOUT_MS` raises that for a slow
    server). Session memory and the brief leave through flushers that run beside it, and
    the last turns through one started just before the hook returns; to keep those too,
    wait until the session's `$TMPDIR` holds no `loom-flush-*.json` file before tearing the
    host down.

    #### The MCP entry alone

    Mount Loom as an MCP server from a file and allow only its tools. A headless run has no
    interactive OAuth, so the bearer rides the header:

    ```bash
    cat > loom.mcp.json <<EOF
    {"mcpServers": {"loom": {"type": "http",
      "url": "https://<loom>/mcp?toolset=coding",
      "headers": {"Authorization": "Bearer $LOOM_API_KEY"}}}}
    EOF
    claude -p --mcp-config loom.mcp.json --strict-mcp-config \
      --allowedTools "mcp__loom__*" \
      --output-format stream-json --verbose \
      "Triage the failures in the last nightly run; record each root cause you find."
    ```

    | Flag                            | Why                                                                                                  |
    | ------------------------------- | ---------------------------------------------------------------------------------------------------- |
    | `--strict-mcp-config`           | Keeps the bot on the servers the file names, not the user's config.                                  |
    | `--allowedTools "mcp__loom__*"` | Pre-approves every Loom tool, so no permission prompt blocks the run.                                |
    | `--output-format stream-json`   | The first message is the session's `system/init` (see below). `claude -p` needs `--verbose` with it. |

    In the SDKs the same entry is the `loom` key of `mcp_servers` (Python) or `mcpServers`
    (TypeScript), with `mcp__loom__*` in `allowed_tools` or `allowedTools`.

    > **Warning:** gate on the connection. The `system/init` message lists `mcp_servers[]` with a
    > `status` each. Trust the run only when `loom` is `connected`; otherwise the model ran
    > without memory.

    Pick the tool listing with `?toolset=`; the toolsets are listed in
    [MCP toolsets](/docs/reference/mcp#toolsets).

    This route has no hooks and no skills. What makes the agent call the tools is the
    [agent instructions](/docs/features/integrations/agent-instructions) block in the
    project's `CLAUDE.md`, read while the `project` setting source is on.

    If the Loom plugin is installed for the user running `claude -p`, its hooks run too
    ([Claude Code plugin](/docs/features/integrations/claude-code)). Its mentor hints follow only
    the plugin's own server's tools (`mcp__plugin_loom_loom__*`), not a `loom` entry from
    `--mcp-config`.

    #### Bare mode

    `claude --bare` skips the user's hooks, plugins, skills, MCP servers and `CLAUDE.md`. A
    plugin passed with `--plugin-dir` still loads, but its hooks do not run, its MCP entry
    does not connect and the session is not told which skills exist. What is left is what
    flags carry: the MCP entry, and the instruction block appended to the system prompt.

    ```bash
    claude --bare -p "Triage the failures in the last nightly run." \
      --mcp-config loom.mcp.json --strict-mcp-config \
      --append-system-prompt-file loom-instructions.md \
      --allowedTools "mcp__loom__*" \
      --output-format stream-json --verbose
    ```

    `loom-instructions.md` holds the
    [agent instructions](/docs/features/integrations/agent-instructions#the-block) block with
    its namespaces filled in. Bare mode reads no stored login, so the model's own API key
    comes from the environment. An SDK session with an empty setting-sources list loses
    `CLAUDE.md` the same way: pass the block as the `append` of the `claude_code` system
    prompt preset. Nothing captures a bare session, so the bot writes what should outlive it
    (section 4), and the [grep shim](/docs/features/integrations/grep-shim) stands in for the
    code shunt.

    ### Codex `codex exec`

    ```bash
    export LOOM_API_KEY="$(cat token.txt)"
    codex exec --json \
      -c 'mcp_servers.loom.url="https://<loom>/mcp?toolset=coding"' \
      -c 'mcp_servers.loom.bearer_token_env_var="LOOM_API_KEY"' \
      "Summarise what we decided about retries; record any decision that is missing."
    ```

    Codex reads the bearer from the variable the entry names, in the environment `codex`
    starts from. With the Codex plugin installed its hooks run here too
    ([Codex plugin](/docs/features/integrations/codex)).

    ### Kiro CLI

    `kiro-cli chat --no-interactive` is Kiro's headless mode. Loom reaches it through three
    files in the project, or their user-level copies under `~/.kiro/`: the MCP entry, a
    steering file and the skills. Loom ships no hooks for Kiro, so nothing captures the
    session, primes it or redirects a grep; the steering file's two calls stand in for the
    primer, and section 4 covers what the bot writes.

    1. **The MCP entry**, in `.kiro/settings/mcp.json`:

       ```json
       {
         "mcpServers": {
           "loom": {
             "url": "https://<loom>/mcp?toolset=coding",
             "headers": { "Authorization": "Bearer ${LOOM_API_KEY}" }
           }
         }
       }
       ```

       Kiro CLI expands `${LOOM_API_KEY}` from the environment it starts in.
       `loom install --client kiro --toolset coding` writes the entry, with the token itself,
       to the user-level `~/.kiro/settings/mcp.json`
       ([MCP clients](/docs/features/integrations/mcp-clients#what-it-writes-per-client)).

    2. **The steering file**, `.kiro/steering/loom.md`: the
       [agent instructions](/docs/features/integrations/agent-instructions#where-each-client-reads-it)
       block. Kiro includes a steering file in every interaction unless its front matter says
       otherwise.

    3. **The skills**, copied from a clone of the Loom repository:

       ```bash
       mkdir -p .kiro/skills
       cp -R /srv/loom/skills/loom /srv/loom/skills/loom-code .kiro/skills/
       ```

       `skills/loom` and `skills/loom-code` fit Kiro's skill rules: each name matches its
       folder, each description is under 1,024 characters, and the front matter holds only
       `name`, `description`, `license` and `metadata`. The skills under
       `integrations/claude-code-plugin/skills/` are written for a session that has the
       plugin's hooks; leave them out.

    Then run the bot:

    ```bash
    export LOOM_API_KEY="$(cat token.txt)"
    kiro-cli chat --v3 --no-interactive --require-mcp-startup --trust-tools=@loom \
      "Summarise what we decided about retries; record any decision that is missing."
    ```

    | Flag                    | Why                                                                                                                                          |
    | ----------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
    | `--v3`                  | Names the agent harness, so the run does not depend on the headless default.                                                                 |
    | `--require-mcp-startup` | Waits for the MCP servers and exits with code 3 when one does not start. Without it Kiro logs the problem and the model runs without memory. |
    | `--trust-tools=@loom`   | Pre-approves the `loom` server's tools (Kiro CLI 3.3.0 or newer); a headless run denies a tool call that needs approval.                     |

    A custom agent (`--agent <name>`) loads none of the three on its own. Its configuration
    needs `"includeMcpJson": true`, and `file://.kiro/steering/**/*.md` and
    `skill://.kiro/skills/*/SKILL.md` in `resources`.

    A client that drives Kiro over the Agent Client Protocol (`kiro-cli acp`) sends Loom's
    server in `mcpServers` on `session/new`, and again on `session/load`: the session does not
    keep the servers a client supplies.

    This recipe follows Kiro's documentation. What was run against a client is in the Checked
    column of
    [other editors and agents](/docs/features/integrations/mcp-clients#other-editors-and-agents).

    ### The SDK, in the bot's own process

    For a bot that is code rather than a coding agent, skip MCP and call the operations:

    ```python
    from loom import Agent

    async with Agent(org="acme", namespace="agent-nightly-triage", agent="nightly-triage") as a:
        hits = await a.memory.search("flaky tests in the ingest suite", top_k=5)
        await a.memory.set(
            "flaky/ingest_retry_test",
            "Times out against the S3 mock.",
            tags=["failure", "ingest"],
        )
        ans = await a.memory.ask("which suites flaked this week?")
    ```

    `Agent` reads the server from `base_url=` or `LOOM_BASE_URL`, and the token from
    `api_key=`, `LOOM_API_KEY`, then `~/.loom/token`. Other entry points:

    - `agent.tools()` hands a model Loom's verbs (`loom_remember`, `loom_recall`, `loom_ask`,
      `loom_offload`, `loom_fetch`, `loom_note`) as tool definitions with one `execute()`.
    - `agent.session(id)` is the unit an agent framework holds: resume, append, flush, close.
    - A LangGraph graph passes `LoomStore` (`loom.integrations.langgraph`) to
      `compile(store=...)`; a Strands agent uses `LoomMemoryStore` (`loom.integrations.strands`).
    - [`examples/claude_agent_loop.py`](https://github.com/ClickHouse/loom/blob/main/examples/claude_agent_loop.py) is a minimal loop
      with the Anthropic SDK (needs `ANTHROPIC_API_KEY`).

    See the [Python SDK reference](/docs/reference/python-sdk) and
    [framework integrations](/docs/features/integrations/frameworks).

4. **Decide what the bot writes**

    The plugins capture a coding session on their own. A bot outside them decides what to write.
    In short: record decisions and failures, not transcripts; recall once before a task, not once
    per step; hand a finished run's transcript to `memory.set_from_messages`; and report what the
    run relied on with `run.complete(memories_used=[...])`.
    [Agent integration](/docs/guides/agent-integration#3-decide-what-to-write) covers each choice.

5. **When the bot is quiet**

    Run `loom doctor --client` on the bot's machine. It reports each of the usual causes on its
    own line:

    | Symptom                               | Cause                                                                                               |
    | ------------------------------------- | --------------------------------------------------------------------------------------------------- |
    | Reads and writes go to another server | `LOOM_BASE_URL` disagrees with `~/.loom/config.json`                                                |
    | 401 on every call                     | The token expired or was rotated                                                                    |
    | 403 on every write                    | The token is a `viewer` on the namespace the bot writes to                                          |
    | Captures never appear                 | Nothing sent them: stranded `loom-flush-*.json` or `loom-record-*.json` files in the temp directory |

## Related

- [Tokens and grants](/docs/guides/tokens-and-grants)
- [Agent integration](/docs/guides/agent-integration)
- [MCP clients](/docs/features/integrations/mcp-clients)
- [Debugging a request](/docs/guides/debugging)
