Use to install, update, or authenticate the Apiiro CLI, verify its version and available features, offer the optional prevention hooks, or when an apiiro command fails with not found or auth errors.
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Guardian Setup?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/apiiro-guardian-setup)
---
name: guardian-setup
description: "Use to install, update, or authenticate the Apiiro CLI, verify its version and available features, offer the optional prevention hooks, or when an apiiro command fails with not found or auth errors."
---
You are setting up Apiiro. Do the following in order and confirm each step.
Steps 1, 4, 6 and 7 make lasting changes to the user's machine. Before each one, tell the user what it will install or change and where, and run it only after they agree. If they decline, skip that step and continue with the next one. Steps 2, 3, 5 and 8 only sign in or read state.
The CLI keeps itself on the version the organization selects in Apiiro. Most `apiiro` commands, including the feature checks in step 5 and the dry run in step 6, can first download that version and refresh installed hooks, restoring any hook entry that is missing or outdated; `login`, `auth`, `update` and `doctor` never do. Before the first such command, tell the user this and continue only after they agree. If they would rather keep the current version, they can run `apiiro update --disable` first.
## 1. Install Apiiro CLI
- Check if installed: `which apiiro`
- If already installed, skip to step 2
- If it is not installed, ask the user before installing it: the CLI is a program placed on their PATH. If they agree, follow [install.md](install.md) in this skill's directory: it installs a pinned release and verifies its checksum. If that file is not there, point the user to the install instructions at https://github.com/apiiro/marketplace#installation and let them install it themselves. Tell them the install script there also adds the Apiiro skills to every coding agent it finds
## 2. Authenticate with Apiiro
- Tell the user that signing in saves their Apiiro credentials on this machine, so later commands stay signed in until they run `apiiro logout`
- Run: `apiiro login`
- This opens a browser window — sign in with your Apiiro account
- If the usual browser sign-in cannot complete (no browser opens, or the local callback is blocked), run `apiiro login --device` and enter the printed code in any browser instead
## 3. Verify authentication
- Run: `apiiro auth status`
## 4. Check for a newer version
- Run: `apiiro update --check`
- The CLI updates itself to the version the organization selects in Apiiro, for every install method (Homebrew and npm included); tell the user this. If a newer version is available, ask before running `apiiro update` to install it now; an update also refreshes installed hook files. Saying no only skips updating now: other `apiiro` commands still update it unless automatic updates are off
- If automatic updates are off on this machine (`APIIRO_AUTO_UPDATE=off` or `apiiro update --disable`), say so; `apiiro update --enable` turns them back on
## 5. Check available features
Probe which features are enabled for the user's environment. Run these commands and collect results:
```bash
# Fast Scan (secrets + OSS) — fetches the tenant's scan configuration
apiiro fast-scan config 2>&1
# Guardian
apiiro ask "test" --global 2>&1
# Threat Modeling
apiiro threat-model "test" 2>&1
```
For each command, check the output:
- If it contains "not enabled" → the feature is **not available** in this environment
- Otherwise → the feature is **available**
`-f/--file` is an output flag on every command (it saves the result to a file), so do not pass it to probe a feature.
Present a summary table to the user showing which features are enabled and which are not. For disabled features, note: "Contact your Apiiro administrator to enable this feature."
## 6. Offer prevention hooks
`apiiro init` detects Claude Code, Cursor, GitHub Copilot CLI, OpenAI Codex, and opencode, and installs the skills and the prevention hooks (session context, prompt enrichment where the host supports it, and commit scanning) into each one's configuration. In Claude Code it adds the Apiiro marketplace and enables the Apiiro prevention plugins in `~/.claude/settings.json`. The hooks send the user's prompts, the files a commit scan checks, and commit details to their Apiiro tenant (privacy: https://github.com/apiiro/marketplace#privacy--telemetry, support: https://support.apiiro.com). This is a lasting change to those agents, so offer it; never run it unasked:
- First run `apiiro init --dry-run` and show the user which agents and files it would change. Ask whether to install, and for which agents (`--claude`, `--cursor`, `--copilot`, `--codex`, `--opencode` limit it to one host; `--skills-only` skips the hooks)
- Only after the user agrees, run `apiiro init` with the options they chose, then `apiiro doctor` to verify the result. Tell them `apiiro uninstall` removes what it installed. The Codex and Copilot CLI hooks need a 2026.09.09 or newer CLI — upgrade first if `apiiro --version` is older
- Claude Code, Codex, and opencode enrich each prompt; Cursor and Copilot CLI get session context plus commit scanning, because neither host's prompt hook can inject context
- Codex runs a hook only after it is trusted once: tell the user to run `codex` in a terminal, type `/hooks`, and trust each Apiiro entry. Until then Codex skips the hooks silently, and a changed or newly added entry (for example after `apiiro hooks update`) needs trusting again
- If you are running from the Apiiro Claude Code plugin, Claude Code already has the skills: when the user declines the hooks, offer nothing more for Claude Code
- For skills without prevention hooks in other agents, offer `apiiro agents install` instead and run it only after the user agrees (`--agent claude|cursor|copilot|codex|opencode` for one host, `--all` for every known host); `apiiro agents status` shows what is installed
- If anything was installed, tell the user to restart Claude Code
## 7. Offer status line setup (Claude Code only)
Apiiro can add a 🛡️ shield to the Claude Code status line that appears when Apiiro Guardian is active.
**Do NOT modify `~/.claude/settings.json` or any scripts directly.** Instead, explain what the status line does and ask the user if they'd like to set it up. If they agree, use the `statusline-setup` agent to configure it.
Tell the user:
- The shield icon (🛡️) appears in the Claude Code status line when Apiiro Guardian is active in the current session
- It requires adding a `statusLine` entry to `~/.claude/settings.json`
- If they already have a custom status line, the Apiiro check will be appended to their existing script (a backup of the original script will be created first)
If the user wants to proceed, delegate to the `statusline-setup` agent with these details:
### Case A: No existing status line, or one left by an earlier Apiiro setup
Earlier versions pointed `statusLine.command` at `${CLAUDE_PLUGIN_ROOT}/scripts/statusline.sh` or `statusline.ps1`, which the plugin no longer ships, so that status line is now blank. Treat such a command as no status line: replace it with the one below.
Create the script that matches the user's OS, then add the `statusLine` entry to `~/.claude/settings.json`.
**macOS / Linux:** write `~/.claude/apiiro-statusline.sh` and make it executable (`chmod +x`):
```bash
#!/usr/bin/env bash
input=$(cat)
SESSION_ID=$(printf '%s' "$input" | jq -r '.session_id // empty' 2>/dev/null)
SESSION_FILE="$HOME/.apiiro/sessions/$SESSION_ID"
MAX_AGE=600
if [ -n "$SESSION_ID" ] && [ -f "$SESSION_FILE" ]; then
MTIME=$(stat -f %m "$SESSION_FILE" 2>/dev/null || stat -c %Y "$SESSION_FILE" 2>/dev/null || echo 0)
[ $(($(date +%s) - MTIME)) -lt $MAX_AGE ] && echo "🛡️ Apiiro Guardian Activated"
fi
```
```json
{
"statusLine": {
"type": "command",
"command": "~/.claude/apiiro-statusline.sh"
}
}
```
**Windows:** write `%USERPROFILE%\.claude\apiiro-statusline.ps1`, then put its absolute path (for example `C:\Users\<name>\.claude\apiiro-statusline.ps1`) in the command:
```powershell
$inputText = [Console]::In.ReadToEnd()
$SessionId = ''
try { $SessionId = ($inputText | ConvertFrom-Json -ErrorAction Stop).session_id } catch { }
if (-not $SessionId) { exit 0 }
$SessionFile = Join-Path $HOME ".apiiro/sessions/$SessionId"
if (Test-Path -LiteralPath $SessionFile -PathType Leaf) {
$age = (Get-Date).ToUniversalTime().Subtract((Get-Item -LiteralPath $SessionFile).LastWriteTimeUtc).TotalSeconds
if ($age -lt 600) { Write-Output ([char]::ConvertFromUtf32(0x1F6E1) + [char]0xFE0F + " Apiiro Guardian Activated") }
}
```
```json
{
"statusLine": {
"type": "command",
"command": "powershell -ExecutionPolicy Bypass -File \"<absolute path of apiiro-statusline.ps1>\""
}
}
```
### Case B: User already has a custom status line script
**First, back up the existing script** by copying it to `<script-path>.bak` before making any changes.
Then find the script file referenced in the existing `statusLine.command` setting and append the Apiiro shield check to the **end** of that script. The check should use the same stdin JSON variable the script already captures (commonly `$input`):
```bash
# Apiiro shield
SESSION_ID=$(echo "$input" | jq -r '.session_id // empty')
SESSION_FILE="$HOME/.apiiro/sessions/$SESSION_ID"
MAX_AGE=600
if [ -n "$SESSION_ID" ] && [ -f "$SESSION_FILE" ]; then
MTIME=$(stat -f %m "$SESSION_FILE" 2>/dev/null || stat -c %Y "$SESSION_FILE" 2>/dev/null || echo 0)
[ $(($(date +%s) - MTIME)) -lt $MAX_AGE ] && echo "🛡️ Apiiro Guardian Activated"
fi
```
**Important:** Claude Code pipes a JSON object to the status line script via stdin. The script must read stdin once (e.g., `input=$(cat)`) and parse fields from that variable. Do not read stdin again for the Apiiro check — reuse the existing variable. Check the script to confirm the variable name before appending.
## 8. Verify and finish
- Run: `apiiro doctor` — checks CLI version, auth, per-agent skills, plugin status, hook integrity, pre-commit hook, and hook toggles in one report
- Explain anything it flags. For a repair that changes the user's files or settings, say what it changes and run it only after the user agrees
Tell the user they are all set! Summarize:
- Which features are available in their environment
- The `guardian-*` skills they can invoke from the agent (ask the agent to list available skills if they want a tour)