What the agent does
A dead-code tool is only as honest as its entry points, so the agent reads the app's wiring first. In an app like the apps/react-vite workspace of alan2207/bulletproof-react, index.html loads src/main.tsx, which mounts the tree under src/app/ (index.tsx, provider.tsx, router.tsx and the routes/ directory). vite.config.ts registers the React plugin and vite-tsconfig-paths for the @/* alias declared in tsconfig.json, and carries the Vitest block: jsdom, setupFiles at src/testing/setup-tests.ts, and e2e/** excluded. package.json is a yarn project with build as tsc && vite build --base=/, test as vitest, lint as eslint src, check-types, a generate script that runs plop from plopfile.cjs and generators/component/, storybook from .storybook/main.ts, and run-mock-server, which starts mock-server.ts: an Express app serving the MSW handlers from src/testing/mocks/handlers through @mswjs/http-middleware. .github/workflows/react-vite-ci.yml runs build, tests, lint, check-types and the Playwright suite from e2e/.
Every one of those is an entry point knip would otherwise report as dead, so the configuration names them: src/main.tsx, mock-server.ts, plopfile.cjs and the generator templates, the .storybook files, the Playwright specs under e2e/, vite.config.ts and playwright.config.ts. With the plugins knip ships for Vite, Vitest, Storybook, Playwright and ESLint, most of that is detected, and the agent checks the detected list against what it read rather than trusting it. Then knip runs and reports unused files, unused exports and types, unlisted and unused dependencies, and dependencies in the wrong section, which in this app includes eslint-plugin-check-file sitting under dependencies rather than devDependencies.
Each finding is then tried, because knip reports what nothing imports, not what the app can do without. For an unused file the agent deletes it on a scratch branch and runs yarn check-types and yarn build; for an unused export it drops the export keyword and adds yarn test, since the feature folders under src/features/ (auth, comments, discussions, teams, users) keep their tests next to the code; for a dependency it removes the package and runs build and tests. A finding that breaks any check is recorded as a false positive with the command that failed, which is often a dynamic import or a component the plop generator references by path.
The result is dead-code.md: one table per kind with the path, the line, the last commit that touched it from git log, and the checks it survived; a section of false positives with their failing command; and a closing section on what knip cannot see, such as a route only reachable by URL or a mock handler kept for an e2e flow. The working tree is left as the run found it.
Start it with one API call
POST https://api.phoenix.so/o/{org}/sessions with this body:
{
"agent": "codex",
"input": "Find dead code in this Vite React app without changing the repository. Read index.html, src/main.tsx, src/app, vite.config.ts, tsconfig.json, package.json, plopfile.cjs, .storybook, playwright.config.ts, mock-server.ts and the CI workflow, and configure knip with every entry point they imply. Run knip, then try each unused file, export and dependency on a scratch branch: remove it and run yarn check-types, yarn build and yarn test. Write dead-code.md with one table per kind listing path, line, last commit and the checks passed, a list of false positives with the failing command, and a section on what the tool cannot see. End with a clean git status.",
"resources": [
{
"url": "https://github.com/your-org/your-app"
}
]
}- Get an API key. In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
- Send the request. POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
- Read what came back. Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.
What comes back
What comes back is dead-code.md as an artifact on the session, with a url on api.phoenix.so that downloads it without a key until url_expires_at, and the same file through the artifacts route with the key. The session's result gives the counts per kind. No branch is pushed and no commit is made; the transcript ends with git status showing nothing to commit.
Each row is actionable on its own: a path, the line, who last touched it, and the three checks it passed after removal. The dependency table separates packages nothing imports from packages in the wrong section of package.json, which are a one-line move rather than a deletion. The false-positive list is the part that saves the next person time, since each entry says which check broke and why, and the knip configuration the agent wrote is included in the report so it can be committed.
The transcript at GET /o/{org}/sessions/{id}/messages holds the knip output and every scratch removal with its build and test result. A follow-up to the session can ask for the confirmed rows to be applied and opened as a pull request, with the app still installed in the sandbox.
Run it on every end of each sprint
Your own scheduler sends POST /o/{org}/sessions with this body at the close of each sprint, with a request_id that is a UUID v5 of the sprint name so a retry returns the same run. Each report is written from the tree at that moment, so the rows that are new since the previous report are the sprint's leftovers: a feature folder whose last consumer was removed, a package added for an experiment.
A webhook URL on the API key gets run.completed when the turn finishes, and the handler downloads dead-code.md from the session and files it where the front-end team plans cleanup. Several apps, such as the three workspaces in a repository like this one, are separate runs with separate reports.
The use case this job follows, with its automation and trigger: Produce a report or file, no repo.
Why run it on Rush?
Running knip takes a moment; confirming its findings takes a tsc, a Vite build and a Vitest run per finding, and an app with a few dozen findings turns that into an afternoon on a laptop that cannot do anything else. The sandbox installs once with yarn and runs the loop as many times as there are rows, and the scratch branch never touches your checkout.
The report carries its evidence. Every row names the commands that passed after the removal, every false positive names the one that failed, and the transcript keeps both, so a reviewer can trust a row without re-running it. Several front ends can be scanned at once, up to the key's max_concurrent limit, each producing its own file.
Frequently asked questions
Does it change my repository?
No. Removals happen on a scratch branch inside the sandbox to run the checks and the branch is discarded; the result is the report. Send a follow-up asking for the confirmed rows to be applied and the agent opens a pull request from the same sandbox.
Why is the mock server an entry point?
mock-server.ts is started by the run-mock-server script and the e2e job, and it imports the MSW handlers and the mock database under src/testing/mocks. Without naming it, knip would list those files as unused, and removing them would break the Playwright suite rather than the unit tests.
Will it catch unused props or unreachable branches?
No. knip works at the file, export and dependency level. Unused props and branches that never run are a different analysis, and the report's last section says so rather than implying the tool covered them.
What does it do with the plop generator templates?
They are files nothing imports, so knip would report them. The agent names plopfile.cjs and the generators/ directory as entries, so templates are kept out of the unused-file table and noted as tooling in the report.
More Vite + React jobs
The same job on other stacks
- Find Dead Code in a Vue Project (Vue)
- Find Dead Code in an Angular App (Angular)
- Find Dead Code in a Flask App (Flask)