# SecureNow CLI — Agent Skill

> **Node.js security:** Use a supported, patched runtime: Node.js 22.23.4+, 24.22.1+, or 26.12.1+ on its respective release line. Earlier patches are affected by [CVE-2026-111497](https://nodejs.org/en/blog/vulnerability/october-2026-security-releases). Upgrading the SecureNow package does not patch Node.js; upgrade the runtime and restart every application process.

The `securenow` CLI runs SecureNow from the terminal: set up an app, see what is attacking it, investigate an address, block, rate-limit, challenge, revoke sessions, write and test detection rules, work the review queues, and run the MCP server for coding agents. It describes securenow 8.24.0; items marked **(8.25.0+)** need 8.25.0 or newer. Wiring the SDK into an app is covered by [SKILL-API.md](./SKILL-API.md).

- `npx securenow help` lists every command; `npx securenow help <command>` shows its subcommands and flags. Both work offline: check a flag there before using it.
- Most read commands take `--json` for machine-readable output and `--app <key>` / `--env <environment>` to pick the target.
- Write commands act on production apps within about 10 seconds. Ask the person first; `--yes` (or `--force`) only skips the prompt after they agreed.
- Never print `.securenow/*.json` files or full `snk_live_` keys.

## Before you start

### Install

```bash
npm install securenow@latest      # in the project; run commands with npx securenow <command>
npm install -g securenow          # or globally: securenow <command>
npx securenow version
```

### Authenticate

```bash
npx securenow login          # browser: admin auth + the app's runtime config (run from the project root)
npx securenow admin login    # admin/control-plane auth only (CLI and MCP)  [--token <TOKEN>] [--global]
npx securenow app connect    # runtime only: pick/create the app, mint the runtime API key  [--global]
npx securenow whoami         # both lanes
npx securenow logout         # clears admin auth; the runtime config stays  [--global]
```

Two lanes, two files: `.securenow/admin.json` (admin token for the CLI and MCP) and `.securenow/runtime.json` (app key, runtime API key `snk_live_...`, SDK config). `--global` writes to `~/.securenow/` instead of the project. Both files are secrets; the CLI adds them to `.gitignore` without ignoring the whole `.securenow/` folder. Never open an auth URL yourself: the CLI generates the callback.

### Pick the app and the environment

- One app key serves every environment. Traces, logs, firewall rules, forensics and alerts are scoped by `config.runtime.deploymentEnvironment` (`production`, `staging`, `preview`, `local`...).
- CLI security commands default to `production`. `npx securenow init` writes `local` for a development machine, so use `--env local` (or `--env all` where accepted) to see local traffic.
- `--app <key>` targets another app. `npx securenow apps default <key>` (or `npx securenow config set defaultApp <key>`) sets the default.

## Tasks

### Set up SecureNow in a project

```bash
npm install securenow@latest
npx securenow login
npx securenow init            # [--env local] [--key snk_live_...] [--ts|--js] [--src|--root] [--force]
npx securenow doctor && npx securenow test-span
```

`init` detects the framework, fills `.securenow/runtime.json`, writes the Next.js instrumentation file and config, and prints the start-script change for plain Node. The full wiring per framework is in SKILL-API.md.

### Production credentials

```bash
npx securenow credentials runtime --env production                 # writes .securenow/credentials.production.json
npx securenow credentials runtime --env production --format env    # prints SECURENOW_CREDENTIALS=<base64>
npx securenow credentials runtime --env staging --out deploy/securenow.json
npx securenow credentials runtime --env production --stdout        # JSON to stdout
```

The file carries the app key, the runtime API key and the SDK config, never the admin token. Mount it as `<app-root>/.securenow/credentials.json`, or store the `--format env` line as a secret environment variable (Vercel, Railway, Render, Heroku, Fly, Kubernetes). Both contain the runtime API key.

Runtime key only:

```bash
npx securenow api-key create --name "CLI runtime"     # mint and save a key for the current app  [--app <key-or-id>] [--global]
npx securenow api-key set snk_live_...                # save a key you already have  [--global]
npx securenow api-key show                            # masked key and its source
npx securenow api-key clear                           # remove the key only  [--global]
```

### Today's overview

```bash
npx securenow today                     # what happened, what SecureNow did, what needs you  [--since 24h|7d] [--attackers 8]
npx securenow status --env production   # apps, protection, unread alerts  [--app <key>] [--env local|production|all]
npx securenow analytics --app <key>     # response-code analytics
npx securenow logs errors --since 1h    # what is failing: errors grouped by message  [--warn] [--limit 20]
```

`today` is the dashboard's Overview: whether each app is covered (data flowing, firewall on, detection monitoring or blocking), attack requests and attackers, what the firewall stopped and what got through, decisions waiting, top attackers, and what SecureNow did. MCP: `securenow_overview`.

### Investigate an IP

```bash
npx securenow attacker 203.0.113.9                    # why it was flagged: verdict, signals, traffic vs normal, detections, timeline
npx securenow ip 203.0.113.9                          # geo, ASN, reputation, verdict
npx securenow ip traces 203.0.113.9 --env production  # its requests
npx securenow traces show <traceId> --env production  # one request: spans, headers, body (redacted)
npx securenow traces analyze <traceId>                # AI analysis of a trace
npx securenow firewall hits --ip 203.0.113.9 --since 24h   # what the firewall did to it
npx securenow agent verify 203.0.113.9                # the double-check the agent runs before acting (alert moment + 3 days)
npx securenow forensics chat --app <key> "what did 203.0.113.9 do in the last 24 hours?"
```

`forensics chat` runs discovery queries, shows its SQL and ends each answer with findings; continue with `--conversation <id> "<follow-up>"`. `npx securenow forensics "<question>"` answers one question without memory. Trust the result rows over the summary. MCP: `securenow_attacker`, `securenow_ip_lookup`, `securenow_ip_traces`, `securenow_forensics_chat`.

### Triage notifications

SecureNow decides most things alone (instant blocks, automations, IP investigations, rules that pause themselves). What it won't decide waits in two queues; work **Alert Review** first, because one rule fix closes every run it caused.

| Queue | Question | Decisions | CLI |
|---|---|---|---|
| Alert Review | "Is this rule right?" A rule fired far too wide, or on your own infrastructure; it usually paused itself | tune the rule, keep it on, close or dismiss with a reason (never blocks or unblocks) | `securenow review` |
| Requires Human | "What do we do about this IP or plan?" An investigated IP with a verdict SecureNow won't act on alone, or a proposed plan | block, false positive, close without blocking, approve or reject a plan | `securenow human` |

```bash
npx securenow notifications list --limit 20            # [--search <rule or IP>] [--severity critical|high|medium|low] [--page N]
npx securenow notifications unread
npx securenow notifications read <id>                  # or: read-all

npx securenow review                                   # open runs grouped by root cause
npx securenow review show 1                            # a group (row number or arc_ key) or one run (notification id)
npx securenow alerts rules change <rule-id> "ignore /healthz and raise the threshold to 20"   # fix the rule first
npx securenow review group 1 --outcome rule_tuning --reason "Guard added" --preview
npx securenow review group 1 --outcome rule_tuning --reason "Guard added" --yes
npx securenow review keep <notificationId> --reason "Correct detection" --yes
npx securenow review dismiss <notificationId> --reason "Not worth acting on" --yes

npx securenow human                                    # decisions waiting, most urgent first
npx securenow human show 1                             # AI report, proofs, investigation steps, trace links
npx securenow human block 1 --reason "Confirmed SQL injection with 2xx answers" --yes
npx securenow human fp 1 --reason "Partner webhook, scoped to /api/hooks" --yes
npx securenow human close 1 --outcome deferred --reason "Scanner, nothing reachable" --yes
npx securenow human action 1 --status rejected --reason "Exclusion too broad" --yes
```

Review outcomes: `rule_tuning`, `false_positive`, `clean`, `deferred`, `new_alert_rule`, `rate_limited`, `ambiguous`, `skipped`, `other`. A group whose rows disagree needs `--allow-mixed` after reviewing every row. `human report` only adds a note (the row stays); `human close` removes the row without enforcement; approving a `tune_rule` or `create_exclusion` plan with `human action` only records the decision (change the rule first); only `approve_block` blocks.

Each notification carries an `ipInvestigations` array; act only on IPs whose own `status` is `open`:

| Status | Meaning | Action |
|---|---|---|
| `open` | No determination yet | Investigate, then decide |
| `false_positive` | Dismissed by an exclusion, a verified bot or a trusted IP | Skip |
| `blocked` | Already on the blocklist | Skip |
| `clean` | Cleared as benign | Skip |

Prefer `metadata.matchedSubdetectors` over guessing which part of a rule fired from the title.

**False-positive exclusions** keep known-safe traffic from alerting. Keep them as narrow as the evidence (app, rule, path, method, status, user agent, body shape):

```bash
npx securenow fp ai-fill --description "Stripe webhook POST to /api/stripe/webhook" --context '{"method":"POST","path":"/api/stripe/webhook"}'
npx securenow fp dry-run --conditions '[{"field":"path","operator":"starts_with","value":"/api/stripe/webhook"}]'   # last 3 days
npx securenow fp create --conditions '[...]' --match-mode all --rule-scope any_rule --reason "Stripe webhook"
npx securenow fp create --path /api/events --method POST --path-safe standard --ua-safe standard --headers-safe standard --query-keys page,limit --reason "Event webhook"
npx securenow fp mark <notification-id> <ip> --rule-scope this_rule --reason "Known partner IP"
npx securenow alerts rules exclusions <rule-id> add --conditions '[...]' --reason "..."     # one rule only
npx securenow fp list | show <id> | edit <id> --active false | delete <id> --yes
npx securenow fp test-body @request.json --conditions '[...]'
```

Conditions are `{"field", "operator", "value"}`. Fields: `path`, `method`, `user_agent`, `status_code`, `request_body`, `request_headers`. Operators: `equals`, `not_equals`, `contains`, `not_contains`, `starts_with`, `ends_with`, `regex`, `in`, `not_in`, and structural checks (`path_safe_values`, `query_safe_values`, `query_has_only_keys`, `ua_safe_values`, `headers_safe_values`, `headers_has_only_keys`, `body_safe_values`, `body_is_format`, `body_has_only_fields`, `json_has_only_keys`, `json_safe_values`, `json_valid`, `json_max_depth`, `json_schema_match`); prefer the `*_safe_values` checks, which only excuse a request whose value is clean. Match modes: `all`, `any`. Scopes: `this_rule` (only through `fp mark`), `specific_rules` (with `--target-rules id1,id2`), `all_existing`, `any_rule` (the `fp create` default). Presets for `--*-safe`: `standard`, `strict`.

MCP: `securenow_alert_review_runs_list`, `securenow_alert_review_run_get`, `securenow_alert_review_run_keep_alive`, `securenow_alert_review_run_resolve`, `securenow_alert_review_run_dismiss`, `securenow_alert_review_run_apply_group_decision`, `securenow_human_actions_list`, `securenow_human_action_report`, `securenow_human_action_block`, `securenow_human_action_false_positive`, `securenow_human_action_close_no_write`, `securenow_human_case_action_update`; prompts `work_alert_review`, `work_human_actions`, `investigate_human_action_row`.

### Block an IP

```bash
npx securenow blocklist add 203.0.113.42 --env production --duration 24h --reason "credential stuffing"
npx securenow blocklist add 203.0.113.0/24 --route /admin --mode prefix --method ALL --reason "admin probing"
npx securenow firewall test-ip 203.0.113.42 --path /admin --method GET --env production   # would it be blocked?
npx securenow blocklist list --env production         # [--status active|removed] [--search 203.0.] [--approval-status pending]
npx securenow blocklist unblock <id> --reason "false alarm after review"   # stops enforcement, keeps the history
npx securenow blocklist approve <pending-id> --yes    # or: reject <pending-id> (records a scoped no-block decision)
npx securenow blocklist stats
```

`--route` (aliases `--path`, `--pattern`) with `--mode prefix|exact|regex` and `--method` makes a scoped block; without them the block is global. `blocklist remove` is an alias of `unblock`. Running apps enforce it within about 10 seconds. In the app (layer 1), ranges are IPv4 CIDRs and IPv6 is matched by exact address.

**Allowlist** is deny-by-default: once any active entry exists for an app and environment, only listed IPs get through. Use it only to lock an app to known IPs, with the person's approval. **Trusted IPs** are the safe way to mark known infrastructure (monitors, office VPN, your servers): alerts on them are suppressed and nobody is restricted.

```bash
npx securenow allowlist add 198.51.100.7 --app <key> --env production --label "Office" --reason "Admin app locked to office"
npx securenow allowlist list | remove <id> | stats
npx securenow trusted add 198.51.100.20 --label "Uptime monitor"     # [--app <key>] [--env <env>]
npx securenow trusted list | remove <id>
```

Default automations block by risk score (95+ for 7 days, 90–94 for 72 hours, 85–89 for 24 hours): `npx securenow automation list`, `automation defaults --yes`, `automation show <id>`, `automation dry-run <id>`, `automation execute <id> --yes`, `automation create|update|delete`.

MCP: `securenow_blocklist_add`, `securenow_blocklist_unblock`, `securenow_firewall_test_ip`, `securenow_allowlist_*`, `securenow_trusted_*`.

### Rate-limit a route

```bash
npx securenow ratelimit add --route /api/login --method POST --limit 5 --window 1m --env production --reason "login brute force"
npx securenow ratelimit add --route /api/ --limit 100 --window 1m --header x-api-key        # per API key value
npx securenow ratelimit add --route /app --limit 300 --window 1m --cookie session           # per session cookie value
npx securenow ratelimit add --route /api/export --limit 50 --window 1h --key-by global      # one bucket for everyone
npx securenow ratelimit add 203.0.113.42 --limit 30 --window 1m --duration 24h              # one IP or CIDR
npx securenow ratelimit parse "5 per minute per IP on POST /api/login for 2h"               # draft only
npx securenow ratelimit from-text "5 per minute per IP on POST /api/login for 2h" --yes     # create
npx securenow ratelimit test 203.0.113.42 --path /api/login --method POST --env production
npx securenow ratelimit list | show <id> | enable <id> | disable <id> | remove <id> --reason "..."
```

`--mode exact|prefix|regex` (default `prefix`), `--method` (default `ALL`), `--window 30s|1m|1h`, `--duration 24h|7d` (expiry), `--key-by ip|global|header|cookie` (`--header <name>` or `--cookie <name>` imply it). Header and cookie values are hashed; requests without them count per IP. Over the limit the app answers 429 with `Retry-After`. Rules are per environment and default to `production`; use `--env local` to try one on a local app. Counters live in each process unless the app sets `config.firewall.rateLimitStore` to a Redis URL. `rate-limit` is an alias of `ratelimit`. MCP: `securenow_rate_limit_parse`, `securenow_rate_limit_create_from_text`, `securenow_rate_limit_create`, `securenow_rate_limit_test`.

### Challenge bots

```bash
npx securenow challenge add --route /login --clearance 30m --env production --reason "credential stuffing wave"
npx securenow challenge add 203.0.113.0/24 --route /signup --difficulty 16 --escalate-to-block --fail-threshold 10 --block-ttl-hours 24
npx securenow challenge test 203.0.113.9 --path /login --method GET --env production
npx securenow challenge list | show <id> | enable <id> | disable <id> | remove <id> --reason "..."
npx securenow firewall hits --action captcha_challenged --since 1h
```

Browsers get an invisible proof of work (`--difficulty` in leading zero bits, 4–28, default 14: about a second or less) and a pass for `--clearance` (default 30m). Clients that don't accept HTML get a 403 JSON `challenge_required`, so don't challenge API routes used by non-browser clients. MCP: `securenow_challenge_create`, `securenow_challenge_list`, `securenow_challenge_update`, `securenow_challenge_remove`.

### Revoke a stolen session

```bash
npx securenow revoke session <session-id> --reason "impossible travel" --duration 24h --app <key>   # [--env <env>]
npx securenow revoke user <user-id> --reason "account takeover"      # every session of that user; default expiry 7d
npx securenow revoke list                                            # [--type session|user] [--status active|restored]
npx securenow revoke restore <revocation-id> --reason "verified with the user"
```

The app enforces it within 30 seconds, through one of: `"sessions": { "guard": true }` in its runtime config **(8.25.0+)**, `sessions.guard()` middleware, or `sessions.check(req)` **(8.25.0+)** (SKILL-API.md section 5.10). The session id is the SHA-256 of the Bearer token or session cookie, as it appears in `session.id` on traces and `session.seen` events; the user id is the JWT `sub` or what the app reports. There is no MCP tool for revocation: use this command.

### Create an alert rule from English and test it

```bash
npx securenow alerts rules from-text "one IP failing 10 sign-ins in 5 minutes" --app <key> --draft-only   # see the checked draft
npx securenow alerts rules from-text "one IP failing 10 sign-ins in 5 minutes" --app <key>               # create it (asks)
npx securenow alerts rules test <rule-id> --wait                 # dry run on real data (default)
npx securenow alerts rules test <rule-id> --mode live --wait     # inserts 6 synthetic attack requests first
npx securenow alerts rules run <rule-id>                         # run a periodic rule now  [--no-wait]
npx securenow alerts rules runs <rule-id> --since 1h             # each run: notified, no_rows, throttled, suppressed_blocked, ...
npx securenow alerts rules why <rule-id> --ip 203.0.113.50 --since 2h
npx securenow alerts rules change <rule-id> "raise the threshold to 20"   # rewrite from English as a new version
npx securenow alerts rules quality <rule-id>                     # 14-day precision, wrong alerts and why
npx securenow alerts rules promote <rule-id> --yes               # a person: test → prod  (demote: back to test)
npx securenow alerts rules request-promotion <rule-id> --reason "..." --evidence @evidence.md   # what an agent does instead
```

`from-text` picks an instant rule (each request, as it arrives) or a periodic one (SQL on a schedule); force it with `--instant` or `--periodic`, and set `--name`, `--severity`, `--env` (default: every environment). New rules start in **test mode**: they alert, and no instant block, automation or agent acts on them. With `--yes`, `from-text` refuses a rule whose check matches your data right now (it would alert at once, usually a bad baseline); `--yes --force` creates it anyway when the rows are a real attack. A person approves promotion requests with `npx securenow human promotions` and `human approve-promotion <request-id> --yes` (or `deny-promotion <request-id> --reason "..."`); API keys and MCP tokens can ask but not decide.

When a rule stays quiet, `alerts rules runs` names the outcome of every run (`notified`, `no_rows`, `throttled`, `suppressed_blocked`, `suppressed_trusted`, `no_ip`, `storm`, `auto_resolved`, `skipped`, `error`) and `alerts rules why` ends in a verdict such as "Detected at 15:06:31 but not notified: 203.0.113.50 was already blocked". The throttle sends one alert per rule and address per window (default 15 minutes).

**SQL rules.** Read the contract first and check the fields the app really sends:

```bash
npx securenow telemetry schema --json                  # offline: tables, timestamps, tenant scope, event mapping, templates  [logs|traces|events]
npx securenow telemetry fields --app <key> --env production --since 24h --json   # names, types, counts, event types (never values)
npx securenow alerts rules validate --sql @rule.sql --app <key>                  # dry-run before creating anything
npx securenow alerts rules create --name "Auth: magic-link brute force" --sql @rule.sql --apps <key> \
  --severity high --schedule "*/15 * * * *" --nlp "single IP flooding /api/auth/signin"
npx securenow alerts rules create --name "Secrets probe" --apps <key> \
  --conditions '[{"field":"path","operator":"contains","value":"/.env"}]'      # an instant rule, no SQL
npx securenow alerts rules set-sql <rule-id> --sql @rule.sql                     # replace a custom rule's SQL
npx securenow alerts rules delete <rule-id> --yes
```

Scope app keys with `__USER_APP_KEYS__` (logs: `resources_string['service.name'] IN (__USER_APP_KEYS__)`; traces: `` `resource_string_service$$name` IN (__USER_APP_KEYS__) ``) and return an `ip` column (SQL without one is refused unless `--allow-no-ip`: it would never notify). `create` dry-runs the query and deletes the rule again if it fails (`--no-validate` skips that); a new periodic rule runs once right away. Label a rule `READY` only when its fields were observed and `validate` succeeded, otherwise `NEEDS_INSTRUMENTATION` (the app must send a `track()` event), `NEEDS_BASELINE` or `NEEDS_CUSTOMER_DECISION`. Details: `node_modules/securenow/TELEMETRY-SQL.md`. System rules are tuned with `alerts rules tune-query <id> --sql @candidate.sql --reason "..." --apply-globally --yes` (admin), after `alerts rules dry-run-query <id> --sql @candidate.sql --app <key> --wait`.

MCP: `securenow_alert_rule_draft`, `securenow_alert_rule_create`, `securenow_alert_rule_test`, `securenow_alert_rule_runs`, `securenow_alert_rule_run_now`, `securenow_alert_rule_explain`, `securenow_alert_rule_request_promotion`, `securenow_alert_rule_candidate_test`, `securenow_alert_rule_instant_update`, `securenow_alert_rule_quality`.

### Starter protection

```bash
npx securenow protect                       # the current app: mode, rules, alerts, ready to block?  [--all] [--rules] [--json]
npx securenow protect enable --app <key>    # monitor mode: rules alert, nothing is blocked
npx securenow protect block --app <key>     # a signed-in person only: block-ready rules block for 6 hours
npx securenow protect monitor --app <key>   # back to alerts only
npx securenow protect disable --app <key>   # off until someone turns it on  [--yes]
npx securenow protect learn --app <key>     # detection learning now (it also runs hourly)
```

Every app gets about 20 starter rules in monitor mode when it is created or first sends traffic. `protect block` is refused for API keys, MCP connectors and the agent, and while more than 20% of the app's traffic arrives through a proxy the SDK doesn't trust (fix with `config.networking.trustedProxies`). Detection learning labels each alert (right, wrong, unclear), keeps each rule's 14-day precision per app and adds a safe exclusion only when it excuses the wrong alerts and none of the right ones. MCP: `securenow_protection_status`, `securenow_protection_learn`.

### Let the autonomous agent work the queues

```bash
npx securenow agent                          # status: on/off, mode per action, what it did, agreement with people
npx securenow agent on                       # or: off (also revokes a run in progress)
npx securenow agent mode all shadow          # record what it would do, change nothing
npx securenow agent mode block_ip act --yes  # then hand over one kind of action at a time
npx securenow agent activity --mode applied  # every decision with its evidence  [--action block_ip] [--page N]
npx securenow agent undo <id> --yes          # unblock, reopen the row, or roll the rule back
npx securenow agent runs                     # patrols: status, tool calls, cost, summary
npx securenow agent run                      # patrol now
```

Actions: `close_row`, `false_positive`, `block_ip`, `review_close`, `keep_rule`, `rule_change`, `case_action` (or `all`); modes: `off`, `shadow`, `suggest`, `act`. The API enforces the limits whatever the model decides: the agent's token reaches only the queue, verification and rule-tuning routes, it can't block without a verification that allows it, and an action type that people keep undoing drops back to shadow by itself.

Your own harness instead: `npx securenow agent prompts` lists the runbooks; `npx securenow agent prompt patrol` prints one (`patrol`, `alert-review`, `human-queue`; `--confirm-writes` for the variant that may act, `--search`, `--limit`, `--max-alert-review-groups`, `--max-human-rows`):

```bash
claude -p "$(npx -y securenow@latest agent prompt patrol --search my-app --confirm-writes)" --allowedTools "mcp__securenow"
```

### Set up MCP

```bash
npx securenow login                                        # the local server uses this auth
claude mcp add securenow -- npx securenow mcp              # Claude Code
codex mcp add securenow -- npx securenow mcp               # Codex
claude mcp add --transport http securenow https://api.securenow.ai/mcp   # hosted server, OAuth sign-in
```

Cursor, `.cursor/mcp.json`:

```json
{ "mcpServers": { "securenow": { "command": "npx", "args": ["securenow", "mcp"] } } }
```

- The local stdio server is `npx securenow mcp` (also the `securenow-mcp` bin). Admin tools use `.securenow/admin.json`; app-scoped reads can use `.securenow/runtime.json`. Warm the package once (`npx -y securenow@latest --version`) so the first connection doesn't time out on the download, and give the client a longer connect timeout (Claude Code: `MCP_TIMEOUT=120000`).
- The hosted server `https://api.securenow.ai/mcp` needs no install and always has the current tools: OAuth sign-in with a SecureNow account (or `Authorization: Bearer <API key>`). The SecureNow plugin for Claude Code and Codex bundles it with skills (`/plugin marketplace add securenow-ai/claude-plugin`, then `/plugin install securenow@securenow`).
- Read tools are annotated read-only; every write tool refuses to run without `confirm: true` and a non-empty `reason`. Resources: the installed SKILL-API.md, SKILL-CLI.md and NPM_README.md, the project config, the tool catalog. Prompts: `secure_project_setup`, `verify_firewall_default_on`, `investigate_ip`, `investigate_human_action_row`, `work_human_actions`, `work_alert_review`, `soc_patrol`, `agent_patrol`, `cleanup_legacy_pending_blocks`, `configure_default_automation`.
- Profiles serve only the tools one job needs (`npx securenow mcp --profile <name>` or `SECURENOW_MCP_PROFILE=<name>`). Every profile keeps `securenow_auth_status`, `securenow_apps_list` and `securenow_apps_info`; a tool outside the profile returns an error naming it.

  | Profile | Tools | Contents |
  |---|---|---|
  | `all` (default) | 125 | everything |
  | `investigator` | 65 | every read-only tool, plus forensics question/chat/confirm |
  | `detection` | 53 | alert rules (draft, create, test, run, runs, explain, versions, exclusions, request promotion...), traces, logs, forensics, IP intelligence, notifications |
  | `responder` | 82 | notifications, both queues, blocklist, allowlist, trusted IPs, rate limits, challenges, automations, firewall, IP intelligence, plus rule get/runs/explain and traces/logs |

  ```bash
  claude mcp add securenow-investigator -- npx -y securenow@latest mcp --profile investigator
  ```

### Emit an event, a log or a span from a script

```bash
npx securenow event send auth.login.failure --user u_123 --ip 203.0.113.10 --attrs reason=bad_password,method=password
npx securenow event send auth.otp.send.result --session s_1 --level warn --attrs status=failed --env staging
npx securenow log send "Backup failed" --level error --attrs host=db-01      # --level trace|debug|info|warn|error|fatal
npx securenow test-span ci.smoke-test --env production
```

`event send` posts one custom event to the `/v1/events` ingest with the runtime credentials (`--user`, `--session`, `--ip`, `--user-agent`, `--level`, `--attrs k=v,k=v`, `--env`): the same event `track()` sends from Node, for cron jobs, CI or non-JS services. `log send` and `test-span` exit non-zero on HTTP errors, so CI can catch failures.

### Diagnose a setup

```bash
npx securenow env            # resolved service name, environment, endpoints, firewall (no secrets)  [--json]
npx securenow doctor         # probes traces, logs, API and firewall sync; exit 1 on failure  [--json]
npx securenow test-span      # "Span accepted (HTTP 200)"
npx securenow firewall status --env production   # the app's firewall state, layers, blocklist
npx securenow firewall apps                      # every app with its firewall on/off per environment
npx securenow firewall enable --app <key> --env production   # or: disable
npx securenow config path                        # config and credential files in use
```

### Threat-modeling prompts

```bash
npx securenow threat-model --list
npx securenow threat-model authentication --out threat-prompt.md   # then: "Follow threat-prompt.md"
npx securenow threat-model authentication | claude -p
```

Categories include `authentication`, `authorization`, `injection`, `api-security`, `rate-limits-and-abuse`, `webhooks`, `ai-llm-features` and more (`--list`).

### Utilities

```bash
npx securenow redact '{"user":"alice","password":"s3cret","otpCode":"123456","status_code":200}'   # [--fields f1,f2] or @file.json
npx securenow cidr match 10.0.0.5 10.0.0.0/8,192.168.1.0/24    # exit 0 = match, 2 = no match
npx securenow cidr parse 10.0.0.0/24                           # network, broadcast, mask, size
```

`redact` uses the same rules as SDK capture (field names, OTP names matched exactly so `status_code` stays, secret-shaped values).

## Command reference

`securenow help <command>` is authoritative. Subcommand flags not listed by `help` are shown in its usage lines below.

| Command | Subcommands | Key flags |
|---|---|---|
| `run` | `run [node-flags] [--firewall-only] <script> [args]`; `securenow <script.js>` is a shorthand | `--firewall-only`, Node flags pass through (`--watch`, `--inspect`) |
| `login` | | `--token`, `--global` |
| `logout` | | `--global` |
| `whoami` | | |
| `admin` | `login` (default), `logout` | `--token`, `--global` |
| `app` | `connect` (default) | `--global` |
| `credentials` | `runtime` (default) | `--env` (default `production`), `--out`, `--stdout`, `--format env` |
| `api-key` | `create`, `set <key>`, `clear`, `show` (default) | `create`: `--name`, `--app <key-or-id>`, `--preset runtime_app`, `--global` |
| `init` | | `--env` (default `local`), `--key snk_live_...`, `--ts` (`--typescript`), `--js` (`--javascript`), `--src`/`--root` (Next.js file folder; default `src/` when `app/` or `pages/` is there), `--force` (replace the instrumentation file, keeping a `.bak`) |
| `apps` | `list` (default), `create <name>`, `info <id>`, `delete <id>`, `default <key>`, `discover [appId]`, `scan` | `create`: `--hosts h1,h2`, `--instance <id>`; `delete`: `--force`; `discover`: `--domain`; `scan`: `--yes` |
| `status` | | `--app`, `--env local\|production\|all` |
| `today` | | `--since 1h..7d` (default 24h), `--attackers <n>` (default 8), `--json` |
| `attacker` | `attacker <ip>` | `--json` |
| `traces` | `list` (default), `show <traceId>`, `analyze <traceId>` | `--app`, `--env`, `--limit`, `--start`, `--end` |
| `logs` | `list` (default), `trace <traceId>`, `errors` | `--app`, `--env`, `--since 30m\|6h\|2d`, `--minutes`, `--level trace\|debug\|info\|warn\|error\|fatal`, `--limit`, `--start`, `--end`; `errors`: `--warn` |
| `analytics` | | `--app` |
| `protect` | `status` (default), `enable`, `disable`, `block`, `monitor`, `learn` | `--app`, `--all`, `--rules`, `--yes` |
| `agent` | `status` (default), `on`, `off`, `mode <action> <mode>`, `activity`, `undo <id>`, `runs`, `run`, `verify <ip>`, `prompt <name>`, `prompts` | `--action`, `--mode`, `--page`, `--notification`, `--yes`, `--confirm-writes`, `--limit`, `--search`, `--max-alert-review-groups`, `--max-human-rows` |
| `human` | `list` (default), `show`, `block`, `fp`, `close`, `report`, `action`, `prompt`, `work`, `promotions`, `approve-promotion`, `deny-promotion` | `--reason`, `--outcome`, `--summary`, `--evidence`, `--yes`, `--search`, `--limit`, `--page`, `--status`, `--note`, `--conditions`, `--rule-scope`, `--create-exclusion`, `--missing-proof` |
| `review` | `list` (default), `show`, `keep`, `close`, `dismiss`, `group` | `--outcome`, `--reason`, `--summary`, `--preview`, `--allow-mixed`, `--search`, `--yes` |
| `notifications` | `list` (default), `read <id>`, `read-all`, `unread` | `list`: `--limit`, `--page`, `--search`, `--severity` |
| `alerts` | `rules` (default), `channels`, `history` | `history`: `--limit` |
| `alerts rules` | `list` (default), `from-text`, `change`, `create`, `show`, `update`, `duplicate`, `promote`, `demote`, `set-sql`, `validate`, `dry-run-query`, `tune-query`, `delete`, `test`, `run`, `runs`, `why`, `quality`, `exclusions <id> [list\|add\|delete]`, `versions`, `version`, `rollback`, `request-promotion` | `--app`, `--apps`, `--applications-all`, `--env`, `--instant`, `--periodic`, `--draft-only`, `--name`, `--sql`, `--conditions`, `--severity`, `--schedule`, `--throttle-minutes`, `--no-throttle`, `--channel`, `--allow-no-ip`, `--no-validate`, `--mode dry_run\|live` (test) / `test\|prod` (list, update), `--status`, `--wait`, `--ip`, `--since`, `--limit`, `--reason`, `--evidence`, `--apply-globally`, `--yes`, `--force` |
| `fp` | `list` (default), `show`, `create`, `edit`, `delete`, `test-body`, `dry-run`, `ai-fill`, `mark <notification-id> <ip>` | `--conditions`, `--match-mode`, `--rule-scope`, `--target-rules`, `--path`, `--method`, `--path-safe`, `--query-safe`, `--query-keys`, `--ua-safe`, `--headers-safe`, `--headers-keys`, `--reason`, `--description`, `--context`, `--active` |
| `ip` | `ip <address>` (lookup), `lookup`, `traces <ip>` | `traces`: `--app`, `--env` |
| `forensics` | `forensics "<question>"`, `query`, `chat`, `conversations [<id>]`, `library` | `--app`, `--env`, `chat`: `--conversation <id>`, `--yes` |
| `firewall` | `status` (default), `apps`, `enable`, `disable`, `test-ip <ip>`, `hits` | `--app`, `--env`; `test-ip`: `--path`, `--method`; `hits`: `--since`, `--action blocked\|rate_limited\|captcha_challenged`, `--source`, `--rule`, `--ip`, `--limit` |
| `automation` | `list` (default), `defaults`, `show`, `create`, `update`, `dry-run`, `execute`, `delete` | `--name`, `--conditions`, `--actions`, `--logic`, `--status`, `--body`, `--file`, `--app`, `--applications-all`, `--env`, `--environments-all`, `--limit`, `--sample-limit`, `--yes`; `defaults`: `--force-enable` |
| `ratelimit` (alias `rate-limit`) | `list` (default), `add [ip]`, `parse`, `from-text`, `show`, `test <ip>`, `enable`, `disable`, `remove` | `--route`/`--path`, `--mode`, `--method`, `--limit`, `--window`, `--duration`, `--key-by`, `--header`, `--cookie`, `--key-name`, `--app`, `--env`, `--reason`, `--text` |
| `challenge` | `list` (default), `add [ip]`, `show`, `test <ip>`, `enable`, `disable`, `remove` | `--route`/`--path`, `--mode`, `--method`, `--difficulty` (4–28, default 14), `--clearance` (default 30m), `--duration`, `--escalate-to-block`, `--fail-threshold` (10), `--block-ttl-hours` (24), `--app`, `--env`, `--reason` |
| `blocklist` | `list` (default), `add <ip>`, `unblock <id>`, `remove <id>`, `approve <id>`, `reject <id>`, `stats` | `--route`/`--path`/`--pattern`, `--mode`/`--path-mode`, `--method`, `--duration`, `--app`, `--env`, `--reason`, `--status`, `--approval-status`, `--search`, `--view`, `--page`, `--limit` |
| `revoke` | `list` (default), `session <id>`, `user <id>`, `restore <id>` | `--reason`, `--duration` (default 7d), `--app`, `--env`, `--type`, `--status` |
| `allowlist` | `list` (default), `add <ip>`, `remove <id>`, `stats` | `--app` (comma-separated), `--env`, `--label`, `--reason`, `--page`, `--limit` |
| `trusted` | `list` (default), `add <ip>`, `remove <id>` | `--app`, `--env`, `--label` |
| `telemetry` | `schema` (default) `[all\|logs\|traces\|events]`, `fields` | `--app`, `--env`, `--since` (max 30d), `--source`, `--limit` (1–500), `--json` |
| `log` | `send <message>` (default) | `--level`, `--attrs`, `--env` |
| `event` | `send <type>` (default) | `--user`, `--session`, `--ip`, `--user-agent`, `--level`, `--attrs`, `--env` |
| `test-span` | `test-span [<name>]` | `--env` |
| `threat-model` | `threat-model <category>` | `--list`, `--out` |
| `redact` | `redact '<json>'` or `@file` | `--fields` |
| `cidr` | `match <ip> <cidrs>`, `parse <cidr>` | |
| `doctor` | | `--json` |
| `env` | | `--json` |
| `mcp` | | `--profile all\|investigator\|detection\|responder` |
| `instances` | `list` (default), `test <id>` | |
| `config` | `get [key]`, `set <key> <value>`, `path` | keys: `apiUrl`, `appUrl`, `defaultApp` |
| `version` | | |

## Flags, environment and errors

| Flag | Short | Effect |
|---|---|---|
| `--json` | `-j` | JSON output for scripts and agents |
| `--help` | | Help for the command |
| `--yes` | `-y` | Confirm a write without the prompt |
| `--force` | `-f` | Same as `--yes` on most write commands |

Environment variables the CLI reads: `NO_COLOR` (plain output), `SECURENOW_MCP_PROFILE` (MCP tool profile), `SECURENOW_CREDENTIALS` (runtime credentials, used by `env`, `doctor`, `test-span`, `log send`, `event send`). The admin token always comes from `admin.json` (`npx securenow admin login`).

| Error | Meaning | Recovery |
|---|---|---|
| `Session expired` | The admin token expired | `npx securenow admin login` |
| `Not logged in` | No admin token found | `npx securenow admin login` (the runtime file is a separate lane) |
| `Access denied (403)` | The user's role or the key's scopes don't allow it | Check the role in the organization or the API key's scopes |
| `HTTP 402` | The 14-day trial ended and the account has no subscription; everything, the firewall included, is paused | Subscribe in the dashboard ($99 per app per month, every feature) |
| `Cannot connect` | API unreachable | Network, or `npx securenow config get apiUrl` |
| `Unknown command` | Typo | `npx securenow help` |
