Technical debt isn't just about architecture. In long-running TypeScript projects, it also accumulates as "noise": unused exports, orphaned files, and dependencies you no longer need. Cleaning this manually is risky and boring.
In my latest article, I share a workflow that combines Knip (a powerful static analysis tool) with an AI Agent to automate this cleanup safely.
What you'll learn
✅ Why manual cleanup is dangerous and how automatic tools can break your production.
✅ How to configure Knip correctly, especially to avoid the common "test files" trap.
✅ The @internal pattern: A smart way to keep exports for testing without confusing your analysis.
✅ The complete AI Workflow: How to use an AI agent to verify unused code and remove it (or tag it) without breaking your app.
A taste of what's covered
One of the biggest challenges when cleaning code is distinguishing between code that is truly unused and code that is only used in tests.
If you simply delete an export because it's not used in production, you might break your test suite. Instead of deleting it, our workflow teaches the agent to use the JSDoc @internal tag:
/**
* @internal Exported for unit testing only - used internally by Cart component
*/
export const calculateTotal = (items: Item[]) => {
// ...
};
This keeps your tests green while telling Knip (and other developers) to ignore this export in future cleanup runs.
This article provides the full configuration and the specific prompt to let an AI agent handle the tedious verification work for you.
👉 Read the full article here: Efficiently Cleaning a TypeScript Project: Knip + AI Agent Workflow
Top comments (0)