Skip to content

: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.

chore(frontend): add agent guide for frontend/src (#66056)

Julian Bez5fe3746b3e13
diff --git a/AGENTS.md b/AGENTS.md
index ae884aa8e27d..f35e25a96e35 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -121,6 +121,7 @@ See [.agents/security.md](.agents/security.md) for SQL, HogQL, and semgrep secur
- Python: Write as if mypy `--strict` is enabled — annotate all function signatures (arguments + return types), avoid `Any`, use `TYPE_CHECKING` imports for type-only references. Do not run mypy locally (too slow); CI runs it on every PR. The config isn't fully strict yet, but new code should be
- Python imports: keep imports at module level — not inside functions, methods, or conditionals. Inline imports hide dependencies from static analysis, slow hot paths with repeated lookups, and mask circular-import problems instead of fixing them; ruff's `PLC0415` enforces this. Defer an import only to (1) break a true unavoidable circular import (fix the structure first if you can), (2) reference types under `TYPE_CHECKING`, or (3) keep a heavy/optional dependency off the import path so it loads only when its code runs. For (3), add a justified `# noqa: PLC0415` on the import line (e.g. `# noqa: PLC0415 — keeps the heavy dep off the import path`) — never blanket-suppress the rule
+- Frontend: for any frontend work — the main app (`frontend/src/`) **or** a product frontend (`products/*/frontend/`) — follow [frontend/src/AGENTS.md](frontend/src/AGENTS.md): reuse existing Lemon/quill components instead of hand-rolling tables/badges/labels, import generated `*Api` types instead of handwriting them, and run typecheck/typegen at the right moments. Product frontends share the same components and generated types, so the same rules apply there
- Frontend: TypeScript required, explicit return types
- Frontend: If there is a kea logic file, write all business logic there, avoid React hooks at all costs.
- Frontend (quill design system): before writing UI that imports `@posthog/quill` / `lib/ui/quill`, read [packages/quill/packages/primitives/AGENTS.md](packages/quill/packages/primitives/AGENTS.md) — component choice (dropdown vs select vs combobox, accordion vs collapsible, etc.), composition, and spacing rules. Charts: [packages/quill/packages/charts/AGENTS.md](packages/quill/packages/charts/AGENTS.md); DataTable/DateTimePicker: [packages/quill/packages/components/AGENTS.md](packages/quill/packages/components/AGENTS.md)
diff --git a/frontend/src/AGENTS.md b/frontend/src/AGENTS.md
new file mode 100644
index 000000000000..8e2d9665e375
--- /dev/null
+++ b/frontend/src/AGENTS.md
@@ -0,0 +1,64 @@
+# Frontend agent guide (`frontend/src`)
+
+Applies to any change under `frontend/src`. This is a **discovery + cadence** guide: the rules below exist because agents tend to generate before they look. The root `AGENTS.md` and the quill package guides remain authoritative — this file does not repeat them, it points at them.
+
+## Rule 1 — Reuse before you create
+
+**Before building any UI element, search for an existing one.** PostHog already has a badge, a label, a table, a tag, a card, a modal. Hand-rolling one with raw `<div>`/`<table>` + Tailwind is the single most common agent mistake here, and it produces unbounded, off-design output.
+
+Where to look, in order:
+
+1. `frontend/src/lib/lemon-ui/` — the main-app default (~50 `Lemon*` components). Grep here first.
+2. `@posthog/quill` (`packages/quill/`) — preferred for menus, comboboxes, autocompletes, and new charts. Read `packages/quill/packages/primitives/AGENTS.md` for component choice **before** importing.
+3. `frontend/src/lib/ui/` and `frontend/src/lib/components/` — older / app-specific shared pieces.
+
+Common reinventions and what to use instead:
+
+| You're about to build… | Use instead |
+| ------------------------------------ | ----------------------------------------------------------------------------------------- |
+| a `<table>` | `LemonTable` (`lib/lemon-ui/LemonTable`) — has sorting, pagination, loading, empty states |
+| a colored status pill / count badge | `LemonBadge` |
+| a small removable chip | `LemonSnack` or `LemonTag` |
+| a form field label | `LemonLabel` |
+| a dropdown / combobox / autocomplete | quill `DropdownMenu` / `Combobox` / `Autocomplete` (not a new `LemonMenu`) |
+| a card / panel | `LemonCard` |
+| a modal / confirm dialog | `LemonModal` / `LemonDialog` |
+
+If nothing fits, say so and propose extending the existing component before adding a new one. Don't silently fork.
+
+> LemonUI vs quill, and the quill spacing/composition rules, live in the root `AGENTS.md` ("Code Style → Frontend (quill …)") and `packages/quill/packages/primitives/AGENTS.md`. Follow those — don't mix quill and Lemon inside one component's internals.
+
+## Rule 2 — Don't handwrite API types; use the generated ones
+
+Django serializers are the source of truth. `hogli build:openapi` generates TypeScript types (suffix `Api`) and API functions. **Never write an `interface` that mirrors a backend serializer** — import the generated type instead.
+
+- Types: `import type { UserAuthSessionApi } from '~/generated/core/api.schemas'`
+ (exemplar: `frontend/src/scenes/settings/user/loginSessionsLogic.ts`)
+- Request functions: `import { getExportsContentRetrieveUrl } from '~/generated/core/api'`
+ (exemplar: `frontend/src/scenes/inbox/components/signalCards/SessionReplaySignalCard.tsx`)
+- Generated output lives in `frontend/src/generated/core/` and `products/*/frontend/generated/`. **These files are codegen output — never edit them by hand.** Change the serializer and rerun.
+
+When touching `lib/api`, `api.get<`, `api.create<`, or any handwritten API interface, invoke the `/adopting-generated-api-types` skill first.
+
+## Rule 3 — Business logic in kea, not React hooks
+
+Covered by the root `AGENTS.md` (Code Style → Frontend). The discovery hint for this tree: if a scene/component has a `*Logic.ts`, that's where actions/reducers/selectors/listeners belong. See `/writing-kea-logics` and `/using-kea-disposables`.
+
+## Typecheck & typegen cadence (don't over-run these)
+
+These are slow; run them at the right moment, not after every edit.
+
+- **TypeScript check** — `pnpm --filter=@posthog/frontend typescript:check` (runs `tsgo --noEmit` over the whole app). Rely on the editor/LSP while editing; run the full check **once before you call the work done**, not per-edit.
+- **kea typegen** (`*Type.ts` files) — regenerates automatically via `typegen:watch` while the dev server runs (`./bin/start` / `hogli start`). If you must regen one logic without the server, use `pnpm --filter=@posthog/frontend typegen:file <path>`. **Don't routinely run the full `typegen:write`** — it's a heavy whole-repo pass (multi-GB heap).
+- **`hogli build:openapi`** — only needed when you changed a **backend serializer/viewset**. A pure `.tsx`/`.ts` change never needs it. Don't run it speculatively.
+
+## Lint & format
+
+Run `pnpm --filter=@posthog/frontend format` (oxlint `--fix` + oxfmt) before finishing. Config: root `.oxlintrc.json`. CSS, spelling, and copy-casing rules live in the root `AGENTS.md` (Code Style).
+
+## Deeper references
+
+- Root `AGENTS.md` — full Code Style + architecture rules (authoritative).
+- `packages/quill/packages/primitives/AGENTS.md` — component selection matrix.
+- `docs/published/handbook/engineering/conventions/frontend-coding.md` — frontend conventions.
+- Skills: `/adopting-generated-api-types`, `/writing-kea-logics`, `/using-kea-disposables`, `/writing-tests`.
diff --git a/frontend/src/CLAUDE.md b/frontend/src/CLAUDE.md
new file mode 120000
index 000000000000..47dc3e3d863c
--- /dev/null
+++ b/frontend/src/CLAUDE.md
@@ -0,0 +1 @@
+AGENTS.md
\ No newline at end of file