# KarmaDue for Factory Droid: check package installs before Execute runs

Factory Droid runs `PreToolUse` hooks before each tool call and reads the same `hookSpecificOutput.permissionDecision` JSON as Claude Code. This hook takes the shell command Droid is about to run (tool `Execute`), asks KarmaDue about the npm and PyPI packages in every step of it, and answers **deny** for a block.

One difference from Claude Code matters: in Droid, `ask` does not stop the call. It falls back to normal permissions, so at higher autonomy levels a call Droid would run without asking still runs. So this script turns KarmaDue's ask (for example an unverified package name) into **deny** with the reason "ask your person first". Stricter, on purpose.

## Setup (2 steps)

1. Install the guard files (no account, no shims) and the hook script:

       curl -fsSL https://karmadue.expo.app/guard/install.sh | KARMADUE_NO_SHIMS=1 sh
       curl -fsSL https://karmadue.expo.app/recipes/factory-droid/karmadue-droid-hook.sh -o ~/.karmadue/karmadue-droid-hook.sh && chmod +x ~/.karmadue/karmadue-droid-hook.sh

2. Add this to `~/.factory/hooks.json` (or `<repo>/.factory/hooks.json`). Droid's docs ask for absolute paths, so replace `/home/you` with your home directory:

```json
{
  "PreToolUse": [
    { "matcher": "Execute", "hooks": [
      { "type": "command", "command": "/home/you/.karmadue/karmadue-droid-hook.sh", "timeout": 30, "onFailure": "block" }
    ] }
  ]
}
```

If you keep hooks in `~/.factory/settings.json` instead, wrap the same map in a top-level `"hooks"` key. `"onFailure": "block"` makes a missing or crashed guard (or a timeout) deny the call instead of letting it run; leave it out if you prefer fail-open. Add `--fail closed` after the script path to also deny when KarmaDue can't be reached. Only package identifiers (for example `npm:postmark-mcp@1.0.18`) leave the machine, not the command line.

Check the install with a known-bad command (it should print a deny):

    echo '{"hook_event_name":"PreToolUse","tool_name":"Execute","tool_input":{"command":"npx -y postmark-mcp@1.0.18"}}' | ~/.karmadue/karmadue-droid-hook.sh

## What happened when we ran it (2026-11-15, 15:48 UTC)

Droid-shaped stdin, fed to the script on a test machine with the guard installed. Not run inside Droid itself (no Droid login here); the input and output fields follow Droid's hooks reference at https://docs.factory.com/harness/hooks as read on 2026-11-15.

| Command (tool) | Script answer |
| --- | --- |
| `npx -y postmark-mcp@1.0.18` (Execute) | deny: postmark-mcp@1.0.18 malicious |
| `echo ok && npx -y postmark-mcp@1.0.18` | deny (the second step is checked) |
| `cd x; npm i postmark-mcp@1.0.18` | deny |
| `pip install reqeusts` | deny, "ask your person first" (KarmaDue's ask, turned into deny) |
| `npm install is-number@7.0.0` | no decision, so Droid's normal permissions apply |
| `ls -la` | no output (no packages) |
| postmark command sent as tool `Read` | no output (only Execute is checked) |
| KarmaDue unreachable | no decision plus a "NOT CHECKED" warning (fail-open unless `--fail closed`) |
| Guard not installed | exit 1 with the reason on stderr: blocks with `onFailure: block`, otherwise Droid shows an error and runs the call |
| Missing command field or unreadable input | no decision plus a "NOT CHECKED" warning |

## Limits

- Checks npm and PyPI packages in the command. Other steps of a chained command are not judged, so `npm i is-number && rm -rf /` gets no decision from this hook; Droid's own permissions still apply to it.
- Not yet tested inside a live Droid session. If Droid's hook input differs from its docs, tell us on the forum: https://karmadue.expo.app/forum

More: all hooks <https://karmadue.expo.app/docs/hooks.md>, recipes <https://karmadue.expo.app/recipes/index.md>, check one install by hand with check_install (https://karmadue.expo.app/docs/any-agent.md), and shared fixes in the knowledge trees https://karmadue.expo.app/trees
