# deleteDocument

Canonical URL: https://developers.iagenify.com/sdk/ref/tools/delete-document/
Language: en

`tools: { delete_document: api.tools.deleteDocument }`

Lets a run remove a file or a folder from view on the caller's computer — into a recycle bin, not out of existence.

Status: declaration only · free · recoverable

A declaration. And the one of the four that is not what its name suggests: nothing is destroyed.

## What the model sends {#arguments}

| Name | Type | Requirement | Description |
| --- | --- | --- | --- |
| `path` | string | required | The file or folder to remove, relative to the workspace. |

```javascript
// What the run reports back
{ path: "Launch plan/draft.md",
  trash: ".trash/2026-10-07T09-12-44-000Z/Launch plan/draft.md" }
```

## It is a move into .trash {#trash}

The item goes to `.trash/<timestamp>/<original path>`. The timestamp is what keeps two deletions of the same path apart, and the original path is kept underneath so a restore is a move back.

```javascript
// Restoring what a run removed
const trashed = ".trash/2026-10-07T09-12-44-000Z/Launch plan/draft.md";
await pc.files.move(trashed, "Launch plan/draft.md");
```

> **Hidden folders stay out of a listing**
>
> A dotted name is skipped by files.list(), so the bin does not show up as work. Reading it is a matter of naming it — which is what makes the recovery possible without a second mechanism.

## Why a run never deletes for real {#why}

An agent acts on text it has read — a page, a document, an instruction it was given. One mistaken step should not be final, and no model judgement is worth a file. So the destructive operation is not declared at all: what is declared is the reversible one.

## Emptying the bin is yours to do {#emptying}

Nothing clears `.trash` on its own: deciding when something is really gone is the account holder's, not a run's.

```javascript
for (const batch of await pc.files.list(".trash")) {
  if (Date.parse(batch.name.replace(/-(\d{3})Z$/, ".$1Z")) < Date.now() - 30 * 86_400_000) {
    await pc.files.remove(`.trash/${batch.name}`);
  }
}
```

> **It runs on the caller's computer, through the package**
>
> The server cannot reach a disk. When the agent calls this, the run asks the machine that holds the key to perform it, the package does the work there, and the answer goes back into the run. So it only works while your process is listening — and nothing of the file ever travels to be written.

## Refusals the run reports {#refusals}

- Nothing at that path.
- A path outside the workspace, or an absolute one.
- The workspace root.
- A bin entry already holding the same path at the same instant.

- [files.remove()](/sdk/ref/local-files/remove): The final deletion, from your own code.
- [moveDocument](/sdk/ref/tools/move-document): The move this is built on.
- [api.tools](/sdk/ref/tools): The fifteen, and the two ways to use them.

```python
# What the run reports back
{"path": "Launch plan/draft.md",
 "trash": ".trash/2026-10-07T09-12-44-000Z/Launch plan/draft.md"}
```

```python
# Restoring what a run removed
trashed = ".trash/2026-10-07T09-12-44-000Z/Launch plan/draft.md"
pc.files.move(trashed, "Launch plan/draft.md")
```

```python
import shutil, time

# Python's list() hides dot folders: walk .trash from the workspace root
month_ago = time.time() - 30 * 86_400
for batch in (pc.files.root / ".trash").iterdir():
    if batch.stat().st_mtime < month_ago:
        shutil.rmtree(batch)
```
