/semgrep:install-mfwfrom Semgrep Guardian
Installs and configures the mfw (Semgrep Malware Firewall) CLI — a local MITM proxy that gates package-manager downloads on Semgrep's backend. Handles trust store, PATH shims, shell integration, and background daemon setup, with care for managed dotfiles.
Ships in Semgrep Guardian. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
Install and set up the mfw client — Semgrep's Malware Firewall, a local MITM proxy that gates package-manager downloads (pip / npm / pnpm / uv / cargo / maven / gem / nuget / composer / go) on Semgrep's backend before bytes hit disk.
$ARGUMENTS may carry a backend/dist URL override (e.g. https://example.semgrep.dev)
or --store system. Default backend is https://semgrep.dev (mfw is distributed
off prod). If empty, use the defaults.
Your job: drive the install end to end, ask the user only at genuine decision
points (via AskUserQuestion), and — the part that needs care — never edit a
managed (symlinked) shell rc file in place. Work through the steps in order.
The installer downloads + checksum-verifies the binary to ~/.local/bin/mfw, then
mfw fixup: ① generates a local CA and adds it to the OS trust store (plus, on
macOS with Homebrew present, into Homebrew's openssl trust dir), ② drops
package-manager shim symlinks in ~/.semgrep/mfw/shims, ③ writes
~/.semgrep/mfw/rc-setup.sh (PATH + proxy/CA env) and makes your shell source
it, ④ installs a background daemon (launchd/systemd/openrc — skipped inside
containers with no service manager) that runs the proxy and, via mfw supervise,
auto-updates mfw on a schedule (on by default). Undo anytime with
mfw uninstall (which also deletes the mfw binary). It is a real,
system-modifying install — make sure the user is on
board before you run it (they invoked this skill, so a brief summary + proceeding
is fine; only stop for the choices below).
uname -s and uname -m. Supported: Linux x86_64/aarch64, macOS
arm64 (Apple silicon). If it's Windows, or Intel macOS, stop: there is no
published build — tell the user plainly.command -v curl (or wget). If neither, stop and say so.command -v mfw — if already installed, this is an idempotent re-run / upgrade;
carry on (fixup self-heals).Run the inspector and parse it (do not dump it on the user):
sh ${CLAUDE_SKILL_DIR}/scripts/inspect-shell-config.sh
For the user's login_shell, look at its rc file(s): zsh → ~/.zshrc; bash →
~/.bashrc plus ~/.bash_profile or ~/.profile. Decide managed vs plain:
symlink=yes (any class: nix, chezmoi, git-dotfiles,
unknown) or class=nix-generated (a real file with a "Generated by Home
Manager/Nix" header). These are owned by a tool; editing the deployed file is
wrong — it's read-only (nix) or gets reverted on the next rebuild/apply.Why this gate exists:
mfw fixupwrites its one-line hook with an atomicrename()over the rc file, which replaces a symlink with a regular file — clobbering a nix/home-manager-managed rc. So managed rc files must never be edited in place; mfw's one-line hook goes into the user's source-of-truth instead.
Remember the result; it decides Step 3 and Step 4.
If the shell config is PLAIN (and you don't otherwise need the managed path),
use the standard installer — it downloads, verifies, and runs mfw fixup, correctly
editing the real rc file:
curl -fsSL https://semgrep.dev/dist/mfw/install.sh | sh
(Swap the host if $ARGUMENTS/env gave an override: …/<host>/dist/mfw/install.sh.)
install.sh reconnects a TTY (mfw fixup </dev/tty) so a human running it in a
terminal gets the interactive prompts, and falls back to mfw fixup --yes when
there's no controlling terminal. When you run this line through the Bash tool
there's no TTY, so it takes the --yes path: fixup auto-accepts and edits the
real rc file at mfw's best-guess paths — exactly what we want for a plain config.
If the shell config is MANAGED, do not run the bundled fixup (it would clobber the symlink). Install the binary only, then drive fixup with shell edits turned off:
sh ${CLAUDE_SKILL_DIR}/scripts/install-binary.sh
~/.local/bin/mfw fixup --skip-login
mfw fixup here runs non-interactively (no TTY), so it writes
~/.semgrep/mfw/rc-setup.sh, installs certs/shims/daemon, and prints the
shell lines instead of editing your rc — exactly what we want. We handle login in
Step 6 and the shell hook in Step 4. (Pass an override URL with
--backend-url <url> if one was given.)
Use ~/.local/bin/mfw for subsequent calls in case ~/.local/bin isn't on PATH
in this session yet.
Skip this whole step for plain configs (the installer already did it). For managed configs, the only thing the user's shell needs is this exact hook, which sources mfw's self-managed env file:
[ -r "$HOME/.semgrep/mfw/rc-setup.sh" ] && . "$HOME/.semgrep/mfw/rc-setup.sh"
This single line is exactly what mfw doctor looks for (a trimmed line match — no
comment markers). Now find where it belongs and ask the user with AskUserQuestion,
offering the candidate= paths the inspector found plus an "Other" path:
class=nix or nix-generated): add the hook to the
shell-init attribute, e.g. programs.zsh.initContent (newer) or
initExtra/programs.bash.initExtra/bashrcExtra; on NixOS
programs.zsh.interactiveShellInit. If they instead manage the file wholesale
(home.file.".zshrc".text = ''…''), append the hook inside that string. A bare
$HOME is literal in nix strings (interpolation is ${…}), so the line is safe
verbatim; if you're inside a ''…'' block and the linter complains about ${,
there is none here, so no escaping is needed. After editing, tell the user to
rebuild: home-manager switch / darwin-rebuild switch / sudo nixos-rebuild switch.class=chezmoi): edit the source, not the deployed file —
chezmoi edit ~/.zshrc opens it, or edit the matching dot_zshrc in
~/.local/share/chezmoi; append the hook, then chezmoi apply.class=git-dotfiles): the resolved= path IS
the real file in the repo (the symlink points straight at it). Append the hook
there with Edit, then remind the user to commit. No relink needed.link_target/resolved path, ask the user where the
source-of-truth is, and edit that.Read the target file first, then make a minimal Edit that inserts the hook in the right place (inside the right nix attribute / at the end of the rc source). Confirm the destination with the user before writing if there's any ambiguity.
AskUserQuestion whether to install the CA into the system store
(needs sudo): sudo mfw install-certs --store system. If they decline, note that
gated downloads will fail TLS verification until it's trusted.mfw install-certs themselves and approve the prompt. (Homebrew's openssl
trust is handled by fixup automatically when brew is present.)mfw runs without login — unauthenticated requests just follow the configured
fail-open/closed policy — but it can't actually scan until authenticated. Check
the login line in mfw doctor (Step 7). If not authenticated, ask whether to log
in now. mfw login opens a browser OAuth flow you can't complete for them, so
have them run it in this session: suggest they type ! mfw login (or set
SEMGREP_APP_TOKEN). Don't block the rest of fixup on it.
mfw doctor (use ~/.local/bin/mfw doctor if needed). Walk the user
through anything still ✗. For managed configs the shell line stays ✗ until they
restart their shell (and, for nix, rebuild first). Doctor also prints a few
informational lines that aren't failures: a version/update check
(up to date / update available … run mfw upgrade), whether auto-update is
disabled, and whether the supervisor is running — don't treat those as ✗.exec "$SHELL" -l or a new terminal —
then re-run mfw doctor; it should print the "Semgrep mfw is protecting this
machine." banner (a green ○○○ logo + a little watching face whose eyes are
randomized each run). If
they're not logged in the headline is instead "mfw can't scan anything until
you authenticate — run mfw login" (see Step 6); other steps can still be ✓.
If they're signed in but their Semgrep deployment doesn't have the Semgrep
malware firewall enabled, the login line is ✗ and the headline is "the Semgrep
malware firewall isn't enabled for your Semgrep deployment. Enable it in Semgrep
or ask your org admin." — that's a backend entitlement issue, not a fixup step,
so re-running mfw fixup won't fix it.~/.semgrep/mfw/, shims on PATH,
the managed daemon), and that mfw uninstall reverses everything (and deletes
the mfw binary). mfw keeps
itself updated via the supervisor (auto-update on by default); mfw upgrade
forces it now and mfw restart bounces the daemon.curl … | install.sh | sh line modifies the system — it's expected to need one
confirmation; let it.Edit them all? [Y]es / [n]o, show me the line to add myself / [s]kip, and
per-file it's Apply to <path>? [Y]es / [n]o, I'll do it myself / [s]kip. The
default is yes (Enter applies the edit); n immediately prints the source
line to paste yourself, s skips.
Because your Bash-tool calls have no TTY, mfw fixup runs non-interactively: it
still writes rc-setup.sh, installs certs/shims/daemon, and prints (never
edits) the rc lines — which is exactly why the managed-config path in Step 3 works.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
mfw, semgrep, malware-firewall, package-manager-security, mitm-proxy
npx claudepluginhub semgrep/guardian --plugin semgrep5 skills in this plugin
/add-and-validate-guardian-developer-semgrep-rulewrite a custom semgrep rule with the user, add it to guardian in either user or repo scope, and prove it fires by writing a file that should trip it. use when someone wants guardian to catch something it currently misses, asks to write or add a semgrep rule, or wants a project convention enforced on the code claude writes./recommend-guardian-policy-rulesRecommend Semgrep rules to add to the organization's Guardian policy for a repository — pull the rules Guardian runs now, gather candidates from the repo's existing findings and the org's custom rules, rank them for Guardian, let the user pick, and turn the picks on through the Semgrep MCP. Use when someone wants Guardian to catch more, asks which rules Guardian should run, or wants to tune or customize the Guardian policy for a repo./reconnectRe-check Semgrep Guardian's connection and recover it — verify the credential live, and log in again if it is expired. Use when Guardian reported that it timed out checking credentials or could not reach Semgrep, when scans seem not to be running, or when the user asks to reconnect Guardian./remove-guardian-developer-semgrep-ruleRemove a custom Semgrep rule from Guardian — list what is installed, work out which file holds the rule, and delete or edit it out of the user or repo rules directory. Use when someone wants Guardian to stop flagging something, asks to remove, delete or disable a custom rule, or wants to clear room under the rule limit.Other plugins' skills for the same job