multi-tenancy

multi-tenancy is a skill for Claude Code from camilooscargbaptista/cto-toolkit. It costs 22 tokens per session (1,057 once invoked), scanned A, original, MIT.

A guide to multi-tenant software, where one application serves several separate organizations or customers. It covers ways to keep each customer's data isolated using shared rows, separate database schemas, or separate databases.

In plain words
What is it for?
Use it when designing SaaS systems, tenant routing, database structure, access controls, and repositories that must only return one organization's data.
Why use it?
It helps teams choose how to separate customer data while balancing safety, cost, and maintenance effort.

Skill for Claude Code

Written for Claude Code: shipped in a Claude Code plugin.

Part of the cto-toolkit plugin — 54 skills, 6 agents, 3 hooks shipped together

Good fit Use it when designing SaaS systems, tenant routing, database structure, access controls, and repositories that must only return one organization's data.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/camilooscargbaptista/cto-toolkit/multi-tenancy
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add camilooscargbaptista/cto-toolkit --skill multi-tenancy
Clone the repo
git clone --depth 1 https://github.com/camilooscargbaptista/cto-toolkit

Made for: Claude Code.

Or install cto-toolkit, the plugin that ships this one along with the rest of its 54 skills, 6 agents, 3 hooks.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for multi-tenancy

README.md
[![agentmods](https://agentmods.dev/badge/skills/camilooscargbaptista/cto-toolkit/multi-tenancy.svg)](https://agentmods.dev/skills/camilooscargbaptista/cto-toolkit/multi-tenancy)
Your own site
<a href="https://agentmods.dev/skills/camilooscargbaptista/cto-toolkit/multi-tenancy"><img src="https://agentmods.dev/badge/skills/camilooscargbaptista/cto-toolkit/multi-tenancy.svg" alt="Measured on agentmods" height="20"></a>
Per session 22 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,057 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00022 $0.01057
Opus 5 $0.00011 $0.00528
Sonnet 5 $0.00004 $0.00211
Haiku 4.5 $0.00002 $0.00106

Measured 7d ago against content hash 373fdbe2e16a, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-07, from the pricing page.

Security

Grade A, and why

multi-tenancy scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 7d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

multi-tenancy/SKILL.md · 145 lines

How it starts

The opening of the file, as written. The whole thing — 145 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Multi-Tenancy Patterns

When to Use

  • Building SaaS that serves multiple organizations/clients
  • Designing data isolation between tenants (companies, stations, fleets)
  • Choosing the right isolation level for your compliance needs

Isolation Models

1. Row-Level (Shared Everything)

┌──────────────────────────────┐
│         Single Database       │
│  ┌────────────────────────┐  │
│  │     users table         │  │
│  │  tenant_id │ name       │  │
│  │  ──────────┼──────────  │  │
│  │  company_a │ Alice      │  │
│  │  company_b │ Bob        │  │
│  └────────────────────────┘  │
└──────────────────────────────┘

Pros: Simple, cheap, easy to maintain
Cons: Risk of data leakage, shared resources
Best for: Small/medium SaaS, cost-sensitive

Implementation — TypeORM Global Scope:

// Middleware injects tenant
@Injectable()
export class TenantMiddleware implements NestMiddleware {
  use(req: AuthRequest, res: Response, next: NextFunction) {
    req.tenantId = req.user?.companyId;
    next();
  }
}

// Repository automatically filters by tenant
@Injectable()
export class TenantAwareRepository<T> {
  constructor(private repo: Repository<T>) {}

  findAll(tenantId: string): Promise<T[]> {
    return this.repo.find({ where: { tenant_id: tenantId } as any });
  }

  // CRITICAL: NEVER allow findAll without tenantId
}

// Global subscriber (safety net)
@EventSubscriber()
export class TenantSubscriber implements EntitySubscriberInterface {
  afterLoad(entity: any) {
    // Verify tenant match on every load (paranoia mode)
  }
  
  beforeInsert(event: InsertEvent<any>) {
    // Auto-inject tenant_id
    if (event.entity && !event.entity.tenant_id) {
      event.entity.tenant_id = getCurrentTenantId();
    }
  }
}

2. Schema-Level (Shared Database, Separate Schemas)

┌──────────────────────────────┐
│         Single Database       │
│  ┌──────────┐ ┌──────────┐  │
│  │ schema_a  │ │ schema_b  │  │
│  │  users    │ │  users    │  │
│  │  orders   │ │  orders   │  │
│  └──────────┘ └──────────┘  │
└──────────────────────────────┘

Pros: Good isolation, shared infra cost
Cons: Schema migration complexity, connection pooling
Best for: Medium SaaS, regulated industries

Read the full file on GitHub · 145 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 7d ago First seen · 145 lines · 22 tokens per session scan A 373fdbe2e16a

Subscribe to this mod's changes

multi-tenancy is a skill published in the GitHub repository camilooscargbaptista/cto-toolkit (7 stars, last pushed 5mo ago), licensed MIT. It adds 22 tokens to every session and 1,057 once invoked, about $0.0001 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.

Related

Other skills, from other repositories

architecture-paradigm-cqrs-es

Applies CQRS and Event Sourcing for read/write separation and audit trails. Use when designing systems with complex domain logic or full state-change history.

athola/claude-night-market · 39 tokens

backend-event-sourcing

Use this skill when the user says 'event sourcing', 'event store', 'event stream', 'event sourced', 'rehydrate from events', 'event replay', 'projection rebuild', 'event log', 'append-only log', 'event history'. This skill enforces: events as the single source of truth, current state derived from event replay…

j4flmao/agent-skills · 118 tokens

backend-multi-tenancy

Use this skill when the user says 'multi-tenancy', 'SaaS', 'tenant isolation', 'row-level security', 'DB per tenant', 'schema per tenant', 'tenant provisioning', 'tenant migration', 'multi-tenant database', 'tenant context'. This skill implements tenant isolation strategies: row-level, schema-per-tenant, and…

j4flmao/agent-skills · 113 tokens

backend-cqrs-patterns

Use this skill when the user says 'CQRS', 'command query segregation', 'separate read write model', 'command model', 'query model', 'read model', 'write model', 'materialized view', 'command handler', 'query handler'. This skill enforces: strict command/query separation, write model optimized for consistency, read…

j4flmao/agent-skills · 125 tokens

migration-evolution

Use when thinking through, reviewing, changing, or verifying data and contract evolution: schema migrations, expand-and-contract, resumable backfills, API or event compatibility, synchronization, CDC, reindexing, traffic cutover, or legacy integration. For outbox and inbox delivery use async-messaging; for transaction…

d4rkNinja/arcforge · 81 tokens

transactions-consistency

Use when thinking through, reviewing, changing, or verifying transactional or concurrent behavior: isolation, anomalies, locking, state machines, idempotency, sagas, consistency, replication, sharding, consensus, distributed locks, fencing, or ordering. For jobs, queues, and outbox delivery use async-messaging; for…

d4rkNinja/arcforge · 77 tokens