posthog-foss / rules
Cursor rule721 starsChanged 56 days agoMITView on GitHub
Rules for writing frontend code at PostHog (mostly React + Typescript with Kea)
1 other project uses a version of this.
Adopted by
Most recently taken up by
- PostHog/posthogword for word, first seen Oct 4, 2026
Other versions1 project uses a version of this.
Word for word · 1
- PostHog/posthog★ 40k100% same
Edited · 0
None found.
Wrote their own version · 0
None found.
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
Where files are headingNew Cursor rule files have more rules about planning and tracking tasks, and fewer about code style.
Of the Cursor rule files we read, the 1,533 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository119 other files it gives its agents.
- AGENTS.mdAGENTS.md
- common/AGENTS.mdAGENTS.md
- proto/AGENTS.mdAGENTS.md
- rust/AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- common/CLAUDE.mdCLAUDE.md
- proto/CLAUDE.mdCLAUDE.md
- rust/CLAUDE.mdCLAUDE.md
- .cursor/rules/django-python.mdcCursor rule
- .cursor/rules/rust.mdcCursor rule
- adding-activity-loggingSkill
- adding-api-scopesSkill
- adding-inbound-webhooksSkill
- adding-inbox-sourcesSkill
- adding-ingestion-warningsSkill
- adding-mcp-store-serversSkill
- adding-personhog-rpcSkill
- adding-product-alertingSkill
- adding-project-secret-api-key-authSkill
- adopting-generated-api-typesSkill
- analyzing-experiment-precompute-canarySkill
- analyzing-experiment-query-performanceSkill
- analyzing-insights-across-teamsSkill
- announcing-behavior-changesSkill
- auditing-llm-gateway-paritySkill
- auditing-warehouse-source-coverageSkill
- authenticating-to-clickhouseSkill
- authoring-ci-workflowsSkill
- autoresolving-pr-conflictsSkill
- building-product-empty-statesSkill
- clickhouse-migrationsSkill
- debugging-ci-failuresSkill
- debugging-local-replaySkill
- debugging-local-task-agent-runsSkill
- debugging-mcp-analyticsSkill
- debugging-signals-pipelineSkill
- debugging-table-access-deniedSkill
- depot-ciSkill
- depot-container-buildsSkill
- depot-github-runnersSkill
- developing-subscriptionsSkill
- django-migrationsSkill
- django-startup-timeSkill
- documenting-warehouse-sourcesSkill
- editing-agents-mdSkill
- establishing-code-ownershipSkill
- extending-hobby-smoke-testsSkill
- extending-personhog-test-harnessSkill
- finding-llm-gateway-migration-candidatesSkill
- fixing-flaky-testsSkill
- gating-production-deploysSkill
- gating-sensitive-actionsSkill
- generating-clickhouse-query-performance-reportsSkill
- hogliSkill
- implementing-mcp-toolsSkill
- implementing-mcp-ui-appsSkill
- implementing-warehouse-sourcesSkill
- improving-drf-endpointsSkill
- improving-mcp-toolsSkill
- ingestion-pipeline-doctor-nodejsSkill
- The first 60 shown.
The file
Show its rules and text
We split this react-typescript.mdc into the rules it gives an agent
19 rules. About 0 are common, 15 are distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈15
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 17
Always implement data layer in Kea logic.
- Distinctive: line 20
Write TypeScript with proper typing for all new code
- Distinctive: line 21
Use functional programming patterns.
- Distinctive: line 22
Prefer iteration and modularization over code duplication.
- Distinctive: line 23
Use descriptive variable names with auxiliary verbs (e.g., isLoading, hasError).
- Very specific: line 24
Don't use useState or useEffect to store local state.
- Distinctive: line 26
Use named exports; avoid default exports
- Very specific: line 30
Always look around the codebase for naming conventions, and follow the best practices of the environment (e.g.
- Very specific: line 31
Use clear, yet functional names (searchResults vs data).
- Very specific: line 36
Avoid index.ts, styles.css, and other generic names, even if this is the only file in a directory.
- Distinctive: line 39
Use Tailwind CSS as primary styling solution
- Distinctive: line 41
Use SCSS with component-specific files
- Distinctive: line 43
Follow BEM for modals (.DashboardMenu__modal)
- Distinctive: line 44
Import styles directly (MyComponent.scss)
- Distinctive: line 46
When mentioning PostHog products, the product names should use Sentence casing, not Title Casing.
- Distinctive: line 51
Add presentational elements to Storybook
- Distinctive: line 52
Run storybook locally: pnpm storybook
- Distinctive: line 56
Keep data layer separate from view hierarchy
- Distinctive: line 57
Write clear, understandable code
≈ “Common” is an estimate: at least 1 in 5 of the 3,030 Cursor rule files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
---
description: Rules for writing frontend code at PostHog (mostly React + Typescript with Kea)
globs: frontend/**/*.ts,frontend/**/*.tsx,products/**/*.ts,products/**/*.tsx
alwaysApply: false
---
You are an expert in TypeScript, React, Kea, Tailwind, and UX design.
Since you are an expert, remember that when you add or remove anything in a kea *logic.ts file there will always be typescript errors.
You need to wait for the kea typegen to complete before those errors go away, please don't start editing files trying to fix the errors until kea typegen has run
Also, any file with a name ending logicType.ts is autogenerated and should never be edited
Architecture
- Two-layer system: Kea (data/state) -> React (view/template)
- Always implement data layer in Kea logic; avoid React state
Code Style and Structure
- Write TypeScript with proper typing for all new code
- Use functional programming patterns; avoid classes
- Prefer iteration and modularization over code duplication.
- Use descriptive variable names with auxiliary verbs (e.g., isLoading, hasError).
- Don't use `useState` or `useEffect` to store local state. It's false convenience. Take the extra 3 minutes and change it to a `logic` early on in the development.
- Logics still have a tiny initialization cost. Hence this rule doesn't apply to library components in the `lib/` folder, which might be rendered hundreds of times on a page with different sets of data. Still feel free to write a logic for a complicated `lib/` component when needed.
- Use named exports; avoid default exports
- Structure files logically: logic, component, types, styles
Naming Conventions
- Always look around the codebase for naming conventions, and follow the best practices of the environment (e.g. use `camelCase` variables in JS, `snake_case` in Python).
- Use clear, yet functional names (`searchResults` vs `data`).
- Logics are camelCase (`dashboardLogic`)
- React components are PascalCase (`DashboardMenu`).
- Props for both logics and components are PascalCase and end with `Props` (`DashboardLogicProps` & `DashboardMenuProps`)
- Name the `.ts` file according to its main export: `DashboardMenu.ts` or `DashboardMenu.tsx` or `dashboardLogic.ts` or `Dashboard.scss`. Pay attention to the case.
- Avoid `index.ts`, `styles.css`, and other generic names, even if this is the only file in a directory.
UI and Styling
- Use Tailwind CSS as primary styling solution
- For non-Tailwind cases:
- Use SCSS with component-specific files
- Namespace under component class (.DashboardMenu)
- Follow BEM for modals (.DashboardMenu__modal)
- Import styles directly (MyComponent.scss)
- Replace custom SCSS with Tailwind when possible
- When mentioning PostHog products, the product names should use Sentence casing, not Title Casing. For example, 'Product analytics', not 'Product Analytics'. Any other buttons, tab text, tooltips, etc should also all use Sentence casing. For example, 'Save as view' instead of 'Save As View'.
Testing Requirements
- Logic tests for all Kea logic files
- React Testing Library tests for interactive lib/ components
- Add presentational elements to Storybook
- Run storybook locally: pnpm storybook
Core Principles
- Prioritize maintainability over development speed
- Keep data layer separate from view hierarchy
- Write clear, understandable code
- Think data first, implement views second
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

