How to Use dbt clean Command to Remove Artifacts
Use the
dbt clean command to delete all files in the target and dbt_modules directories of your dbt project. This helps remove compiled files and dependencies safely before a fresh build.Syntax
The dbt clean command has a simple syntax with no additional arguments needed. It removes the target and dbt_modules folders in your project directory.
dbt clean: Deletes thetargetanddbt_modulesdirectories.
bash
dbt clean
Example
This example shows running dbt clean in a dbt project folder. It deletes the target and dbt_modules directories, clearing compiled models and installed packages.
bash
$ dbt clean Removing directory: target Removing directory: dbt_modules
Output
Removing directory: target
Removing directory: dbt_modules
Common Pitfalls
Common mistakes when using dbt clean include:
- Running it outside the dbt project folder, so it does nothing.
- Expecting it to remove source data or logs (it only removes
targetanddbt_modulesfolders). - Not reinstalling packages after cleaning, which can cause build errors.
Always run dbt deps after dbt clean to reinstall dependencies.
Quick Reference
| Command | Description |
|---|---|
| dbt clean | Deletes target and dbt_modules directories |
| dbt deps | Reinstalls packages after cleaning |
| dbt run | Builds models after cleaning and reinstalling |
Key Takeaways
Use
dbt clean to remove compiled files and installed packages safely.Always run
dbt deps after cleaning to reinstall dependencies.Run
dbt clean inside your dbt project directory.dbt clean does not delete source data or logs.Use
dbt clean to fix build issues caused by stale files.