Skip to content

Removing Unused Code

Once a scan has reported unused code, you can remove it all at once with help from your AI agent, or record it in a baseline and clean it up gradually.

If you set up Periphery with the Periphery skills, ask your agent to scan your project and remove the unused code. The periphery-scan skill runs the scan, summarizes the results, and removes them when you ask it to.

Without the skills, run a scan with the agent-prompt output format and give the output to your agent:

Terminal window
periphery scan --format agent-prompt

This format presents the results as a removal task for an AI agent, with guidance on how to remove each kind of result.

Removing one declaration can break the build if other unused code still refers to it. The agent-prompt format avoids this by ordering and grouping the results into steps that can be removed one after another without causing build failures.

Your agent can build after each step to confirm the project still compiles, and you can review and commit the changes a step or a few steps at a time.

On a large project, you may not want to remove all the existing unused code straight away. A baseline records the results that exist today and excludes them from future scans, so you start from a clean state and only newly introduced unused code is reported:

Terminal window
periphery scan --write-baseline baseline.json

From then on, scan with --baseline baseline.json to keep new unused code out of your project, and clean up the recorded results at your own pace. See Baselines for how to use and update a baseline.