# KarmaDue for Amp: check package installs before a shell command runs

Amp has no shell hooks; it has plugins. A plugin's `tool.call` handler runs before each tool call and returns `allow` or `reject-and-continue` (Amp plugin docs: https://ampcode.com/docs/customize/plugins and <https://ampcode.com/docs/plugin-api>, read 2026-11-15). This plugin takes the shell command Amp is about to run, asks KarmaDue about the npm and PyPI packages in every step of it, and:

- **blocks** a known-bad package (reject-and-continue, with KarmaDue's reason sent back to the agent);
- **asks** with an Amp confirm dialog when your person should decide (for example an unverified package name). With no UI to show it (for example `amp -x`), it blocks, because nobody can answer;
- allows everything else.

## Setup (2 steps)

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

       curl -fsSL https://karmadue.expo.app/guard/install.sh | KARMADUE_NO_SHIMS=1 sh

2. Install the plugin for all projects on this machine, then run `plugins: reload` in Amp:

       mkdir -p ~/.config/amp/plugins && curl -fsSL https://karmadue.expo.app/recipes/amp/karmadue.ts -o ~/.config/amp/plugins/karmadue.ts

   (Amp's docs also describe `amp plugins add <url>` for single-file plugins; we haven't run it.) For one project only, save it as `.amp/plugins/karmadue.ts`.

Set `KARMADUE_STRICT=1` in Amp's environment to block, not allow, when the guard is missing or KarmaDue can't be reached. Only package identifiers (for example `npm:postmark-mcp@1.0.18`) leave the machine, not the command line. The plugin is 50 lines; read it before you load it.

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

The plugin file was run under Bun (Amp runs plugins with Bun) against a stand-in for Amp's plugin API that passes the command through, with the guard installed. **Not run inside Amp** (no Amp login here), so Amp's own `shellCommandFromToolCall` helper and dialogs were simulated.

| Command | Plugin answer |
| --- | --- |
| `npx -y postmark-mcp@1.0.18` | reject-and-continue: postmark-mcp@1.0.18 malicious |
| `echo ok && npx -y postmark-mcp@1.0.18` | reject-and-continue (the second step is checked) |
| `cd x; npm i postmark-mcp@1.0.18` | reject-and-continue |
| `pip install reqeusts` | confirm dialog; Run anyway → allow, decline → reject; no UI → reject |
| `npm install is-number@7.0.0`, `ls -la` | allow |
| Non-shell tool (e.g. Read) | allow, not checked |
| KarmaDue unreachable | allow plus a NOT CHECKED line in the plugin log; with KARMADUE_STRICT=1, reject |
| Guard not installed | allow plus a NOT CHECKED line in the plugin log; with KARMADUE_STRICT=1, reject |

## 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 allow from this plugin; Amp's own permissions still apply.
- Not yet tested inside a live Amp session, and fail-open by default: without KARMADUE_STRICT, a missing guard is logged, not shown in a dialog. If it behaves differently in Amp, 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
