mcpbeat Sign in

Managing Path Cleaning Rules Agent Skill

Inspects URL paths and proposes, tests, orders, and applies project-level path cleaning rules so dynamic segments (numeric IDs, UUIDs, slugs, dates) collapse into readable aliases. Use when the user says "clean the paths", "normalize URLs", "group similar pages", "too many distinct paths", "/users/123 and /users/456 are the same page", "set up path cleaning", or asks why a Web analytics or Paths breakdown is fragmented across thousands of nearly-identical URLs. Covers regex syntax (re2), alias placeholder convention, rule ordering, the test workflow, and applying rules via the project-settings-update MCP tool.

2k tokens
context cost
the whole folder, loaded on every use
1
files
instructions only
0
copies elsewhere
how many repositories repackaged it
57
stars on the repo
on the repository, not the skill itself

Install

one command, takes just this skill from the repository
npx skills add https://github.com/PostHog/skills --skill managing-path-cleaning-rules

The instruction itself

11 sections, as written by the author

Managing path cleaning rules

Path cleaning rules normalize $pathname and $entry_pathname so that pages

sharing the same template (/users/123/profile, /users/456/profile, …) collapse

into one row (/users/<id>/profile) in Web analytics tiles, Paths insights, and

any HogQL query that calls apply_path_cleaning. They are the right answer when

a breakdown is fragmented across thousands of near-identical URLs.

This skill teaches you how to:

  • recognize when path cleaning is the right tool
  • inspect real paths to find what needs cleaning
  • write regex + alias rules in re2 syntax with the project's placeholder

convention

  • test rules before saving them
  • order rules so specific patterns aren't swallowed by generic ones
  • apply the rules via MCP

Data model

Team.path_cleaning_filters is a JSON list of PathCleaningFilter objects:

{
  "regex": "/users/\\d+/profile",
  "alias": "/users/<id>/profile",
  "order": 0
}
  • regex — a re2 pattern. No

need to escape /. Anchor with ^ / $ when you mean it.

  • alias — the literal replacement. Use angle-bracket placeholders

(<id>, <slug>, <uuid>, <date>) by convention so the cleaned path stays

human-readable. The alias is _not_ a regex template — backreferences are not

supported.

  • order — integer. Rules apply sequentially in order ascending,

each rule's output feeds the next.

Application is replaceRegexpAll(pathname, regex, alias) per rule, chained.

Source: posthog/hogql/property.py:613.

Workflow

1. Confirm path cleaning is the right move

Ask yourself: is the user complaining about cardinality (too many distinct paths

in a chart), or do they want a per-URL drill-down? Path cleaning is for the

former. If they want per-URL data, suggest a property filter on $pathname

instead.

2. Inspect the real paths

Don't guess at patterns — query them. With the execute-sql MCP tool:

SELECT properties.$pathname AS path, count() AS views
FROM events
WHERE event = '$pageview'
  AND timestamp > now() - INTERVAL 7 DAY
GROUP BY path
ORDER BY views DESC
LIMIT 200

Scan the result for:

  • numeric IDs: /users/123, /orders/4242
  • UUIDs: /sessions/8f3c1a3b-…
  • slugs: /posts/why-i-love-posthog
  • dates: /archive/2024-09-12
  • locales: /en-US/, /fr-FR/
  • pagination: ?page=3, /page/3/

3. Draft regex + alias

| Pattern | Example match | regex | alias |

| ------------------- | ---------------------- | ---------------------------- | ---------------------- |

| Numeric segment | /users/123/profile | /users/\d+/profile | /users/<id>/profile |

| UUID v4 | /sessions/8f3c1a3b-… | /sessions/[0-9a-f-]{36} | /sessions/<uuid> |

| Slug | /posts/why-posthog | /posts/[a-z0-9-]+$ | /posts/<slug> |

| ISO date | /archive/2024-09-12 | /archive/\d{4}-\d{2}-\d{2} | /archive/<date> |

| Locale prefix | /en-US/about | ^/[a-z]{2}-[A-Z]{2}/ | /<locale>/ |

| Trailing query/page | /blog?page=3 | \?page=\d+$ | (empty alias drops it) |

Anchoring rules of thumb:

  • start the regex with ^ only when the segment must be at the beginning of

the path

  • end with $ to keep a generic rule (e.g. \d+$) from matching mid-path

segments

4. Test before saving

Three options, pick one:

  • Settings page tester: /settings/project#path_cleaning has a built-in

"test path" input that replays the full ordered chain.

  • Project HogQL (via execute-sql):
  SELECT replaceRegexpAll('/users/42/profile', '/users/\d+/profile', '/users/<id>/profile')

Chain replaceRegexpAll calls in the same order the rules will run if you

want to verify multi-rule interaction.

  • Built-in AI helper: there is already an AiRegexHelper modal accessible

from the rule editor (Help me with Regex button) that turns natural

language into a regex. Suggest it to the user when they say "I don't know

regex" — but always validate the output against real paths via the tester.

5. Order rules from most-specific to most-general

Sequential application means a generic rule placed first will swallow

everything that should have hit a specific rule.

order=0  /users/me/profile        →  /users/me/profile     (specific, runs first)
order=1  /users/\d+/profile       →  /users/<id>/profile
order=2  /users/[a-z0-9-]+        →  /users/<slug>          (catch-all, runs last)

If /users/[a-z0-9-]+ ran first it would also match /users/me/profile and

make the more specific rule unreachable.

6. Apply via MCP

Use the project-settings-update tool with the full list (the field is

replaced, not merged):

{
  "path_cleaning_filters": [
    { "regex": "/users/me/profile", "alias": "/users/me/profile", "order": 0 },
    { "regex": "/users/\\d+/profile", "alias": "/users/<id>/profile", "order": 1 },
    { "regex": "/users/[a-z0-9-]+", "alias": "/users/<slug>", "order": 2 }
  ]
}

Always read the existing rules first (project settings include

path_cleaning_filters) and merge — overwriting silently destroys whatever the

team has already configured.

Where the rules apply

When the user (or a HogQL query) opts in:

  • Web analytics: the Path cleaning toggle in the page header

(PathCleaningToggle.tsx)

  • Paths insights: the path cleaning toggle in the insight filters
  • HogQL: any query that calls apply_path_cleaning(path_expr, team)

The rules are stored once per project — they are not insight-scoped.

Common pitfalls

  • Backreferences in alias need double-escaping — ClickHouse's

replaceRegexpAll supports \0 (whole match) and \1\9 (capture

groups). In a JSON field or SQL string literal the backslash must be

doubled, so use \\1 in path_cleaning_filters / HogQL to get the \1

backreference at the ClickHouse layer.

  • Forgetting $\d+ without an end anchor matches every numeric run

in any path, so /blog/2024-09-12/post becomes

/blog/<num>-<num>-<num>/post when you only meant to match the year

segment. Use \d+$ or \d+(/|$) depending on intent.

  • Escaping / — re2 does not require it. \/ works but adds noise.
  • Case sensitivity — re2 is case-sensitive by default. Use (?i) at the

start of the pattern for case-insensitive matching, e.g. (?i)/users/\d+.

  • Replacing the whole listpath_cleaning_filters is overwrite, not

append. Always start from the current list.

  • Rules apply globally — adding a rule can change historical numbers in

every Web analytics / Paths chart that has cleaning enabled. Warn the user

before applying anything destructive.

Other skills for the same job

different authors, same section of the catalogue
XLSX
by anthropics
vendor ×15

Comprehensive spreadsheet creation, editing, and analysis with support for formulas, formatting, data analysis, and visualization. When Claude needs to work with spreadsheets (.xlsx, .xlsm, .csv, .tsv, etc) for: (1) Creating new spreadsheets with formulas and formatting, (2) Reading or analyzing data, (3) Modify existing spreadsheets while preserving formulas, (4) Data analysis and visualization in spreadsheets, or (5) Recalculating formulas

5k tokens scripts
XLSX
by w95
×7

Use this skill any time a spreadsheet file is the primary input or output. This means any task where the user wants to: open, read, edit, or fix an existing .xlsx, .xlsm, .csv, or .tsv file (e.g., adding columns, computing formulas, formatting, charting, cleaning messy data); create a new spreadsheet from scratch or from other data sources; or convert between tabular file formats. Trigger especially when the user references a spreadsheet file by name or path — even casually (like \"the xlsx in my downloads\") — and wants something done to it or produced from it. Also trigger for cleaning or restructuring messy tabular data files (malformed rows, misplaced headers, junk data) into proper spreadsheets. The deliverable must be a spreadsheet file. Do NOT trigger when the primary deliverable is a Word document, HTML report, standalone Python script, database pipeline, or Google Sheets API integration, even if tabular data is involved.

3k tokens
Raffle Winner Picker
by frostant
×5

Picks random winners from lists, spreadsheets, or Google Sheets for giveaways, raffles, and contests. Ensures fair, unbiased selection with transparency.

949 tokens
Fda Database
by christophacham
×4

Query openFDA API for drugs, devices, adverse events, recalls, regulatory submissions (510k, PMA), substance identification (UNII), for FDA regulatory data analysis and safety research.

32k tokens scripts
Matlab
by christophacham
×4

MATLAB and GNU Octave numerical computing for matrix operations, data analysis, visualization, and scientific computing. Use when writing MATLAB/Octave scripts for linear algebra, signal processing, image processing, differential equations, optimization, statistics, or creating scientific visualizations. Also use when the user needs help with MATLAB syntax, functions, or wants to convert between MATLAB and Python code. Scripts can be executed with MATLAB or the open-source GNU Octave interpreter.

25k tokens
Umap Learn
by ComeOnOliver
×4

UMAP dimensionality reduction. Fast nonlinear manifold learning for 2D/3D visualization, clustering preprocessing (HDBSCAN), supervised/parametric UMAP, for high-dimensional data.

14k tokens
D3 Viz
by chrisvoncsefalvay
×3

Creating interactive data visualisations using d3.js. This skill should be used when creating custom charts, graphs, network diagrams, geographic visualisations, or any complex SVG-based data visualisation that requires fine-grained control over visual elements, transitions, or interactions. Use this for bespoke visualisations beyond standard charting libraries, whether in React, Vue, Svelte, vanilla JavaScript, or any other environment.

20k tokens
Alphafold Database
by christophacham
×3

Access AlphaFold 200M+ AI-predicted protein structures. Retrieve structures by UniProt ID, download PDB/mmCIF files, analyze confidence metrics (pLDDT, PAE), for drug discovery and structural biology.

7k tokens

How to use it

Copy the folder

Take posthog/managing-path-cleaning-rules from the repository into ~/.claude/skills for personal use, or into .claude/skills inside a project.

Check the name does not clash

The agent identifies a skill by the name field in its header. Two skills with the same name cannot sit side by side — one of them will be ignored.