Cleaning Up Stale Feature Flags

作者 PostHog469d1773e9cb無授權條款收錄於 2026年10月8日更新於 2026年10月8日

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.

AI 產生的概覽

審查 PostHog 中過期的功能旗標,產生程式碼清理指示,並停用或刪除已核准的旗標。

功能
透過基於使用情況與基於設定的過期訊號,識別 PostHog 專案中的過期功能旗標,並評估每個候選旗標是否關聯實驗、存在相依性以及最後修改時間。它依發布狀態將旗標分類,並產生針對性的程式碼清理指示以移除旗標檢查。在程式碼變更部署且使用者核准後,逐一停用或軟刪除這些旗標。
適用情境
當使用者想要審查、清理或減少 PostHog 中舊功能旗標帶來的技術債時使用。適用於尋找未使用、已全量發布或已棄用的旗標並安全移除的要求。
執行需求
需要存取 PostHog 功能旗標工具(清單、定義、狀態、停用、刪除),並在停用或刪除任何旗標前取得使用者核准。不附帶指令碼,僅為指示。

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:

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

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

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

text
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 via posthog:feature-flag-disable: The flag stops being evaluated but the configuration is preserved. The tool takes only the flag id, so targeting cannot change. If something was missed in the code cleanup, re-enabling is instant. Recommended as the default.
  • Delete via posthog:delete-feature-flag: A soft-delete — the flag is marked as deleted but not physically removed. Keeps the flag list clean, but re-enabling requires recreating the flag. Better for flags the user is confident they'll never need again.

Once the user has chosen and confirms their code changes are deployed, apply the chosen action one flag at a time. Confirm each action so it's easy to stop if something goes wrong.

Example interaction

text
User: "Can you help me clean up our stale feature flags?"
Agent steps:- Call posthog:feature-flag-get-all with active: "STALE" to get all stale flags in one request- For each stale flag, call posthog:feature-flag-get-definition to check experiment_set and dependencies- Present findings:
   "I found 7 stale feature flags in your project:
   | Flag | Last called | Reason | Recommendation |   |------|-------------|--------|----------------|   | old-checkout-flow | 45 days ago | No evaluations in 45 days | Clean up and disable |   | beta-dashboard-v2 | Never | 100% rolled out, created 3 months ago | Clean up and disable |   | holiday-promo-2024 | 90 days ago | No evaluations in 90 days | Clean up and disable |   | new-pricing-page | 60 days ago | No evaluations in 60 days, tied to experiment #42 | Check experiment first |   ...
   Want me to generate cleanup instructions for any of these? I'd recommend   starting with old-checkout-flow and beta-dashboard-v2 since they have no dependencies."
- User confirms: "Yes, do old-checkout-flow and beta-dashboard-v2"- Classify rollout states from the flag definitions:   - old-checkout-flow: fully_rolled_out (boolean, 100% rollout, no conditions)   - beta-dashboard-v2: fully_rolled_out (boolean, 100% rollout, no conditions)- Generate and present cleanup prompt:
   "Here's a cleanup prompt you can paste into your code editor:
   ---   Find and remove all references to these feature flags in the codebase.   For each flag, search for all usages: isFeatureEnabled, useFeatureFlag,   getFeatureFlag, posthog.isFeatureEnabled, posthog.getFeatureFlag, etc.
   ## Flags that were rolled out to 100%   These flags were fully rolled out. Remove the flag check but KEEP the enabled code path.
   Boolean flags (remove the if-check, keep the body):   - old-checkout-flow   - beta-dashboard-v2
   If there is an else branch, remove the else branch entirely.   After cleanup, remove any dead code branches and unused imports.   ---
   Once you've cleaned up your code and deployed, let me know.   Would you like to disable or delete these flags?   - Disable (recommended): keeps the config, re-enabling is instant   - Delete: removes from the list, but you'd need to recreate if needed"
- User confirms: "Disable them, code is deployed"- Disable each flag using posthog:feature-flag-disable- Confirm: "Both flags are now disabled in PostHog."

Important notes

  • Code first, then disable. Disabling a flag while code still references it causes the enabled code path to silently stop working. Always clean up code and deploy before disabling.
  • Prefer disable over delete. Disabling is instantly reversible. Deletion is not — re-enabling requires recreating the flag. Always present both options with tradeoffs and let the user choose.
  • Always confirm before acting. This skill involves disabling flags, which can affect production behavior. Never disable without explicit user approval.
  • Disabled flags are not stale. Don't recommend disabling flags that are already intentionally disabled — they may be kept for emergency reactivation.
  • Experiment flags need extra care. If a flag is tied to an active or recently completed experiment, the user likely wants to keep it until they've analyzed results.
  • Seasonal flags may return. Flags like "black-friday-sale" might look stale but are intentionally reused. Ask the user before removing these.
  • Code cleanup is the real win. Removing the flag from PostHog is the easy part. The value comes from removing the dead code paths.

Related tools

  • posthog:feature-flag-get-all: List and search feature flags (supports active: "STALE" filter)
  • posthog:feature-flag-get-definition: Get full flag details including experiment associations
  • posthog:feature-flags-status-retrieve: Get the status and reason for a single flag
  • posthog:feature-flag-disable: Turn a flag off without touching its targeting
  • posthog:delete-feature-flag: Soft-delete a flag

來源與署名

來源:PostHog/ai-plugin位於skills/cleaning-up-stale-feature-flags提交469d177

授權條款: 無授權條款

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架

更多來自 PostHog/ai-plugin 的技能

Writing Simplified Technical English

PostHog

套用 ASD-STE100 簡化技術英語規則,讓代理撰寫的文字語意明確、方便執行。

Writing & Content2026年10月8日

Working With Task Comments

PostHog

透過 PostHog MCP exec 調度器讀取並解讀 PostHog 任務、成品和畫布上的留言。

Productivity & Workflow2026年10月8日

Working With Skills

PostHog

指導代理使用 PostHog 的 skill-* MCP 工具來探索、讀取、建立、更新與重構技能。

AI & Agents2026年10月8日

Working With Scouts

PostHog

說明如何把監看工作委派給 PostHog Signals 偵察代理、處理其回報,並長期調校整個代理團隊的操作手冊。

AI & Agents2026年10月8日

Validating And Publishing Canvases

PostHog

Validate and publish a canvas source project safely: the source-project shape, declared capabilities, reading the current version pointer, iterating on validation diagnostics, guarded publishing with expected_current_version_id, staging a draft build and promoting it, waiting out the queued build, and recovering from a 409 version_conflict or a 429 capacity limit without overwriting concurrent work. Use whenever a canvas edit is ready to save, a draft build is wanted, a canvas publish or build returns diagnostics or a conflict, or a task needs to understand canvas version history.

待分類2026年10月8日

Understanding Billing Usage

PostHog

Explains PostHog billing usage and spend from the customer's visible Billing MCP tools. Use when the user asks why usage or spend is high, which product or project is driving usage, what a usage type means, how to reduce usage, what changed over time, why they got a usage change alert, or whether a spike/drop alert was real or noisy. Also use before product-specific analytics skills when the user names a billable PostHog product metric such as events, recordings, feature flag requests, exceptions, survey responses, synced rows, logs, AI events, AI credits, or Inbox credits. Starts from Billing usage/spend tools, then routes to customer-visible product MCP surfaces for deeper investigation.

待分類2026年10月8日