:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
PostHog Admin console
The staff back office at /admin/console/.
It replaces custom Django admin views and templates for staff workflows.
The no-new-custom-admin-views semgrep rule blocks new ones, and the program ends when its findings reach zero.
The Django admin stays for plain CRUD on models.
Before you add or change a panel, operation or tool, invoke /extending-the-admin-console. It holds the judgment calls: where a change goes, copy, how to classify an operation, and the checks before done.
Invariants
- Every console route sits under
/admin/and is wrapped inadmin.site.admin_view.AdminOAuth2Middlewareadds the Google step-up for every/admin/path, andadmin_viewadds the staff check and CSRF protection. The console has no auth of its own, so a route outside that prefix or without that wrapper is unprotected. - Staff operations never go through DRF, MCP, or API keys. Keys and MCP tokens skip the admin step-up. An operation is a Python callable that a console view runs.
- A panel returns data, not markup. Subclass
Paneland returnFactandOperationobjects. Do not write templates,format_html, ormark_safefor a panel. The shell renders every panel the same way, so a new panel cannot drift from the design. - Only the shell writes templates (
posthog/templates/admin_console/). They use quill'squill-*classes and Tailwind utilities, with the markup quill's React components emit, including theirdata-*attributes. - A destructive operation sets
danger=True, has a form with areasonfield, and setsundo_hint.Operationrefuses it otherwise. The console writes the reason to the audit log and shows the undo hint on the confirm page. - An operation that only some staff may run sets
gate. UseGate.group(name)or aGatewith a reviewed rule. Never gate on a Django model permission:User.is_superusermirrorsis_staff, so every staff member passes. The console shows a gated operation disabled with who may run it, and refuses the request with 403. - The contract checks itself. The registry refuses a key that is not a slug, a blank title and a tool group outside
TOOL_GROUPS.Factrefuses markup, andPagerefuses unknown blocks and table rows of the wrong width. When a check fires, fix the contribution. Do not loosen the check in the same change.
Add a panel
- In
products/<product>/backend/console.py, subclassPaneland decorate it with@console.register_panel. Setrecordto a key fromRECORD_TYPESinrecords.py(team,organizationordeletion-request). Import only your product'sfacade/,posthog.admin.console, and, for a bridge, theModelAdminthat still holds the view.products/workflows/backend/console.pyis the reference. - Set
owner = Owner(name=..., crest=...). The crest is a mini crest slug from@posthog/brand, for exampleworkflows. - For each action, return an
Operation. Put its inputs in a Djangoforms.Form(form_class); the console renders and validates it. Itshandler(request, obj, form)returnsNonewhen done. The handler is a service function, orAdminViewBridge(Model, SomeAdmin.view_method)while the logic still lives in aModelAdmin. A bridged view must take a POST and answer with a redirect. Later, replace the bridge with a service function; the panel stays as it is. - Run
pnpm --filter=@posthog/frontend build:admin-consolewhen you add an owner crest or change a template.posthog/admin/test_admin_console.pyfails when a template class, a linked asset or an owner crest is missing from the build output.
Add a tool
A tool is a page that is not about one record, for example a report across all teams.
- In
products/<product>/backend/console.py, subclassConsoleTooland decorate it with@console.register_tool. Setkey,title,ownerandgroup; the group is the navigation heading.posthog/admin/console/events_retention_tool.pyis the reference. page(request)returns aPageof blocks (Notice,TablewithRowandGroupRow,Paging,Output,Live). It only reads; the console serves it for GET and HEAD only. The console renders the blocks, so a tool needs no template. When a tool needs a block that does not exist, add it totools.pyandtool.htmlin the shell, not a template in the product.- For an action that is not about one record, return a
ToolOperationfromoperations(request). It works like a recordOperationwithout the record:handler(request, form). Its handler returnsNone(back to the tool with its messages), or aPagethat the console shows as the result. Return a resultPageonly when running the operation again is harmless, such as a dry run, because a reload submits the form again.products/cohorts/backend/console.pyis the reference. - An operation that changes many records at once sets
preview. The console shows the previewPageand a confirm button, and the confirm runs exactly the previewed input from a signed token. The handler still re-checks the current state, because records can change between preview and confirm. The token is readable, so a form with a preview holds no secrets.posthog/admin/console/organization_tools.pyis the reference. - A block that should follow running work, such as the runs of a started job, is a
Liveblock. Return it fromlive(request, key)and embed the same call inpage. Keeprefresh_secondsset while something runs and None once nothing does, so the page stops asking.posthog/admin/console/health_checks_tool.pyis the reference. - When a tool replaces a Django admin page, keep the old path and point it at
MovedToConsole.page_redirect, so bookmarks keep working. Keep its URL name too when the name lives in the root URLconf, such asee/urls.py. A name in theadmin:namespace only exists inside aModelAdmin.get_urls, which the freeze rule flags, so drop it oncergfinds no caller that reverses it.
Move a Django admin action
Replace the old button with MovedToConsole.action(record, obj, panel_key, label) from moved.py. It links to the panel on the console record page, so staff who look in the usual place find the new one. When a whole page moves, route its old URL to MovedToConsole.page_redirect(title, url), which tells staff the page moved.
Old URLs never break, because staff keep bookmarks to them, query parameters included. When a record action's view is deleted, its old path goes into the MOVED_*_ACTIONS map of its record type in urls.py, which redirects to the console form or panel.
Read when needed
frontend/src/design.md: quill component choice and states. Read it before you change a template.packages/quill/packages/primitives/AGENTS.md: the markup and attributes of each quill primitive. Read it before you add a quill class to a template.