Deskit

Scripts and AI agents

dkit is built to be driven by programs as well as people. This page covers running dkit commands from a script or an agent with a shell. For an assistant that speaks the Model Context Protocol, use dkit mcp instead: it adds a preview-before-remove rule that a shell cannot enforce.

Agent skill

An agent that runs shell commands, but has no MCP support, can be given Deskit’s skill: a short instruction file that tells it to preview first, wait for your yes, never release, and how to undo. It is skills/deskit/SKILL.md.

For Claude Code, copy the folder into your skills:

cp -r skills/deskit ~/.claude/skills/

Other agents that support skills take the same folder; for the rest, paste the file’s contents into the agent’s instructions.

A skill is advice the agent is expected to follow. Unlike dkit mcp, nothing stops an agent with a shell from running dkit release. Prefer the MCP server where the assistant supports it.

The rules

  1. No interactive screen without a terminal. When output is piped or redirected, or with --plain or --json, every command prints once and exits.
  2. --json works on every command and prints one JSON document on stdout.
  3. Errors go to stderr and the exit code is 1. With --json the error is {"error": "..."}.
  4. Nothing that changes files runs without a go-ahead. Outside a terminal, dkit clean, dkit purge, dkit installers, dkit uninstall, dkit release, dkit update and dkit remove refuse unless --yes is given.
  5. Colour is off when piped. NO_COLOR=1 forces it off, FORCE_COLOR=1 forces it on.
  6. The network is used by dkit update and by nothing else. No command checks for updates by itself.
  7. --debug adds a log on stderr and leaves stdout alone, so --json --debug still prints one JSON document on stdout. See --debug.

Safe to run at any time

These only read:

dkit status --json
dkit status --json --watch --count 10   # ten snapshots, one per line
dkit doctor --json
dkit analyze <path> --json
dkit clean --dry-run --json
dkit clean --rules --json
dkit purge <path> --dry-run --json
dkit uninstall --list --json
dkit uninstall <app> --dry-run --json
dkit uninstall <app> <app> --dry-run --json
dkit purge --kinds --json
dkit installers --dry-run --json
dkit installers --kinds --json
dkit history --json
dkit history <run-id> --json
dkit keep --json
dkit purge folders --json
dkit remove --dry-run --json

dkit update --check --json changes nothing either, but it downloads the latest release to read its version. It is the one reading command that uses the network.

Changing things

dkit clean --yes --json             # free what rebuilds itself; hold the rest 7 days for undo
dkit clean --yes --hold --json      # hold everything; all of it can be undone
dkit clean --yes --release --json   # free everything at once; nothing can be undone
dkit purge <path> --yes --json      # move idle projects' build folders aside; undo for 7 days
dkit purge <path> --yes --release --json   # delete them at once; cannot be undone
dkit installers --yes --json        # move finished installer files aside; undo for 7 days
dkit uninstall <app> --yes --json   # move an app and its files aside; undo for 7 days (macOS)
dkit uninstall <app> <app> --yes --json   # several apps in one run: all of them, or none
dkit undo --json                    # put back everything the last run holds
dkit undo <run-id> --json
dkit undo <run-id> <path>... --json # only these items, or what was inside these folders
dkit release --yes --json           # delete everything being held
dkit release <run-id> --yes --json

--include <rule> and --skip <rule> narrow or widen a clean; both can be repeated.

dkit keep add <path>... --json      # never clean these
dkit keep remove <path>... --json   # allow them to be cleaned again

The keep list needs no --yes: it only ever stops files from being cleaned.

dkit purge folders add <path>... --json     # where a bare `dkit purge` looks
dkit purge folders remove <path>... --json
dkit purge --yes --json                     # purge across the saved folders

Saving a folder needs no --yes either: it removes nothing, and gives purge no power it would not have with the folder named.

dkit update --yes --json            # replace dkit with the latest release
dkit remove --yes --json            # delete Deskit's own files, held files included, and the program

These two act on Deskit itself and are the person’s to decide. An agent should not run either unasked.

  1. Run dkit clean --dry-run --json and show the person the total and the largest groups, including each group’s recovery cost.
  2. Wait for the person to agree.
  3. Run dkit clean --yes --json, without --release, so anything costly to get back can still be undone.
  4. Report freed_bytes, held_bytes, any failed items, and that dkit undo puts the held part back.

Only use --release or dkit release when the person asks for the space to be freed now.

Output shapes

dkit clean --dry-run --json

{
  "dry_run": true,
  "total_bytes": 13314398618,
  "item_count": 66,
  "groups": [
    {
      "rule_id": "app-caches",
      "name": "App caches",
      "description": "Files apps keep to start faster. They are rebuilt when needed.",
      "category": "caches",
      "recovery": "automatic",
      "selected": true,
      "bytes": 6657199309,
      "file_count": 48211,
      "items": [
        { "path": "/Users/sam/Library/Caches/Example", "bytes": 2254857830, "is_dir": true, "file_count": 9120 }
      ],
      "unreadable": []
    }
  ],
  "skipped": [
    { "rule_id": "app-caches", "path": "/Users/sam/Library/Caches/link", "reason": "is a symbolic link" }
  ]
}
  • total_bytes and item_count cover groups with "selected": true only.
  • recovery is one of automatic, download, slow, never.
  • unreadable lists folders the rule could not open; their contents are missing from items.

dkit clean --yes --json

{
  "dry_run": false,
  "run_id": "20261128-153045",
  "moved_bytes": 13314398618,
  "moved_count": 66,
  "freed_bytes": 6657199309,
  "freed_count": 41,
  "held_bytes": 6657199309,
  "held_count": 25,
  "failed": [{ "path": "/Users/sam/Library/Caches/Busy", "reason": "permission denied" }],
  "released": false,
  "expired": []
}
  • run_id is null when nothing was moved.
  • moved_* counts everything cleaned. freed_* is the part already deleted; held_* is the part dkit undo can still put back.
  • released is true when nothing is held, so the run cannot be undone.
  • expired lists older runs whose 7 days were over and were released along the way.

dkit purge --dry-run --json

{
  "dry_run": true,
  "roots": ["/Users/sam/code"],
  "min_idle_days": 30,
  "total_bytes": 4294967296,
  "item_count": 1,
  "found": [
    {
      "kind": "node-modules",
      "name": "Node packages",
      "path": "/Users/sam/code/shop/node_modules",
      "project": "/Users/sam/code/shop",
      "recovery": "download",
      "bytes": 4294967296,
      "file_count": 48211,
      "idle_days": 400,
      "selected": true
    }
  ],
  "skipped": [{ "path": "/Users/sam/code/kept/node_modules", "reason": "on your keep list" }],
  "unreadable": []
}
  • found is largest first and includes folders of recently active projects with "selected": false. total_bytes and item_count cover selected folders only.
  • idle_days is whole days since the project last showed activity, or null when that could not be worked out; such folders are not selected.
  • --min-age <days> changes what is selected (default 30; 0 selects everything).
  • An entry of skipped with synced_by is a folder a cloud service keeps in sync, such as { "path": "/Users/sam/Dropbox", "reason": "kept in sync by Dropbox, so it was not looked in", "synced_by": "Dropbox" }. It was not entered, so whatever build folders are in it are not listed and cannot be purged. Naming such a folder as the path fails, with the service in the error. See Purge. Do not work around it by removing the folders another way: on a synced folder that deletes them from the person’s other devices.

The preview also has looked_in, which says how roots were chosen: named (folders were given), saved (none were given, so the saved folders were used) or here (none were given or saved, so the current folder was used). saved_not_searched lists saved folders that could not be searched, each with a reason.

dkit purge --yes --json prints the same shape as dkit clean --yes --json, plus roots: the folders that were searched. Before purging for someone, show them the preview: build folders take time and bandwidth to get back.

dkit purge folders --json, also printed by purge folders add and purge folders remove:

{
  "file": "/Users/sam/Library/Application Support/Deskit/purge-folders.txt",
  "paths": ["/Users/sam/code", "/Users/sam/work"],
  "added": ["/Users/sam/work"],
  "removed": [],
  "unchanged": [],
  "not_searched": []
}

paths is the list as it now stands. not_searched holds saved folders that cannot be searched right now, each with a path and a reason, such as one that has been deleted.

dkit installers --dry-run --json

{
  "dry_run": true,
  "folders": ["/Users/sam/Downloads", "/Users/sam/Desktop"],
  "min_age_days": 7,
  "total_bytes": 734003200,
  "item_count": 1,
  "found": [
    {
      "kind": "disk-image",
      "name": "Disk images",
      "path": "/Users/sam/Downloads/Editor.dmg",
      "recovery": "download",
      "bytes": 734003200,
      "age_days": 45,
      "selected": true
    }
  ],
  "skipped": [{ "path": "/Users/sam/Downloads/notes.dmg", "reason": "its content is not what its name says" }],
  "unreadable": []
}
  • folders are the folders that were looked in: Downloads and Desktop in the home folder, where they exist. Only their top level is read.
  • found is largest first and includes recent installers with "selected": false. total_bytes and item_count cover selected files only.
  • age_days is whole days since the file arrived or last changed, or null when that could not be worked out; such files are not selected.
  • --min-age <days> changes what is selected (default 7; 0 selects everything).
  • skipped lists entries named like an installer that were left alone. Files with other names are not mentioned at all. A Desktop or Downloads folder that a cloud service keeps in sync is in skipped too, with synced_by naming the service; it is then missing from folders, because it was not looked in.

dkit installers --yes --json prints the same shape as dkit clean --yes --json. freed_* is always zero: installers are held, and there is no --release or --hold here. dkit installers --kinds --json prints an array of kinds, each with id, extensions, name, description, recovery and proof.

dkit completion <shell> prints a shell script, not JSON, whatever options are given. See Completion.

dkit uninstall --list --json prints an array of apps, each with name, bundle_id, version, path and blocked (null, or the reason it cannot be removed).

dkit uninstall <app> --dry-run --json

{
  "dry_run": true,
  "app": { "name": "Chat", "bundle_id": "com.example.chat", "version": "3.1", "path": "/Applications/Chat.app", "blocked": null },
  "total_bytes": 412000000,
  "item_count": 3,
  "items": [
    { "path": "/Applications/Chat.app", "what": "The app", "matched": "app", "recovery": "download", "bytes": 400000000, "is_dir": true, "selected": true },
    { "path": "/Users/sam/Library/Preferences/com.example.chat.plist", "what": "Settings", "matched": "id", "recovery": "never", "bytes": 4096, "is_dir": false, "selected": true }
  ],
  "unreadable": []
}
  • matched is app, id (named exactly by the identifier), id-related (identifier plus an ending, or a team prefix) or name. Items matched by name always have "selected": false and are never removed.
  • When app.blocked is set, nothing is selected and dkit uninstall <app> --yes fails.
  • dkit uninstall <app> --yes --json prints the same shape as dkit clean --yes --json. An app’s settings and data go with it, so show the preview first.

With more than one app named, the preview has a different shape: the same object per app, under apps, and the totals of all of them.

{
  "dry_run": true,
  "total_bytes": 520000000,
  "item_count": 5,
  "apps": [
    { "app": { "name": "Chat", "bundle_id": "com.example.chat", "version": "3.1", "path": "/Applications/Chat.app", "blocked": null }, "total_bytes": 412000000, "item_count": 3, "items": [], "unreadable": [] },
    { "app": { "name": "Notes", "bundle_id": "org.sample.notes", "version": "1.4", "path": "/Applications/Notes.app", "blocked": null }, "total_bytes": 108000000, "item_count": 2, "items": [], "unreadable": [] }
  ]
}
  • One app named gives the single shape above, without apps. Check for apps if you pass a list that may hold one name or several.
  • Every app is found before anything is removed. If one is not found, matches several apps or has blocked set, --yes fails, the error says which, and nothing has changed. The preview still succeeds for a blocked app, with nothing of it selected.
  • dkit uninstall <app> <app> --yes --json makes one run: one run_id, and one dkit undo puts every app back.

dkit undo --json

{
  "run_id": "20261128-153045",
  "restored_bytes": 13314398618,
  "restored_count": 66,
  "kept": [],
  "held_bytes": 0,
  "held_count": 0
}
  • kept lists items that could not be put back, each with a reason. They stay in holding.
  • held_* is everything the run still holds afterwards: kept, plus items that were not asked for.
  • With paths, every path must match something the run holds, either an item’s own path or a folder above it. Otherwise the command fails and nothing is put back.

dkit history <run-id> --json prints one run: id, created_unix, state and items. Each item has original (where it was), bytes, rule_id and a status whose state is held, restored, released or failed.

dkit history --json prints an array of runs, newest first. Each has id, created_unix, state (held, restored or released) and items. A run is held while any of its items is; each item carries its own status.

dkit keep --json, also printed by keep add and keep remove:

{
  "file": "/Users/sam/Library/Application Support/Deskit/keep.txt",
  "paths": ["/Users/sam/.cache/huggingface"],
  "added": ["/Users/sam/.cache/huggingface"],
  "removed": [],
  "unchanged": []
}

paths is the list as it now stands. unchanged holds paths given that changed nothing: already listed, or not on the list. Items a clean leaves alone because of the list appear in skipped (dry run) or failed with the reason on your keep list or contains something on your keep list.

dkit release --yes --json prints an array of { "run_id", "bytes", "items" }, one per run released.

dkit status --json has host, cpu, memory, disks, disk_io, networks, battery, temperatures, process_count and top_processes.

{
  "disks": [{ "name": "Macintosh HD", "mount_point": "/", "total_bytes": 994662584320, "available_bytes": 415000000000, "used_bytes": 579662584320, "removable": false, "file_system": "apfs", "io": { "read_bytes_per_sec": 16384, "written_bytes_per_sec": 559927 } }],
  "disk_io": { "read_bytes_per_sec": 16384, "written_bytes_per_sec": 559927 },
  "battery": { "charge_percent": 57.0, "state": "discharging", "on_mains": false, "time_to_empty_secs": 16140, "time_to_full_secs": null, "cycle_count": 36, "health_percent": 99.8 },
  "temperatures": [{ "label": "PMU tdie1", "celsius": 37.1 }, { "label": "NAND CH0 temp", "celsius": 35.0 }]
}
  • battery is null on a machine with no battery, and on Windows for now. disk_io and a disk’s io are null when the system gives no counters. temperatures is empty when the machine reports no sensors.
  • A missing reading is null or absent, never 0. Do not turn null into zero, and do not report it as a fault: it means the system did not say.
  • state is charging, discharging, full, not_charging or unknown. The two times are the system’s own estimates and are often null.
  • The battery is read at most every 30 seconds and temperatures every 5, so several lines of --watch in a row can carry the same reading. See System status.

dkit status --json --watch prints that same object again and again, each on one line (JSON Lines), every --interval seconds (default 2, at least 0.2), each line sent as soon as it is taken:

dkit status --json --watch --interval 5 --count 12   # one minute, then exit
dkit status --json --watch | while read -r line; do ...; done
  • It ends with exit code 0 after --count lines, or when its reader closes the pipe. Otherwise it runs until it is interrupted.
  • The first line arrives after about 0.2 seconds and is measured over that window, as the one-off report is. Later lines cover the interval before them.
  • Without --json it is refused. See System status.

dkit update --check --json and dkit update --yes --json have current, latest, state (up_to_date, available, updated, ahead or managed), path, origin (standalone, homebrew, cargo or build) and command. A copy that Homebrew or cargo installed is never replaced: state is managed, command is what to run instead, and the exit code is 0. See Update.

dkit remove --dry-run --json has dry_run, data_dir, items, total_bytes, the held_* counts of what undo would lose, left_alone and program. dkit remove --yes --json has removed, removed_bytes, data_dir_removed, program_removed, failed and program. See Remove.

dkit doctor --json has checked_unix, checks and limits. Each check has id, title, state (ok, note or unknown), summary, items and advice. The exit code is 0 whatever the checks say. See Doctor.

dkit analyze --json has root, total_bytes, file_count, dir_count, unreadable, entries and largest_files. entries are the direct children of root, largest first. Each has name, path, bytes, is_dir and file_count, and one that a cleanup command covers also has covered_by:

{ "name": "node_modules", "path": "/Users/sam/code/shop/node_modules", "bytes": 4294967296, "is_dir": true, "file_count": 48211,
  "covered_by": { "command": "purge", "id": "node-modules", "name": "Node packages", "on_by_default": true } }
  • command is clean or purge; id is the cleanup rule or the purge kind. on_by_default is false for a cleanup rule that only runs with --include <id>.
  • covered_by means the location is covered, not that the entry would be removed. Age limits, a running app, project activity and the keep list are only worked out by a preview. Follow a mark with dkit clean --dry-run --json (adding --include <id> when on_by_default is false) or dkit purge <folder> --dry-run --json on the folder that holds the project, and go by what that lists.
  • An entry without the field is covered by neither. Only the entry itself is judged, not what is inside it.

All sizes are in bytes. Field names may still change before version 1.0.

From docs/automation.md at v0.1.0-alpha.2.