Flavia Leotta
06/04/2026, 7:50 AMif <full_nextflow_command>
then
nextflow clean -f -k
fi
⢠The second one was to just add cleanup = true to my custom configuration file.
When I tried the second way, my whole work/ directory was cleaned up of everything, including .sh, .run, and .log files, which were never removed using the first method and which I needed to monitor what command was actually sent. Moreover, previous runs on the same sample were not cleaned up (their work/process/ folders were intact) which makes me think that this behaviour was caused by me messing around with the config.
Is it a functionality of cleanup = true or did something completely different happened? Thank you for anyone that might have an idea.Mahesh Binzer-Panchal
06/04/2026, 8:26 AMcleanup = true completely wipes the current run's work directory. It's documented https://docs.seqera.io/nextflow/reference/config#cleanup although it could be cleaner.
Here's a simple run script to use instead.
#! /usr/bin/env bash
set -euo pipefail
trap 'echo "=!= ERROR: Workflow failed (exit code: $?) ==="' ERR
echo "=== Starting workflow: ==="
echo "=== Profile: ${NXF_PROFILE:-uppmax} ==="
WORKFLOW=../../code/01_mapping/01_mapping.nf
nextflow run "${WORKFLOW}" \
-params-file params.yml \
-profile "${NXF_PROFILE:-uppmax}" \
${CLI_OPTS:-""}
echo ""
echo "=== Cleaning up obsolete work directories ==="
nextflow clean -f -before last && find work -type d -empty -delete
echo "=== Workflow complete ==="
⢠set -e means the script exits on an error, so if nextflow run errors, nextflow clean does not run
⢠update the profile to your needs. This is just a simple example from one of my projects.Flavia Leotta
06/04/2026, 8:29 AMThomas Danhorn
06/04/2026, 9:12 PM.command.sh, you can find that in the execution_report_.*html -- there is a table with all of the processes (including exit codes, RAM, CPU, and time allocations and use), and if you scroll over to the script column, you'll find the commands (click to expand). That saves you from keeping and searching through all of the .command.sh files.
And cleanup = true only affects the current run -- anything still hanging around from prior runs will not (and should not) be touched. The nextflow clean command has options like -before and -after that give you fairly fine-grained control over which runs to clean and which to keep. (Note that process work directories that are used [either originally or as cache] in other runs will not be deleted, even if they are also part of a run you are deleting.) The reason you are retaining logs, etc., with nextflow clean is the -k option -- without that the effect would be closer to cleanup = true.
But if you want ultimate control, a script like Mahesh showed you is the way to go.