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.
Remove with your AI agent
Section titled “Remove with your AI agent”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:
periphery scan --format agent-promptThis format presents the results as a removal task for an AI agent, with guidance on how to remove each kind of result.
Removing in steps
Section titled “Removing in steps”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.
Start from a clean state with a baseline
Section titled “Start from a clean state with a baseline”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:
periphery scan --write-baseline baseline.jsonFrom 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.