configdirector-clean-up-flag
Remove a settled temporary ConfigDirector feature flag from the code, keeping the branch it serves, after reading its lifecycle state, its recent evaluations and every code reference through the ConfigDirector MCP server or CLI and configdirector scan, and archive the config only once the user confirms the removal is deployed. Use when the user asks to remove, retire or clean up a flag, or to hardcode its value.
Skill body
Remove a settled flag from the code
Work through the steps in order. The result is the code without the flag: the branch the flag serves stays, the other branch, the evaluation and their tests go, and the config is archived only once the user confirms the removal is deployed everywhere that read it. Confirm with the user before editing anything and before archiving.
This skill removes one temporary feature flag per run. A kill switch or a permanent config stops at step 2, and why a flag is still read is not answered here.
Cleaning up a flag needs an API token with these permissions, as the ConfigDirector dashboard names them under API tokens: Projects: Read, Environments: Read, Configs: Read, Configs: Archive.
1. Reach the account, find the project and check the permissions
Use the ConfigDirector MCP tools when the ConfigDirector MCP server is connected, and the configdirector CLI otherwise; never both in one run, except scan in step 3, which exists only on the CLI. With the CLI, always pass --json and read the output, never the human text. Each step names the MCP tool first and the CLI command second.
List the projects: list_projects / configdirector projects list --json. When the current repository has configdirector.json, the project is the one whose slug is its project, and every CLI command, projects list included, runs from the directory that holds the file. Otherwise it is the only project listed, or the one the user picks when there are several: ask which one the flag belongs to. Then pass --project <slug> to every CLI command below.
Then read the token’s permissions, before proposing anything. On MCP, they are the ConfigDirector tools you can see by name, loaded or not, since the server offers only the tools the token allows; on the CLI, configdirector api-token get --json lists them in short form in permissions. The table gives each permission in the dashboard’s wording, its short form and the MCP tool that needs it:
| Permission | Short form | MCP tool |
|---|---|---|
Projects: Read |
projects:read |
list_projects |
Environments: Read |
environments:read |
list_environments |
Configs: Read |
configs:read |
get_config |
Configs: Archive |
configs:archive |
archive_config |
When Projects: Read, Environments: Read or Configs: Read is missing, stop and ask before proposing anything. When Configs: Archive is missing, tell the user that archiving the config at the end needs it, and go on; step 6 stops and asks before the archive.
When a step fails, tell the user why. The CLI sign-ins case runs the command again; every other case means nothing can be created or changed, so stop and ask, with the case’s fix as the first choice:
- No route answers: no ConfigDirector tool is available, and
configdirectoris not installed, orprojects listexits 2 withNo API token foundorNo CLI sign-in is for the organization, or withThe Admin API refused the requestand a code other thanINSUFFICIENT_PERMISSIONS, such asAPI_TOKEN_EXPIRED. Send the user toconfigdirector-connectfor a token with the permissions above. - Exit 2 with
unknown command: the installed CLI is older than the commands this skill uses. Tell the user to install@configdirector/cliagain, which updates it, as the Install section of https://docs.configdirector.com/integrations/cli shows. - Exit 2 with
There are CLI sign-ins for: the CLI is signed in to several organizations, and nothing names this repository’s. Ask the user which organization, offering the names the message lists. When the directory holds aconfigdirector.json, it has noorganizationyet: runconfigdirector init --organization <name>from that directory, which adds it, and tell the user the file changed and belongs in their next commit. When it holds none, pass--organization <name>to every later CLI command. Then run the command again. - The token belongs to another organization than the one
configdirector.jsonnames: the projectslist_projectsorprojects listreturns carry anotherorganizationIdthan itsorganization, or a CLI command exits 2 withThe token fromandbelongs to the organization. Tell the user so, and where the token came from: the MCP server’s configuration, the source the CLI’s message names, or elseCONFIGDIRECTOR_TOKENorCONFIGDIRECTOR_ORGANIZATIONset where you run commands, which the CLI uses ahead of the repository’s organization. Send them toconfigdirector-connect. - A permission is missing: on MCP, a tool of the table that you cannot see, or a tool error naming the permission; on the CLI, one the table lists that
permissionslacks, or exit 2 withThe Admin API refused the requestand the codeINSUFFICIENT_PERMISSIONS. A refusal names the permission in its short form. Tell the user which one in the dashboard’s wording, from the table, and that they can add it to the token on the API tokens page. - Exit 2 with any other message, or any other tool error, such as a suspended service or an unreachable API: report the message, which says what to do.
Stop and ask means: stop at once, before any other work, including work the user asked for outside this skill. Tell the user what was not created or changed and why, with a missing permission in the dashboard’s wording, and ask how to go on:
- They fix it, as the case says, and you try again.
- They archive the config from the dashboard’s Configs page, and you go on.
- They archive it later, as step 6 says, and you go on without archiving.
Wait for their answer. Choices 2 and 3 apply at step 6 only: before it, the run needs the facts of step 2 to decide whether the flag can go, so the first is the only choice.
2. Read the facts and decide from the lifecycle state
Read all three before deciding anything:
- The config:
get_config/configdirector configs get <key> --json. Note its currentkey, which the user may have named by an old one, its old keys indeprecatedKeys[].key, itsrole,lifetimeandstate, and itstargets, one entry per environment withtargets[].environment.slugandtargets[].environment.live, itsrulesand itsdefaultValue, the default targeting rule value. Write each environment’s rules in one line per rule, asconfigs getwrites them, with the default targeting rule value last, for exampleproduction (live): 1. plan is one of pro, team: true; default targeting rule: true. When no config has the key (on MCP, an error saying so; on the CLI, exit 2 withNo config in <project> has the key), list the configs withlist_configs/configdirector configs list --jsonand ask which one the user means. - The recent evaluations:
get_config_activity/configdirector configs activity <key> --json. Each entry oflatestEvaluationsis the most recent evaluation from one environment, SDK key kind (source), SDK name and SDK version, with itstime. An SDK listed here can belong to another application than the repository you are in. - The environments:
list_environments/configdirector environments list --json, for which ones arelive. A live environment serves real traffic, and only live environments decide what the flag serves.
Then decide from the config, in this order, and stop where a line says so:
roleiskill-switch: stop. Cleanup is for temporary feature flags, which ConfigDirector tracks until they are removed, and a kill switch is permanent by its role: it stays in the code. When the team now means to remove it,configdirector-create-configupdates its role to feature flag, and ConfigDirector tracks it from then on. The dashboard also archives any config from its Configs page when they really mean to remove it now.lifetimeispermanent: stop. Cleanup is for temporary configs, and a config’s lifetime is the team’s choice: this one is meant to be read for good. When the team now means to remove it, they update its lifetime to temporary with the Edit lifetime pencil on its Settings tab in the dashboard, and ConfigDirector tracks it from then on. The dashboard also archives any config from its Configs page when they really mean to remove it now.stateisneworin-use: stop, and show the facts: which environments evaluated the flag and whether each is live, when, from which SDKs, and the rules in each environment, in the sentences of item 1. The flag is still read, so removing it now would change what those applications do.stateissettled,archive-readyorstale: go on. A settled flag has served one value in every live environment for its role’s horizon; an archive-ready one was in use or settled and has since gone quiet; a stale one was created more than 15 days ago and never evaluated.
3. Find every reference
Run configdirector scan --json from the directory that holds configdirector.json, or with --project <slug> when the repository has none. The scan has no MCP form: when the CLI is not installed, send the user to the Install section of https://docs.configdirector.com/integrations/cli, and when it reports No API token found or No CLI sign-in is for the organization, have them sign in to the repository’s organization with configdirector login in their own terminal, never by pasting the token into the chat. The CLI signs in on its own, apart from the MCP server, and scan needs Projects: Read and Configs: Read, so a token with the permissions of step 1 serves it as well.
Collect every entry of references whose key is the config’s current key or one of its old keys:
kinddirect: an SDK call that evaluates the flag, withcall, andargumentnaming the constant when the key came from one. The constant’s own definition is not listed again.kindindirect: the key written as a quoted string outside an SDK call, such as a list of keys, a wrapper’s argument or a fixture.
Either kind has test true when it is a test client call or sits in a test file.
The scan covers this repository only. When dynamicReferences is not empty, stop: list each one with its file, line, call and argument, and tell the user that an SDK call whose key the scan cannot know may read this flag, so it has to pass its key as a string or a constant before the cleanup can be trusted. When no reference to the key is listed, the code no longer reads it: say so and go to step 6.
4. Decide which branch stays
For a settled flag, the branch that stays is the single value the live environments serve, read from the rules of each live environment’s targets entry: its defaultValue when it has no rules, otherwise the value that every rule and the defaultValue serve. A percentage rule serves every value it splits over. ConfigDirector also reports the value as settledValue; when the two differ, or the live environments disagree, show the rules and ask. For an archive-ready flag, read it the same way, and when the live environments do not serve one value, the user picks. For a stale flag, the user picks. When the project has no live environment, read every environment.
Show each environment’s rules in the sentences of step 2, then propose the branch, such as “Keep the true branch: production and staging both serve true”, and wait for the user’s yes.
5. Show the change, then edit
Before editing, list every reference from step 3 and what happens to it:
- The evaluation is replaced by the kept branch: the SDK call, its in-code default value and the other branch go, and the kept branch’s code stays as it was, without the condition.
- The constant that holds the key is removed when nothing else reads it; a list of keys loses its entry; a wrapper or fixture loses its argument.
- The test client entries for the key and the tests of the removed branch are removed, and the tests of the kept branch stay without the flag, following
configdirector-test-with-flags. - The SDK client and its setup stay, whatever else reads them.
Wait for the user’s yes. Then make the edits, run the project’s build, typecheck and tests, and fix anything the change broke. Run configdirector scan --json again and confirm that no reference to the key or its old keys is listed.
6. The archive gate
Ask whether the removal is deployed everywhere that read the flag; the SDKs and environments of step 2 say where that is. Advise waiting a day or two after that deploy before archiving, in case an application is rolled back to the version that still reads the key: that version would get its in-code default value instead of the value the flag served, which can be the other branch.
On a yes, when Configs: Archive is missing, stop and ask as step 1 says. Otherwise show the archive before doing it: the config’s current key and project, that SDKs stop receiving the config and an application that still reads it gets its in-code default value and raises a Config not found alert, and that the dashboard restores it for 30 days with its targeting rules intact. Wait for the user’s yes, then archive it by its current key: archive_config / configdirector configs archive <key> --json. On the CLI, exit 2 with No config in <project> has the key means the config is already archived or belongs to another project; on MCP, an error saying no config has the key means the same. Read any other failure, such as a missing permission, as step 1 does, and stop and ask.
On a no, or when the user wants to wait, end without archiving and tell them how to archive later: run this skill again, which finds no reference and goes straight to this step, or run configdirector configs archive <key>, call archive_config, or archive it from the dashboard’s Configs page.
7. Hand over
In a few lines, tell the user:
- first, anything they asked for in ConfigDirector that was not created or changed, and why, ahead of what was done;
- the branch kept, and the files changed, with the tests removed or kept;
- whether the config was archived, or is left to archive later and how;
- that the dashboard restores an archived config for 30 days, after which it is deleted for good.
Skill frontmatter
Work with this as data
Every skill here is available over the APIs.io API and to AI agents over MCP.