Models tenants, memberships, contacts and support sessions in PermDock. Use when declaring named scopes (organizations, workspaces, customers inside an organization), loading memberships through a MembershipSource, putting a role on one scope, keeping an owner per organization with min, max or transferOnly, controlling who hands out which role with assigns and for, checking a membership change with decideRoleChange, letting tenant admins define custom roles with customRoles and validateCustomRole, giving external customer contacts portal access as kind contact principals found through a PrincipalSource and principalByIdentity, letting support staff view the app as a customer with decideSupportSession, signSupportSession and subjectFromSupportSession, or fixing doctor PD023, PD025 or PD026 and denials such as tenant-mismatch, last-holder, not-assignable-by or reason-required.
Ships in PermDock. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
A policy declares its scopes in order (an organization, the customers inside it). A role is held at one scope, a membership names one instance of that scope, and a grant reaches a row only through that scope's key. Roles never cascade between scopes (named scopes, tenancy). Set up the policy and factory first with the permdock-wire skill (npx skills add ScaleDockHQ/PermDock --skill permdock-wire).
organization_id, customer_id).subjectFrom* provider, or the app's tables.via): staff, contact, guest, partner, support.subjectFrom* provider, the policy's subject or context function, a MembershipSource or a CustomRoleSource. Never from a request body, an unsigned header, a model argument or a CLI flag.permdock.team(id). A collection check (create, list) still answers from any membership in the tenant; for a staff-only guard pass { scope: '<first scope>' } as the decide option.min, assigns, for), not in handlers. decideRoleChange takes the actor from the instance and never writes.assignable roles in its scope. Its grants carry no condition, approval or limit of their own; a level picks a condition the resource declares in code.kind: 'contact' principal keeps only its { on } resource memberships and is read-only unless a role's for lists 'contact'; a scope role such as the customer-scope contact role below never reaches it. It never approves or creates keys. An email address or chat author with no identity link the app wrote is no principal, never a guest.support actor, needs a reason and, by default, an approval by someone else, and is checked live on every request. A support actor never approves.Declare the scopes. Add them to definePolicy in order, each with its row key and, after the first, within:
definePolicy(
{ permissions, roles },
{
scopes: {
organization: { key: "organization_id" },
customer: { key: "customer_id", within: "organization" },
},
roles: [
role(roles.admin, adminGrants, { on: "organization" }),
role(roles.contact, contactGrants, { on: "customer" }),
],
subject,
},
);
✓ definePolicy accepts the scopes, and each role names one scope with on.
Give resources their scope keys. Every resource a scoped grant touches declares a memberOf relation per scope key it carries, for example relations: { organization: { field: 'organization_id', memberOf: 'organization' } }.
✓ definePolicy does not throw for a missing memberOf relation.
Load memberships. Return memberships as { scope, id, within, roles, via, expiresAt } from the subject resolver, or pass a MembershipSource (one, or an array) as memberships on createPermDock. A person's access ending is the membership's expiresAt.
✓ permdock doctor reports no PD025 for the doctor.memberships fixture.
An organisation role that reaches only the principal's teams is an organisation role with where: { team_id: { in: claim("team_ids") } } (claim from permdock is principal.claims.team_ids, typed under noUncheckedIndexedAccess), not a team role. On Supabase, write the claim with supabase.hook.claims (team reach).
Put ownership on the roles. Set min: 1 on the role that manages each scope, assigns for who hands out what, for: ['staff'] on admin-like roles, and meta.audience for the surface. Every server action that changes a membership calls decideRoleChange(permdock, ...) with the target's current membership and the holder count before it writes. -> references/ownership-and-custom-roles.md
✓ PD026 is clean, and removing the last owner is denied with last-holder.
Custom roles, when tenant admins define roles. Keep declared roles small and mark them in defineRoles (editor: { on: 'organization', assignable: true }). Pass a CustomRoleSource as customRoles, build the editor from useAssignablePermissions(), and save through a server action that runs validateCustomRole. -> references/ownership-and-custom-roles.md
✓ PD023 is clean, and saving a role with a permission outside the ceiling is refused.
Contact principals, when external people sign in or receive messages. Pick the model: a signed-in user with a via: 'contact' membership on the customer scope, or a kind: 'contact' principal with { on: { resource, id }, roles } memberships on the rows it is a party to. Give a contact a write only through a resource role with for: ['contact']. Pass a PrincipalSource as principals (memoryPrincipalSource({ principals, identities }) in tests, principalSource from permdock/better-supabase there) and implement principalByIdentity over identity links the app writes after a signed-in link flow or a verified address, so delivery and chat reach the contact (contact principals). -> references/contacts-and-support-sessions.md
✓ A contact's write without a for: ['contact'] role denies with not-delegated, and an unlinked address resolves to null.
Support sessions, when staff view the app as a customer. Start each session with decideSupportSession(staff, { id, principal, reason }), record an approval by someone else and decide again with { approved: token, approvedBy }. Sign the granted record with signSupportSession(session, signer) and resolve each request with subjectFromSupportSession(token, { verifier, principals, permissions, sessions }) from permdock/server, where sessions is a SupportSessionSource that ends a session early. Send supportSessionEvent to the sink on start and end. On better-supabase, pass supportPolicy as the authorize option of supportSessions (support sessions). -> references/contacts-and-support-sessions.md
✓ An empty reason denies with reason-required, and a token for a session the source reports ended resolves to the anonymous subject.
Test. Add describePolicy rows for a member of another tenant, a contact reaching an organization row, a contact principal writing without an opt-in role, and a role change that breaks min (scenario testing). Run testMembershipSource, testCustomRoleSource, testPrincipalSource and testSupportSessionSource from permdock/testing on custom sources. For list queries and RLS over scoped tables, follow the permdock-data skill.
✓ The tests pass.
user_metadata.min: 1 (PD026), and admin-like roles set for so contact, guest or partner memberships cannot hold them.assigns list lets a role appoint a role ranked above it.decideRoleChange with a holders count from the store, never a guess.validateCustomRole and checks assignablePermissions(). No single assignable admin role makes the ceiling the whole product.MembershipSource, CustomRoleSource, PrincipalSource and SupportSessionSource implementations pass testMembershipSource / testCustomRoleSource / testPrincipalSource / testSupportSessionSource.kind: 'contact' principal gets portal access only through { on } memberships, and every write it may make comes from a role whose for lists 'contact'. When contacts query the database directly, their memberships are kept out of the tables the RLS functions read, or writes are gated in the application.principalByIdentity reads only identity links the app wrote after a signed-in link flow or a verified address. No code creates a principal, a guest or a default role for an unlinked address or chat author.decideSupportSession with a reason, and approval stays on unless the app approves elsewhere; approvedBy is never the staff member.subjectFromSupportSession and a SupportSessionSource, never by signing in as the customer, and supportSessionEvent is sent on start and end.decideRoleChange input and denial reasons, the SQL objects RLS uses, and the custom-role shape, ceiling and editor.PrincipalSource and identity links for delivery and chat, the support-session start, token, live check and events, supportPolicy, and how support sessions differ from supportAccess.What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
/permdock:permdock-tenancyfrom PermDock
npx claudepluginhub scaledockhq/permdock --plugin permdock8 skills in this plugin
/permdockExplains how PermDock decides and routes to the right PermDock skill. Use first for any work with permdock, typed permissions, roles or access control in a TypeScript app, when a check is denied and the reason is unclear, when reading a Decision, denial reason or doctor code, when looking up current PermDock identifiers through the docs MCP, or when choosing between the permdock-wire, permdock-audit, permdock-agents, permdock-approvals, permdock-tenancy, permdock-data and permdock-credentials skills./permdock-agentsGuards AI agent tool calls, automations and chat commands with PermDock operations, subjects, actors and delegation. Use when declaring defineOperations, wiring operations in permdock/agent, permdock/ai-sdk, permdock/claude-agent, permdock/openai, permdock/eve or permdock/mcp, gating models or filtering tool results, running published automations with permdock/workflow or permdock/workflow-sdk, protecting chat commands and approval buttons with permdock/chat or permdock/chat-sdk, separating the user (principal) from the agent (actor), declaring a delegation option or policy delegations, publishing an A2A Agent Card with permdock/a2a, registering WebMCP tools with permdock/webmcp, verifying Web Bot Auth signers as actors, or when agent calls are denied with no-delegation or not-delegated./permdock-approvalsRequires human approval on PermDock grants, notifies approvers and resumes the approved call. Use when adding approval to a destructive or money-moving action (delete, publish, pay, refund, transfer), choosing approvers with approval by, user(), relation(), manager(), mode confirm or authorize, quorum, ttl, escalation, staleOn or approvalFingerprint, ordering approvers with combine and stages, covering an approver with an ApprovalDelegation, loading approval rules as data with an ApprovalPolicySource, separating preparer and approver with exclusiveWith, labelling operations with risk and effects meta, mounting approvalsHandler with an ApprovalStore, sending approval emails (approvalEmail) or chat cards (approvalCard, approvalActions) from approvalPrompt, parking a background run on an ApprovalWaiter (pollingApprovalWaiter, workflowSdkWaiter), resuming with the PermDock-Approval header, mapping approval-required to an agent runtime, MCP elicitation or AG-UI interrupt, or fixing doctor PD017, PD018 or PD024./permdock-auditReviews an existing PermDock setup or a pull request that changes it. Use when auditing permissions, reviewing a PR that touches permissions.ts, policy.ts or an adapter guard, finding ungranted or unused leaves, missing human approvals on agent tools, closures that should be portable, validate never, untested grants, or mapping an app to OWASP ASI02 and ASI03. Use whenever the user asks to audit, review or harden PermDock./permdock-credentialsResolves PermDock subjects from access tokens, API keys and share links. Use when verifying OAuth or OIDC access tokens with subjectFromJwt or an introspection response with subjectFromIntrospection, issuing personal access tokens, API keys, service accounts or feed keys with decideCredential and resolving them with subjectFromApiKey, setting tenant key rules (maxTtl, kinds, allowNoExpiry) in a SettingsSource, minting guest or share links with signCapability and resolving them with subjectFromCapability, serving a link through RLS with exchangeCapability, or fixing doctor PD029 and on('auth') causes such as invalid-chain./permdock-dataEnforces PermDock permissions in database queries and Postgres row-level security. Use when listing rows with permdock.where() and filter(), compiling conditions with toWhere from permdock/drizzle, permdock/prisma or permdock/kysely, guarding Convex functions with permdock/convex, generating or verifying RLS with permdock rls generate, verify or migrate, modelling folders, sub-teams or reporting lines with parent and relation() through a RelationSource, prefetchRelations or whoCan, or proving query and database parity with testOrmParity and testRlsParity. Also for doctor PD027, PD028, PD031 and PD032.