Comment on page

Cleaning up unused imports in Python with autoflake using a VS Code task

python, vs code, autoflake, task, import

Add the following script to tasks.json

vsconfig="$HOME/Library/Application Support/Code/User"
open $vsconfig/tasks.json
// See <>
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
"type": "shell",
"label": "autoflake.removeUnusedImports",
"command": "${command:python.interpreterPath}",
"args": [
"presentation": {
"echo": false,
"reveal": "silent",
"focus": false,
"panel": "shared",
"showReuseMessage": false,
"clear": true,
"close": true
"problemMatcher": [],
"group": {
"kind": "none",

Trigger the cleanup process with a shortcut like $⇧⌥P$ in keybindings.json

MindEase Theme
// Place your key bindings in this file to override the defaults
"key": "Shift+Alt+P", //Set this value to any you like.
"command": "workbench.action.tasks.runTask",
"args": "autoflake.removeUnusedImports",

Automatically run on save from settings.json

"tasks.onSave": "autoflake.removeUnusedImports"
2023 © Yunus Emre AK