Flag code references in Feature Experimentation
Flag code references show where each flag appears in your source code, directly on the flag page. Use code references to decide when a flag is safe to archive, without searching your repositories by hand.
Beta
This feature is in beta. The Code References tab displays only for accounts with access to the feature.
How code references work
A scanner runs in your continuous integration (CI) pipeline. CI is the automated process that builds and tests your code. The open source scanner searches your repository for your flag keys. It sends the location of each match to Optimizely.
The following rules apply to scans:
- The scanner runs on every push to the main or master branch. Optimizely stores references for these two branches only.
- Each scan replaces the references stored for that branch.
- Optimizely never clones or connects to your repository. Optimizely receives only what the scanner sends.
For each reference, the scanner sends the flag key, file path, line number, and a link to the line in your source code host. If your code refers to a flag by another name, called an alias, the scanner also sends the alias.
By default, the scanner sends five lines of code around each match, and Optimizely stores them. To send no code, turn on metadata-only mode in the scanner configuration. Metadata-only mode sends locations without code.
When a scan finds no references to a flag that had references before, Optimizely records an extinction for the flag. An extinction means you removed the flag from your code. If references reappear on main or master, Optimizely clears the extinction.
Set up code references
Setup happens in your repositories, not in the Optimizely app. To set up code references, you need the following:
- Your Feature Experimentation project ID
- A personal access token from a user who has permission to modify flags in the project
Add the scanner to your CI pipeline as a GitHub Action, a GitLab CI job, or a Docker command. The Code References tab updates when Optimizely stores the first scan for your project. For install steps, token guidance, and configuration, see the README in the optimizely/code-references repository on GitHub.
View code references for a flag
- Go to Flags.
- Select a flag.
- Click Code References in the Flag Setup list.
The tab content depends on the scan history of your project and the flag.
References found
The tab displays a warning that summarizes the references, for example: 7 code references found across 2 repositories. Last scanned 14 days ago. Archiving this flag may impact application behavior.
The tab then lists each reference with its file path, line number, repository, branch, and last scan time. Use the Repository drop-down list to filter the list.
Two more warnings display when they apply:
- Some repositories have not been scanned in over 30 days. These results may be out of date.
- Some references have not been confirmed by a scan in over 30 days and may no longer be in the code.
A reference found through an alias is labeled Alias. Click Show details to expand a reference, and click Hide details to collapse it. The expanded reference displays the following:
- The short commit ID
- The matched alias, if any
- A link to the file in your source code host, or Source link unavailable
- The surrounding code with line numbers and the referenced line highlighted, when the scanner stored the code
If the scanner did not store code, the tab displays Metadata-only mode enabled. This repository is configured to send file and line metadata without source code snippets.
Click More options for a reference to display the following actions:
- View on GitHub – Open the file in your source code host in a new tab. The label matches the host: View on GitLab for gitlab.com, View on Bitbucket for bitbucket.org, and View in source host for other hosts, including self-hosted hosts.
- Copy file path – Copy the path of the file.
Scanner not configured
Optimizely has not stored a scan for your project. The tab displays Scanner Not Configured and View Setup Guide. Every user with access to the tab sees the same message. View Setup Guide opens this article. To start scanning, follow the steps in Set up code references.
No references for this flag
Optimizely stored scans for your project, but none of the scanned repositories reference this flag. The tab displays the following text, for example: Scanned repositories did not contain any references to this flag. Last scanned on 16 November 2026 at 11:36AM. The tab also displays No code references found.
No references after previous references
A scan on main or master no longer finds references that an earlier scan found. The tab displays a notification such as Extinction detected today at 11:54AM., the heading No Code References Found, and a message that the flag may be ready for archival. If any repository still has references on main or master, the tab displays the references found state instead.
If you are a flag administrator and the flag is not archived, the tab also displays Archive Flag. Click Archive Flag to archive the flag without a confirmation. Feature Experimentation returns you to the Flags page and displays Flag archived successfully.
If the flag is enabled in the highest-priority environment, Feature Experimentation does not archive the flag. An alert asks you to disable the flag in that environment first.
If a new scan finds references before the archive completes, the Archive Flag? window displays.
Archive a flag that has code references
When a flag has references on main or master, Feature Experimentation stops the archive and displays the Archive Flag? window. The window contains the following:
- A warning that summarizes the references and the time of the last scan.
- A table of up to 25 references with the file path, line number, and repository. If the flag has more references, the window displays the number of remaining references.
- A More options menu for each reference. Click View Reference to open the file in your source code host.
- Two actions: Cancel and Archive Flag.
To keep the flag, click Cancel. To archive the flag anyway, click Archive Flag.
If the window cannot load the references, it displays a general warning that code references exist. If the references no longer exist when the window loads, the window states that the flag is safe to archive.
Note
When you archive a flag, Feature Experimentation also deletes the stored code references and extinction history for that flag.
For the standard archive steps, see Manage flags.
Remove the scanner
To stop scanning, remove the scanner workflow from your CI pipeline. Optimizely keeps the stored code references and the archive warnings that depend on them. The Code References tab notifies you when the data is out of date.
To delete the stored references for a repository, call the Optimizely REST API. Feature Experimentation has no UI for this action. For the request, see the scanning documentation in the optimizely/code-references repository on GitHub.