A developer’s guide to a tidy workspace

Any software project collects clutter over time, from a quick prototype to a large-scale application. Generated files, temporary data, and sensitive information pile up in ways that cost disk space and create security risks. Cleaning up now and then keeps projects lean, secure, and easy to share.

The “what” and “why” of a clean workspace

Messy project folders usually have three kinds of culprits, each worth cleaning up for a different reason.

  • Generateables: These are files and folders created by your tools and frameworks during development. A prime example is the notorious node_modules folder in NodeJS projects. Your app needs it to run, but it can be massive, and it regenerates easily from your package.json file. Other examples include build or dist folders, and __pycache__ directories in Python. Removing them before archiving or sharing a project can make the archive a lot smaller.

  • Temporary Files: Operating systems and development environments often create temporary files (.tmp, .log, .cache). While usually harmless, they contribute to disk usage and are generally unnecessary to keep.

  • Sensitive Data: This is the category you most need to manage. Files like .env (environment variables) and .pem (private keys) often contain confidential information such as API keys and database credentials. Accidentally uploading these to a public repository can lead to serious security breaches.

Prevention first: the power of .gitignore

The best way to keep your repository clean is to prevent unnecessary files from being tracked by Git in the first place. This is where the .gitignore file comes in. It’s a simple text file that tells Git which files and folders to ignore.

A well-configured .gitignore should be one of the first things you create in a new project. It helps avoid accidental commits of large or sensitive files.

A More Complete .gitignore Example:

This example covers common files and folders across different operating systems and development environments.

## Windows ###
# src: https://www.toptal.com/developers/gitignore/api/windows

# Windows thumbnail cache files
**/Thumbs.db
**/Thumbs.db:encryptable
**/ehthumbs.db
**/ehthumbs_vista.db

# Dump file
**/*.stackdump

# Folder config file
**/[Dd]esktop.ini

# Recycle Bin used on file shares
**/$RECYCLE.BIN/

# Windows Installer files
**/*.cab
**/*.msi
**/*.msix
**/*.msm
**/*.msp

# Windows shortcuts
**/*.lnk

### Linux ###
# src: https://www.toptal.com/developers/gitignore/api/linux
**/*~

# temporary files which can be created if a process still has a handle open of a deleted file
**/*.fuse_hidden*

# KDE directory preferences
**/*.directory

# Linux trash folder which might appear on any partition or disk
**/*.Trash-*

# .nfs files are created when an open file is removed but is still being accessed
**/*.nfs*

### Dev ###
**/*.idea
**/*.vscode
**/*.code-workspace
**/*.vercel
**/*node_modules
**/*vendor

# Env
**/*.env*
**/*.pem

# Framework Builds
**/build

Tools of the trade: scripts and automation

For files that have already been created, a bit of scripting can go a long way.

Cleaning a specific project

Before sharing your project as a ZIP file, you can run a script to remove unwanted files and folders.

@echo off
setlocal
title Project Cleanup

REM --- Change directory to the script's location ---
pushd "%~dp0"

echo Starting cleanup process...
echo.

REM --- Delete sensitive files if they exist ---
echo Searching for and deleting sensitive files (.pem, .env*)...
del /s /f /q ".\*.pem" >nul 2>&1
del /s /f /q ".\.env*" >nul 2>&1
echo.

echo Searching for and deleting generated folders...
echo.

REM --- Process node_modules ---
for /f "delims=" %%d in ('dir /b /ad "node_modules*" 2^>nul') do (
    echo Deleting "%%d"
    rmdir /s /q "%%d"
)

REM --- Process .svelte-kit ---
for /f "delims=" %%d in ('dir /b /ad ".svelte-kit*" 2^>nul') do (
    echo Deleting "%%d"
    rmdir /s /q "%%d"
)

REM --- Process .vercel ---
for /f "delims=" %%d in ('dir /b /ad ".vercel*" 2^>nul') do (
    echo Deleting "%%d"
    rmdir /s /q "%%d"
)

REM --- Process vendor ---
for /f "delims=" %%d in ('dir /b /ad "vendor*" 2^>nul') do (
    echo Deleting "%%d"
    rmdir /s /q "%%d"
)

echo.
echo Cleanup complete.
echo.

popd
endlocal
pause

System-wide cleanup: taming node_modules

Over time, old projects pile up node_modules folders that can eat a surprising amount of disk space. Here’s how you can find and delete them.

A tool called npkill is built for this. You can run it without installation using npx. It lists all node_modules directories with their sizes and lets you delete them with a single keypress.

To use it, simply run this command in your terminal:

npx npkill

You can then navigate with the arrow keys and press the spacebar or Del key to delete the selected folder.

Alternatively, you can use a script for a more automated approach.

@echo off
setlocal EnableDelayedExpansion

echo Searching for and deleting all node_modules folders...
for /d /r . %%d in (node_modules) do (
    if exist "%%d" (
        echo Deleting "%%d"
        rmdir /s /q "%%d"
    )
)
echo Deletion process finished.
pause

Clearing system temporary files

Your operating system also has a dedicated temporary folder that can get bloated over time.

@echo off
echo Cleaning system temporary files...
del /q /f /s "%TEMP%\\*"
for /d %%x in ("%TEMP%\\*") do rmdir /s /q "%%x"
echo Temporary files cleaned.
pause
Caution
Be very careful with these commands, especially the Linux/macOS version. Running rm -rf in the wrong directory can have disastrous consequences.

Final thoughts

Make these habits part of your regular development workflow. They free up disk space and keep your projects safer and easier to move around. Start every project with a solid .gitignore, run a cleanup script or npkill every so often, and your environment stays clean and efficient.