/cleaning-up-stale-feature-flags
Identify and clean up stale feature flags in a PostHog project. Use when the user wants to find unused, fully rolled out, or abandoned feature flags, review them for safety, and then disable or delete them. Covers staleness detection, dependency checking, and safe removal
$ npx -y skills add posthog/posthog --skill cleaning-up-stale-feature-flags --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
- Fires itselfAuto-invocation. Claude auto-loads it when your prompt matches the work.Auto-invocation is when the right skill fires by itself at the right moment, driven by a FLOW.md router and a hook, instead of you invoking it by name. It is the difference between a skill being installed and a skill actually getting used.Read the full definition →
- You can call itInvoke it directly when you want it.
- Slash command
/cleaning-up-stale-feature-flags
Context preview
The summary Claude sees to decide when to auto-load this skill.
Identify and clean up stale feature flags in a PostHog project. Use when the user wants to find unused, fully rolled out, or abandoned feature flags, review them for safety, and then disable or delete them. Covers staleness detection, dependency checking, and safe removal
SKILL.md
cleaning-up-stale-feature-flags.SKILL.mdname: cleaning-up-stale-feature-flags
description: 'Identify and clean up stale feature flags in a PostHog project. Use when the user wants to find unused, fully rolled out, or abandoned feature flags, review them for safety, and then disable or delete them. Covers staleness detection, dependency checking, and safe removal workflows.'
Cleaning up stale feature flags
This skill guides you through finding feature flags that are no longer serving a purpose and safely removing them.
When to use this skill
- The user asks to clean up, audit, or review their feature flags
- The user wants to find flags that are stale, unused, or fully rolled out
- The user asks "which feature flags can I remove?" or similar
- The user wants to reduce tech debt from old feature flags
What makes a flag stale
A feature flag is considered stale when it's no longer doing useful work. PostHog tracks this with two signals:
1. **Usage-based staleness**: The flag has `last_called_at` data, but hasn't been evaluated in 30+ days. This is the strongest signal — the SDKs are no longer checking this flag. 2. **Configuration-based staleness**: The flag has no usage data (`last_called_at` is null), is 30+ days old, and is 100% rolled out (boolean at 100% with no property filters, or a multivariate flag with one variant at 100%). A fully rolled out flag with no conditions is equivalent to a hardcoded value — it can be replaced by removing the flag check from code.
Disabled flags (`active: false`) are not considered stale — they were intentionally turned off and may be kept for reactivation.
Workflow
1. List stale flags
Call `posthog:feature-flag-get-all` with `active: "STALE"`. This returns all stale flags in a single request — PostHog handles the staleness detection server-side using the criteria described above.
2. Assess each candidate
For each stale flag, gather context before recommending action:
**Check if it's tied to an experiment:**
The `posthog:feature-flag-get-definition` tool returns an `experiment_set` field. If non-empty, the flag is used by an experiment — check the experiment status before touching it.
**Check if other flags depend on it:**
Feature flags can have dependencies (flag B only evaluates when flag A is true). The flag definition includes dependency information in its `filters`. Look for `flag_key` references in other flags' filter groups.
**Check when it was last modified:**
A flag last updated years ago with no recent calls is a stronger removal candidate than one updated last month with no calls (it might be newly deployed and waiting for a release).
**Summarize for the user:**
For each stale flag, present:
- Flag key and description
- Why it's considered stale (no calls in N days, or fully rolled out for N days)
- Whether it's tied to experiments
- When it was created and last modified
- A recommended action (clean up from code and disable, or keep with explanation)
3. Generate code cleanup instructions
Generate a cleanup prompt the user can run in their code editor or coding agent. The cleanup instructions must be tailored to each flag's rollout state, because the rollout state determines which code path to keep. This list also serves as the approval checklist — if the user says their code is already cleaned up, they review it and confirm which flags to disable.
Classify each flag into one of three rollout states based on its definition:
- **`fully_rolled_out`**: A boolean flag with a release condition at 100% rollout and no property filters, or a multivariate flag where one variant is at 100%. Record which variant was active (for multivariate flags).
- **`not_rolled_out`**: All release conditions are at 0%, or the flag has no release conditions at all.
- **`partial`**: Everything else — the flag had some targeting but wasn't fully rolled out or fully off.
Then generate instructions following this structure:
**For fully rolled out boolean flags** — remove the flag check but keep the enabled code path:
Search for: isFeatureEnabled, useFeatureFlag, getFeatureFlag, posthog.isFeatureEnabled, posthog.getFeatureFlag
For flag "example-flag":
- Remove the if-check, keep the body
- If there is an else branch, remove the else branch entirely
**For fully rolled out multivariate flags** — keep only the winning variant's code:
For flag "example-flag" (keep variant: "winning-variant"):
- For if/else chains: keep only the branch matching "winning-variant", remove the flag check
- For switch statements: keep only the winning variant's case, remove the switch
**For not-rolled-out flags** — remove the entire flag check AND the enabled code path:
For flag "example-flag":
- Remove the if-check AND its body (the feature was never active)
- If there is an else branch, keep only the else body
**For partial rollout flags** — flag these for manual review:
For flag "example-flag":
- This flag had a partial rollout — check the flag's intent to determine which code path to keep
- Then remove the flag check
End the instructions with: "After cleanup, remove any dead code branches and unused imports."
Present the full cleanup prompt in a copyable format so the user can paste it directly into Claude Code, Cursor, Copilot, or any other AI code editor.
4. Disable flags after code changes are deployed
**Never disable flags before the code changes are deployed.** Disabling a fully rolled out flag while code still checks it will cause that code path to stop working — a production regression.
**Never disable flags without explicit user approval.** Always present the list and recommendations first, then ask which flags to act on.
Present the user with both options and their tradeoffs:
- **Disable** (`active: false`) via `posthog:update-feature-flag`: The flag stops being evaluated but the configuration is preserved. If something was missed in the code cleanup, re-enabling is instant. Recommended as the default.
Read more
name: cleaning-up-stale-feature-flags description: 'Identify and clean up stale feature flags in a PostHog project. Use when the user wants to find unused, fully rolled out, or abandoned feature flags, review them for safety, and then disable or delete them. Covers staleness detection, dependency checking, and safe removal workflows.'
Cleaning up stale feature flags
This skill guides you through finding feature flags that are no longer serving a purpose and safely removing them.
When to use this skill
- The user asks to clean up, audit, or review their feature flags
- The user wants to find flags that are stale, unused, or fully rolled out
- The user asks "which feature flags can I remove?" or similar
- The user wants to reduce tech debt from old feature flags
What makes a flag stale
A feature flag is considered stale when it's no longer doing useful work. PostHog tracks this with two signals:
1. **Usage-based staleness**: The flag has `last_called_at` data, but hasn't been evaluated in 30+ days. This is the strongest signal — the SDKs are no longer checking this flag. 2. **Configuration-based staleness**: The flag has no usage data (`last_called_at` is null), is 30+ days old, and is 100% rolled out (boolean at 100% with no property filters, or a multivariate flag with one variant at 100%). A fully rolled out flag with no conditions is equivalent to a hardcoded value — it can be replaced by removing the flag check from code.
Disabled flags (`active: false`) are not considered stale — they were intentionally turned off and may be kept for reactivation.
Workflow
1. List stale flags
Call `posthog:feature-flag-get-all` with `active: "STALE"`. This returns all stale flags in a single request — PostHog handles the staleness detection server-side using the criteria described above.
2. Assess each candidate
For each stale flag, gather context before recommending action:
**Check if it's tied to an experiment:**
The `posthog:feature-flag-get-definition` tool returns an `experiment_set` field. If non-empty, the flag is used by an experiment — check the experiment status before touching it.
**Check if other flags depend on it:**
Feature flags can have dependencies (flag B only evaluates when flag A is true). The flag definition includes dependency information in its `filters`. Look for `flag_key` references in other flags' filter groups.
**Check when it was last modified:**
A flag last updated years ago with no recent calls is a stronger removal candidate than one updated last month with no calls (it might be newly deployed and waiting for a release).
**Summarize for the user:**
For each stale flag, present:
- Flag key and description
- Why it's considered stale (no calls in N days, or fully rolled out for N days)
- Whether it's tied to experiments
- When it was created and last modified
- A recommended action (clean up from code and disable, or keep with explanation)
3. Generate code cleanup instructions
Generate a cleanup prompt the user can run in their code editor or coding agent. The cleanup instructions must be tailored to each flag's rollout state, because the rollout state determines which code path to keep. This list also serves as the approval checklist — if the user says their code is already cleaned up, they review it and confirm which flags to disable.
Classify each flag into one of three rollout states based on its definition:
- **`fully_rolled_out`**: A boolean flag with a release condition at 100% rollout and no property filters, or a multivariate flag where one variant is at 100%. Record which variant was active (for multivariate flags).
- **`not_rolled_out`**: All release conditions are at 0%, or the flag has no release conditions at all.
- **`partial`**: Everything else — the flag had some targeting but wasn't fully rolled out or fully off.
Then generate instructions following this structure:
**For fully rolled out boolean flags** — remove the flag check but keep the enabled code path:
Search for: isFeatureEnabled, useFeatureFlag, getFeatureFlag, posthog.isFeatureEnabled, posthog.getFeatureFlag For flag "example-flag": - Remove the if-check, keep the body - If there is an else branch, remove the else branch entirely
**For fully rolled out multivariate flags** — keep only the winning variant's code:
For flag "example-flag" (keep variant: "winning-variant"): - For if/else chains: keep only the branch matching "winning-variant", remove the flag check - For switch statements: keep only the winning variant's case, remove the switch
**For not-rolled-out flags** — remove the entire flag check AND the enabled code path:
For flag "example-flag": - Remove the if-check AND its body (the feature was never active) - If there is an else branch, keep only the else body
**For partial rollout flags** — flag these for manual review:
For flag "example-flag": - This flag had a partial rollout — check the flag's intent to determine which code path to keep - Then remove the flag check
End the instructions with: "After cleanup, remove any dead code branches and unused imports."
Present the full cleanup prompt in a copyable format so the user can paste it directly into Claude Code, Cursor, Copilot, or any other AI code editor.
4. Disable flags after code changes are deployed
**Never disable flags before the code changes are deployed.** Disabling a fully rolled out flag while code still checks it will cause that code path to stop working — a production regression.
**Never disable flags without explicit user approval.** Always present the list and recommendations first, then ask which flags to act on.
Present the user with both options and their tradeoffs:
- **Disable** (`active: false`) via `posthog:update-feature-flag`: The flag stops being evaluated but the configuration is preserved. If something was missed in the code cleanup, re-enabling is instant. Recommended as the default.
: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.
Repo: posthog/posthog
Other skills on posthog.
- /analyzing-expensive-users
Analyze the most expensive users in AI observability and explain why they cost so much. Use when the user asks about top spenders, expensive users, per-user LLM cost, user-level cost drivers, or patterns behind high AI observability spend.
Open skill - /creating-online-evaluations
Author continuously-running online evaluations in PostHog AI observability, grounded in real failure modes you've identified. Use when the user wants evaluations that automatically score new generations or whole traces going forward — "create an eval to catch X", "continuously
Open skill - /exploring-ai-failures
Find where an AI/LLM application is failing in production and surface the failure patterns, working from real traces. Use when someone wants to understand what's going wrong with an AI feature, find and categorize failure modes, triage errors, or investigate quality issues
Open skill - /exploring-llm-clusters
Investigate AI observability clusters — understand usage patterns in AI/LLM traffic, compare cluster behavior, compute cost/latency metrics, and drill into individual traces within clusters.
Open skill - /exploring-llm-costs
Investigate LLM spend in PostHog — total cost over time, cost by model, provider, user, trace, or custom dimension, token and cache-hit economics, and cost regressions. Use when the user asks "how much are we spending on LLMs?", "which model / user / feature is most expensive?",
Open skill - /exploring-llm-evaluations
Investigate AI observability evaluations — `hog` (deterministic code-based), `llm_judge` (LLM-prompt-based), and `sentiment` (user-message sentiment). Find existing evaluations, inspect their configuration, run them against specific generations, query individual results, and
Open skill

