npx (Node Package eXecute) does not provide a built-in command to list recently run commands or a cache history explicitly. However, there are some workarounds and places you can look to find what has recently been used or cached:
🔍 1. Check the npx cache directory:
By default, npx stores downloaded packages in a cache directory. This can give you clues about recently used packages.
✅ Location of the cache (for npm v5.2+):
The default cache location is:
~/.npm/_npx/
You can view what's inside:
ls ~/.npm/_npx/
Each temporary directory corresponds to a recent npx execution.
You can inspect the directory contents to get more info:
ls -lt ~/.npm/_npx/
-lt will list them by modification time, most recent first.
You can also check symlinks or package files within those folders for names.
🐾 2. Use Shell History (bash, zsh, etc.)
Your shell history might have recent npx commands:
history | grep npx
Or for zsh:
fc -l | grep npx
You can search back through the most recent commands you've used.
📩 3. Verbose npx Logging
Although not persistent logging, you can use npx --verbose when running commands to understand behavior, especially caching behavior.
Example:
npx --verbose create-react-app my-app
This will display downloaded packages and whether the command came from cache or not.
🧹 Optional: View Cache Content with npm cache
You can also poke around the npm cache if relevant packages were downloaded via npx:
npm cache ls --depth=1
📁 TL;DR - Where to find clues
| Location | Use case |
|---|
~/.npm/_npx | Cached package folders, temporary working dirs |
Shell history (history) | Previously executed npx commands |
npx --verbose | Debugging current runs, not historical |
✅ Pro Tip: Keep in mind that npx often deletes the temporary directories unless you use the --no-cleanup flag. So only recent invocations or commands run with that flag will still have cache entries.
Would you like a script to extract and list recent npx used packages from the cache?