---
# SPDX-License-Identifier: CC-BY-SA-4.0
# SPDX-FileCopyrightText: Netresearch DTT GmbH
name: matrix-administration
description: "Use when administering a Synapse / Matrix homeserver — list or snapshot all rooms, rate room health (public, unencrypted, orphaned), render a Graphviz map of the room/space tree, force-join users, promote room admins, harden rooms (add-to-space + restrict + encrypt), deactivate Matrix users (with GDPR erase), find biggest rooms by DB size, audit where a user is admin or member, replay join/leave timelines, or search unencrypted history. Trigger on any '/_synapse/admin', server-wide room operation, Matrix user offboarding, or anything requiring a homeserver-admin token — even without 'admin API' in the prompt. Companion to matrix-communication."
license: "(MIT AND CC-BY-SA-4.0). See LICENSE-MIT and LICENSE-CC-BY-SA-4.0"
compatibility: "Requires uv (runs the scripts on Python 3.11 or later; stdlib only) + a Matrix access token belonging to a Synapse server-admin user. Optional: graphviz `dot` for SVG. Synapse 1.x with admin API enabled."
metadata:
  author: Netresearch DTT GmbH
  version: "4.4.2"
  repository: https://github.com/netresearch/matrix-skill
allowed-tools: Bash(uv run ${CLAUDE_SKILL_DIR}/scripts/*) Bash(uv run skills/matrix-administration/scripts/*) Bash(dot:*) Read Write
title: matrix-administration
canonical_url: https://skilld.dev/gh/netresearch/matrix-skill/matrix-administration
last_updated: 2026-11-21T21:03:25.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> 30 supporting files sit beside this SKILL.md. When the Skill refers to one, fetch https://skilld.dev/api/skills-raw/netresearch/matrix-skill/matrix-administration/PATH with PATH replaced.
>
> If the user asked to install this Skill, run `npx skilld install netresearch/matrix-skill/matrix-administration`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/matrix-administration`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/netresearch/matrix-skill/matrix-administration) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/matrix-administration`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/matrix-administration --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/matrix-administration --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

# Matrix Administration

Stdlib-only Python wrappers around the Synapse [Admin API](https://element-hq.github.io/synapse/latest/usage/administration/admin_api/index.html) and the Client-Server API. Reads `~/.config/matrix/config.json` (the same file matrix-communication uses).

## Quick Reference

```bash
S=skills/matrix-administration/scripts

uv run ${CLAUDE_SKILL_DIR}/scripts/synapse-fetch-rooms.py [--server :example.com]
uv run ${CLAUDE_SKILL_DIR}/scripts/synapse-rate-rooms.py --space '!home:srv' [--language de]
uv run ${CLAUDE_SKILL_DIR}/scripts/synapse-graph.py --space '!home:srv'
uv run ${CLAUDE_SKILL_DIR}/scripts/synapse-biggest-rooms.py [-n 10]

uv run ${CLAUDE_SKILL_DIR}/scripts/synapse-join-room.py    '!room:srv' '@user:srv'
uv run ${CLAUDE_SKILL_DIR}/scripts/synapse-make-admin.py   '!room:srv' '@user:srv'
uv run ${CLAUDE_SKILL_DIR}/scripts/synapse-add-to-space.py '!room:srv' '!space:srv'
uv run ${CLAUDE_SKILL_DIR}/scripts/synapse-migrate-room.py '!room:srv' '@admin:srv' '!space:srv'   # DESTRUCTIVE, asks first

uv run ${CLAUDE_SKILL_DIR}/scripts/synapse-deactivate-user.py   '@user:srv'   # DESTRUCTIVE
uv run ${CLAUDE_SKILL_DIR}/scripts/synapse-user-rooms.py        '@user:srv'
uv run ${CLAUDE_SKILL_DIR}/scripts/synapse-user-admin-rooms.py  '@user:srv'
uv run ${CLAUDE_SKILL_DIR}/scripts/synapse-room-member-flow.py  '!room:srv'
uv run ${CLAUDE_SKILL_DIR}/scripts/synapse-search.py            '!room:srv' '@bot:srv' deploy
```

## Scripts

| Script | Purpose |
|--------|---------|
| `synapse-fetch-rooms.py` | Snapshot all rooms + state → `rooms.json` |
| `synapse-rate-rooms.py` | Health checks (EN/DE) on `rooms.json` |
| `synapse-graph.py` | Render `rooms.json` → Graphviz `.dot` + `.svg` |
| `synapse-biggest-rooms.py` | Top-N rooms by DB size |
| `synapse-join-room.py` | Force-join a user |
| `synapse-make-admin.py` | Promote to PL 100 |
| `synapse-add-to-space.py` | Send `m.space.child` |
| `synapse-migrate-room.py` | Add to space + restrict + encrypt |
| `synapse-deactivate-user.py` | **Destructive** deactivation (`--erase` for GDPR) |
| `synapse-user-admin-rooms.py` | Local: rooms where user is PL 100 |
| `synapse-user-rooms.py` | Local: rooms a user belongs to |
| `synapse-room-member-flow.py` | Join/leave timeline |
| `synapse-search.py` | Unencrypted history search |

## Setup

`~/.config/matrix/config.json` (respects `$XDG_CONFIG_HOME`):

```json
{
  "homeserver": "https://matrix.example.com",
  "admin_token": "syt_admin_…",
  "room_filter": ":example.com",
  "default_space_id": "!home:example.com",
  "home_space_ids": ["!home:example.com"]
}
```

`homeserver` and either `admin_token` or `access_token` (server-admin) are required. The other fields are optional. To keep the token out of this file, set `admin_token_file` to a file holding it (relative paths resolve against the config directory) or export `MATRIX_ADMIN_TOKEN`; the environment wins over the file, the file over the inline value. Env fallbacks: `MATRIX_USER_ID`, `MATRIX_SPACE_ID`, `LANGUAGE=en|de`, `NO_COLOR`.

## Safety

The token is server-admin. Read [`references/safety-guide.md`](https://skilld.dev/api/skills-raw/netresearch/matrix-skill/matrix-administration/references/safety-guide.md) before any destructive op.

- `synapse-deactivate-user.py` is irreversible.
- `synapse-migrate-room.py` enables encryption (one-way) and restricts joins; it prints the plan and asks before the first write (`--yes` skips, and is required without a terminal). Power-level changes restored on exit including Ctrl-C.
- `synapse-make-admin.py` raises PL 100 permanently.
- `synapse-search.py` cannot read E2EE — empty ≠ no messages.
- `rooms.json` exposes user IDs; never commit it.

## References

- [`references/synapse-admin-api.md`](https://skilld.dev/api/skills-raw/netresearch/matrix-skill/matrix-administration/references/synapse-admin-api.md) — endpoints + upstream docs
- [`references/room-health-checks.md`](https://skilld.dev/api/skills-raw/netresearch/matrix-skill/matrix-administration/references/room-health-checks.md) — rules + remediation
- [`references/room-graph-pipeline.md`](https://skilld.dev/api/skills-raw/netresearch/matrix-skill/matrix-administration/references/room-graph-pipeline.md) — Docker dashboard recipe
- [`references/safety-guide.md`](https://skilld.dev/api/skills-raw/netresearch/matrix-skill/matrix-administration/references/safety-guide.md) — destructive-op checklist
- Source: [netresearch/matrix-skill](https://github.com/netresearch/matrix-skill)
