Remove feature flags with your AI coding agent.
The agent deletes the flag and the code only its OFF path used. flagrm checks the build, the tests, lint and every leftover reference, and won’t let the agent stop until they pass.
npx flagrm init
Read the quick start Source on GitHub
Works with Claude Code, GitHub Copilot and Codex. Open source.
verify
- leftovers
- dead-code
- build
- tests
- lint
- coverage
How a removal runs
The agent does the reasoning: finding the flag, its aliases and wrappers, deleting the OFF path, refactoring methods the flag was passed into. flagrm decides when the work is done.
-
npx flagrm initAsks which agents to set up, with the ones your repository already uses pre-selected, and installs only their files: the
flagrm-removeandflagrm-reviewskills, the Claude Code Stop hook, Copilot prompt files, anAGENTS.mdpointer for Codex. Writesflagrm.config.yamlfor the Angular and .NET projects it finds and adds a.gitignoreentry. It never overwrites a file.You run this once. -
/flagrm-remove NewCheckoutOn a clean tree the agent runs
flagrm baseline, which records the commit, build, test and lint results and the flag’s names. In .NET and Angular code the baseline also follows the flag’s value into the locals, fields, getters, parameters and methods that carry it. The agent searches for every usage, records wrappers it finds with--name, removes the flag, and runsflagrm verifyuntil it passes. Name several flags (/flagrm-remove NewCheckout DarkMode) and it removes them one after another, one commit per flag. A passing verify’s results are reused, so each next baseline takes seconds.You ask, the agent works. -
flagrm hook stopIf the agent tries to finish after editing tracked files without a passing verify, the Stop hook sends it back to work with the reason. A removal paused on a question to you doesn’t block.Claude Code only. On other agents,
verifyis still the gate. -
git commitThe agent ends with the checks, the files changed since the baseline, the tests deleted or renamed, and a proposed commit message with the ticket from your branch name. It commits only if you said so. For an independent review, run
/flagrm-review NewCheckoutin a new session: it runsverify, then checks that the ON path is the code that stayed and that each deleted test covered only the OFF path. It reports findings and edits nothing.You review, then commit or let the agent commit.
What verify checks
In typed code, deleting the flag’s definition turns every missed reference into a compile error, so the build does most of the work. The other checks cover what the compiler can’t see.
| Check | Fails when |
|---|---|
leftovers | A recorded name is still in code or config: the flag literal, its constants, the wrappers the agent recorded. A mention in a comment is a warning, and so is a test that still checks text the removal deleted: a test of the OFF path that never names the flag. |
dead-code | The compiler reports new unused locals, imports or private members in the changed files. A method, property, field or type the removal left named only where it is declared is a warning: compilers don’t report public members. |
build | A project’s build command fails. |
tests | A test that passed at the baseline now fails. Tests that already failed at the baseline only warn. Tests that no longer run are sorted by why: deleted in the diff, renamed without the flag in the name, or left out by a changed test command. Any other is a warning the agent has to explain. |
lint | A project’s optional lint command fails where it passed at the baseline. A lint that already failed at the baseline only warns, unless the removal adds error lines. |
coverage | Warns about a changed file that no build, test or lint command checks, such as a script outside every project. Fails only with --strict. |
The baseline also records the build and test commands and the config it ran with. If they change before verify, the affected check warns and shows the difference. baseline --accept config,failures acknowledges a change you meant to make. Exit code 0 on pass, 1 on fail, 2 on a usage error. Add --strict to fail on warnings too, or --json to wire it into CI.
Supported stacks
An adapter tells flagrm how to find flags, build, test and read the compiler’s unused-code warnings. Angular and .NET have their own. The generic adapter covers any other language through file globs and the names of your flag-evaluation methods.
-
angular
- Finds flags in
- Flag objects and enums named like
*Flag*,*Feature*or*Toggle*, thefeaturesofenvironment*.ts, calls to the configuredmethods, and the fields, getters, locals and child component inputs the flag’s value flows into - Dead-code check
- TypeScript’s unused locals and parameters, on the changed files only
- Default build and test
npx ng build,npx ng test --watch=false, writing JUnit or Jest JSON results when the runner can without setup
-
dotnet
- Finds flags in
IFeatureManager,[FeatureGate],FeatureManagementinappsettings*.json, flag constants, and the locals, fields, parameters and methods the flag’s value flows into- Dead-code check
- Compiler warnings for unused fields, locals and parameters, and the IDE analyzers when the build enforces code style
- Default build and test
dotnet build --no-incremental,dotnet testwriting TRX results
-
generic
- Finds flags in
- String literals passed to the configured
methods, constants holding them, andFeatureManagementkeys in JSON. Go, Python, Java, Kotlin, Rust, Ruby, PHP, JS and more by default - Dead-code check
- Not available. Every other check still runs
- Default build and test
- Inferred from
go.mod,Cargo.tomlorpackage.jsonscripts
One file of config
init fills in what it can detect. build and test each fall back to the adapter’s default; set your own where they differ, then check them with npx flagrm doctor --run.
Point testResults at JUnit XML, TRX or Jest JSON and verify compares individual tests against the baseline by name. doctor says what to add for your test runner.
Add an optional lint command for code the build and tests don’t reach, such as end-to-end specs. covers says which files a project’s commands check, so coverage can flag the rest.
Machine can’t build everything? doctor checks the .NET SDK global.json asks for, cargo and Docker. npx flagrm scope --write creates a solution filter that leaves out what can’t build and points the build and test commands at it.
flagrm.config.yamltools: [claude-code, codex] # agents init and update set up
projects:
- name: web
adapter: angular
path: ./frontend
build: npm run build
test: npx ng test --watch=false
testResults: ./frontend/test-results/junit.xml
lint: npx eslint e2e # optional
covers: ['src/**', 'e2e/**']
methods: [isEnabled, watch] # how flags are evaluated
- name: api
adapter: dotnet
path: ./backend
build: dotnet build --no-incremental
test: dotnet test --logger trx --results-directory TestResults
testResults: ./backend/TestResults/*.trx
- name: service
adapter: generic # any other stack
path: ./service
globs: ['**/*.go', 'config/**/*.yaml']
exclude: ['**/Migrations/**']Get started
You need Node.js 22 or later, git, and an AI coding agent that reads skills: Claude Code, GitHub Copilot or Codex. The Stop hook is Claude Code only.
Commit or stash first: the baseline starts from a clean working tree, and verify compares against that commit.
terminal# install and set up (no package.json: npm i -g flagrm)
npm install -D flagrm
npx flagrm init
npx flagrm doctor --run
# in your agent: one flag, or several in a row
/flagrm-remove NewCheckout DarkMode
# optional, in a new session: an independent review
/flagrm-review NewCheckoutOne repository, several stacks
Run
initonce at the root. The config lists each project, such as an Angularweband a .NETapi, and one removal covers both.Separate repositories
Run
initand/flagrm-removein each repository. Each gets its own baseline and verdict. flagrm doesn’t coordinate them, so record the flag’s name in each (it may differ between UI and API) and pick the order yourself.No
package.json?A pure .NET or Go repository can run
npx flagrmor install it globally. The Stop hook runsnpx --no-install flagrm hook stop, so it needs a local or a global install.
The full command reference is in the README. New to flag removal? Read how to remove a feature flag safely, or automate it for stale LaunchDarkly flags on GitHub Actions or Azure Pipelines.
Questions
What flagrm does, what it leaves to the agent, and what it can’t see.
Something else? Ask on GitHub.
Does flagrm edit my code?
No. Your agent finds the usages and makes the edits, guided by the flagrm-remove skill. flagrm records the baseline, runs the checks and decides when the removal is done. Nothing is committed unless you tell the agent to: it proposes a commit message, and you review the diff.
Why use an agent? Couldn’t a codemod remove the flag?
Deleting the if (flag) branch is the easy part, and if your stack fits a structural tool such as Piranha, it does that well. The hard parts don’t fit rewrite rules: wrappers and aliases around the flag, references in config and templates, tests that cover both paths, and code that only becomes dead once the branch is gone. flagrm’s first version had a rewrite engine, and it was dropped for that reason. The agent makes the judgment calls. The compiler, build, tests and lint decide whether it’s done.
Isn’t this just asking the agent to remove the flag?
That prompt is where flagrm starts. Agents are good at the edits and unreliable at knowing when they’re finished. They leave references behind, delete a failing test instead of fixing the code, or stop with a broken build. flagrm adds what the prompt is missing. It takes a baseline before any edit and runs a verify that compares against it. In Claude Code, a Stop hook won’t let the agent finish until verify passes on the current tree.
Does a passing verify mean the removal is correct?
It means no recorded name is left in code or config, the build passes, no test that passed at the baseline fails, lint reports no new errors, and the compiler reports no new unused code. That’s as good as your tests and build are. /flagrm-review, in a new session, checks what verify can’t: that the ON path is the code that stayed and that each deleted test covered only the OFF path. Review the diff the way you would any other change.
What can’t it catch?
Flag names built at runtime (string concatenation, reflection), wrappers the agent didn’t find and record, keys outside the repository (Key Vault, Helm values, App Service settings) and other services that read the same flag. In untyped code, missed references don’t break the build, so leftovers and your tests carry more of the weight.
Does it work with LaunchDarkly, Unleash or my own flag service?
LaunchDarkly, yes, for deciding which flags to remove: flagrm stale reads your project (read-only) and lists the flags that are ON everywhere, marked temporary and have been for a set number of days. A scheduled GitHub Action or Azure DevOps pipeline can then open a removal pull request per flag. See the guides for GitHub Actions and Azure Pipelines. Unleash and other services have no such connection. For them, and for the code side of every service, flagrm works on the code: set methods to the names of your evaluation calls (isEnabled, variation, …) and it finds the flags passed to them. flagrm checks the code change deterministically, so the agent isn’t judging its own work. Archive the flag in the service after the code change is deployed, not before.
Does it work with a monorepo or separate repositories?
Both. flagrm works per git repository, because the baseline is a commit of one repository. In a monorepo, run init once and list each project in flagrm.config.yaml: one removal covers the Angular and the .NET code together. With the UI and the backend in separate repositories, run init in each and ask the agent to remove the flag in each. Every repository gets its own verdict, and the order of the removals is up to you.
Which agents does init set up?
Claude Code gets the skills in .claude/skills/ and the Stop hook. Copilot gets the skills in .github/skills/ and /flagrm-remove and /flagrm-review prompt files. Codex gets the skills in .agents/skills/ and a pointer in AGENTS.md. init never overwrites a file.
Is it stable?
Yes. flagrm follows semantic versioning from 1.0. Within 1.x, commands, options, exit codes, config keys, --json output, the .flagrm/ files, the skill names and the Stop hook command stay compatible. Text and markdown output, the wording of the skills and detection aren’t covered: a minor release may find more flag usages or unused code, so a removal that passed verify before can fail it after an upgrade. Releases reach npm with provenance, and only after a maintainer approves them with 2FA.
Coming from 0.x? Read the 1.0 release notes first: the --frontend and --backend options and their config keys are gone, replaced by projects:. After any upgrade, npx flagrm update refreshes the installed skills and hook.