> For the complete documentation index, see [llms.txt](https://docs.yemreak.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.yemreak.com/arsiv/programming/cleaning-up-unused-imports-in-python-with-autoflake-using-a-vs-code-task.md).

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

![](https://i.imgur.com/3Spu2ai.png)

## Add the following script to `tasks.json`

```shell
vsconfig="$HOME/Library/Application Support/Code/User"
open $vsconfig/tasks.json

```

```json
{
    // See <https://go.microsoft.com/fwlink/?LinkId=733558>
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "label": "autoflake.removeUnusedImports",
            "command": "${command:python.interpreterPath}",
            "args": [
                "-m",
                "autoflake",
                "-i",
                "--remove-all-unused-imports",
                "${file}"
            ],
            "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`

![](https://i.imgur.com/RzinrjY.png)

> MindEase Theme

```typescript
// 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`

![](https://i.imgur.com/e9KWP2b.png)

```json
"tasks.onSave": "autoflake.removeUnusedImports"

```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.yemreak.com/arsiv/programming/cleaning-up-unused-imports-in-python-with-autoflake-using-a-vs-code-task.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
