For the complete documentation index, see llms.txt. This page is also available as Markdown.

AI code clean-up

When the GitHub integration is enabled, Reflag can automatically clean up your code after flags turn stale. The Reflag bot submits a pull request to your GitHub repository that removes flag code once a flag turns stale.

Note: This works best when using the React SDK, but stay tuned for improved Node.js support

Get started with AI code clean-up

1. Connect with GitHub

Make sure the GitHub integration is connected for your organization and a repository have been chosen.

2. Enable automation

Enable "Auto-create AI Clean-up PRs" under organization-level Clean-up settings.

This ensures that newly created flags have the automation switched on.

3. Test it manually

Find a stale flag that is ready for clean-up by looking for the broom icon in the flags table.

Find the "Clean-up guide" in the flag sidebar, click "Show details", and hit the "Create AI clean-up PR" button to start the process.

Within a few minutes, you'll have a GitHub pull request that removes the flag and keeps the enabled codepath, like here:

Magical! ✨

Formatting clean-up PRs

If you're using eslint and/or prettier in GitHub Actions to ensure that code is correctly formatted, you'll need to set up a small GitHub Action workflow which runs on the AI Clean-up PRs.

The idea is that you run your own formatters with the existing configuration once the Reflag generated AI Clean-up PR has been created and then commit the results directly in the same Pull Request to make the PR checks pass.

Example: .github/workflows/reflag-clean-up-formatting.yml

Take note of the magic ✨ keyword included in the commit message in the final step.

Unfortunately, GitHub purposefully disables running checks on commits that are generated from inside the GitHub Actions job. In order for the checks to run again after the code has been correctly formatted and committed, the @reflagcom bot will push an empty commit when it sees a commit with the text (@reflagcom: push empty commit) .

Under the hood

The GitHub integration continuously checks the codebase against the flag keys in Reflag whenever a commit is pushed to the repository.

When the AI clean-up bot runs, it searches for usage of the Reflag SDK in your codebase and identifies where specific flag keys are used. LLMs then refactor the code to remove the flag and eliminate unreachable codepaths.

For React, this usually corresponds to the useFlag hook, like in this contrived example:

When the bot cleans up the file, it removes the hook and only retains the isEnabled codepath:

Limitations:

  • Only isEnabled is removed, whereas track, config, and requestFeedback are untouched.

  • Works best with the React SDK while in beta.

Last updated

Was this helpful?