Skip to content

Dynamic Configuration

Instead of a JSON file, you can use a JavaScript or TypeScript file for a dynamic configuration and type annotations:

knip.ts
import type { KnipConfig } from 'knip';
const config: KnipConfig = {
entry: ['src/index.ts'],
project: ['src/**/*.ts'],
};
export default config;

You can export a regular or async function that returns the configuration object as well:

knip.ts
import type { KnipConfig } from 'knip';
const config: KnipConfig = async () => {
const items = await fetchRepoInfo();
return {
entry: ['src/index.ts', ...items],
project: ['src/**/*.ts'],
};
};
export default config;

Knip also exports a defineConfig helper. It returns the configuration unchanged, so its only purpose is to type what you pass in:

knip.ts
import { defineConfig } from 'knip/config';
export default defineConfig({
entry: ['src/index.ts'],
project: ['src/**/*.ts'],
});

The same works in a JavaScript configuration file, without the JSDoc annotation. A function is accepted as well:

knip.ts
import { defineConfig } from 'knip/config';
export default defineConfig(async () => ({
entry: ['src/index.ts', ...(await fetchRepoInfo())],
project: ['src/**/*.ts'],
}));

ISC License © 2026Lars Kappert