From stackhawk-optimize
Analyze a codebase and produce an optimal HawkScan setup — tech flags, scan-policy plugin selection, and stackhawk.yml corrections — then apply it as a non-destructive trial, run ONE trial scan, and promote or discard. Use when the user asks to "optimize my scan", "tune HawkScan", "make my scan faster", "reduce false positives", "pick the right plugins/policy for my app", or invokes /optimize. Also invoked automatically by the hawkscan skill once at onboarding to set up the scan policy + tech flags (Setup mode), and re-runnable anytime via /optimize; the metrics Refine mode is surfaced when a scan is slow. Do NOT use for: a normal security scan or fixing vulnerabilities (use the hawkscan skill); querying existing findings or posture (use the api skill); or editing stackhawk.yml without optimizing/scanning. Requires an onboarded StackHawk app + env and a `hawk` build whose `hawk op` has the `policy` write commands.
How this skill is triggered — by the user, by Claude, or both
Slash command
/stackhawk-optimize:optimizeThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Turn a codebase into an optimal HawkScan configuration. The skill detects the real tech
Turn a codebase into an optimal HawkScan configuration. The skill detects the real tech
stack and app shape, expresses that as a trial scan policy (tech flags + plugins) plus
local stackhawk.yml corrections, runs one trial scan so the user sees real results, and
then promotes the setup or discards it with no residue.
Org scan policies are stored as hosted assets and downloaded by the scanner at scan time
when app.scanPolicy.name is set (see references/trial-lifecycle.md). Creating a trial
policy and referencing it in stackhawk.yml therefore leaves the application's own policy,
plugins, and tech flags untouched until the user promotes. This is the core safety
property.
# Identify the driving skill for CLI usage telemetry (read by hawk/hawkop).
export _STACKHAWK_SKILL=optimize
hawk version,
hawk config --help, hawk op auth). Additionally confirm the policy write commands
exist: hawk op policy create --help must succeed. If it errors with "unrecognized
subcommand", STOP and tell the user to upgrade hawk.
Also confirm metrics support: hawk op scan metrics --help must succeed. If it errors
with "unrecognized subcommand", the metrics/refine phase is skipped (pre-scan
optimization still works); tell the user to upgrade hawk to enable refinement.ORG_POLICY_MANAGEMENT + WRITE_POLICY
/DELETE_POLICY. If a policy create dry-run reports a permission/feature error,
degrade to recommend-only: print the proposed policy JSON + yml diff and stop.Two modes. Setup configures scan policy + tech flags (no scan) and is what hawkscan
onboarding invokes; it is also re-runnable anytime via /optimize. Refine runs a trial
scan and tunes from per-path metrics; it runs only via /optimize or when a scan is slow.
references/mapping.md.stackhawk.yml corrections. Default to a balanced profile; honor an explicit
speed↔coverage lean if the user gives one. See references/mapping.md.hawk op policy get --name DEFAULT
or the API/GraphQL preset matching the app), edit its tech flags + toggle plugin
families, write the result to a temp JSON file, and create it under a deterministic
name matching ^[A-Z0-9_]+$ (e.g. OPTIMIZE_TRIAL_<APP>_<ENV>, upper-snake, sanitized).
See references/cli-contract.md and references/trial-lifecycle.md.stackhawk.yml, then set
app.scanPolicy: { name: OPTIMIZE_TRIAL_… } plus app-type/OpenAPI/auth corrections.
Show the diff; never clobber unrelated keys. Setup ends here — the named policy is
referenced in stackhawk.yml (the scanner downloads it by name); promotion to the app
default is a Refine concern, not required here.hawk scan. The scanner downloads the policy and applies
its tech flags + plugins. Capture the trial scan id, findings, and duration.hawk op scan metrics <SCAN_ID> --format json and parse
the per-path/operation metrics, signal flags, and request health. See
references/metrics-and-refine.md. If no metrics are available, skip to step 8.rate-limited / timeout-prone
(hawk.scan.concurrentRequests — halve from its current yml value, default 20, floor 1);app.excludePaths for
heavy-path/slow-path; app.authentication.* for auth-wall) with the exact yml
diff, applying only approved changes.
If any change was applied, re-scan and return to step 6 with the new scan id.
STOP when no new high-severity flags remain, after 3 refine iterations, or when the
user declines further refinement. All edits go to the trial stackhawk.yml (backed up).
See references/metrics-and-refine.md for the full mapping + loop control.excludePaths/concurrentRequests), then ask:
promote or discard.references/trial-lifecycle.md. Promote: re-create the
policy under a permanent name, point stackhawk.yml at it (keeping the refined
scope/concurrency yml edits), delete the trial policy, leave the yml change for the user
to commit. Discard: hawk op policy delete the trial policy and restore the
stackhawk.yml backup.--dry-run a policy create/delete first when validating preflight.stackhawk.yml backup before reporting the error.OPTIMIZE_TRIAL_… before creating a fresh one).concurrentRequests, excludePaths) go to the trial stackhawk.yml only;
discard reverts them with the backup. Never auto-apply path exclusions or auth changes —
those require explicit confirmation.hawk.scan.concurrentRequests at 1 (never 0).hawkscan — runs the actual scan loop and owns the onboarding flow + the fallback
tech-flag detection heuristics (references/tech-flags.md), used only when this skill
can't create a scan policy.api — read-only platform lookups via hawk op (app/env/policy listing).npx claudepluginhub stackhawk/agent-skills --plugin stackhawk-optimizeGuides creation and editing of skills using test-driven development with pressure scenarios and subagents to verify agent compliance.
Creates platform-native content for X, LinkedIn, TikTok, YouTube, and newsletters from source material. Adapts voice and format per platform while avoiding engagement bait and filler.