Skip to content

Latest commit

 

History

History
947 lines (805 loc) · 57.6 KB

agent-hooks.md

File metadata and controls

947 lines (805 loc) · 57.6 KB

Agent-Loop Hooks (Claude Code, Codex, Cursor)

Skylos can run inside a coding agent's loop. It checks each edit when the agent makes it, instead of waiting for CI:

  • After every edit, Skylos verifies the lines the agent just changed and tells the agent what to fix.
  • Before the agent reads a file, Skylos blocks the read if the file contains a hard-coded secret, so the key is never sent to the model provider.
  • Before a package install or one-shot run (pip, uv/uvx, poetry, pipx, npm/npx, pnpm dlx, yarn dlx, bun/bunx, go, deno), Skylos blocks packages that do not exist (hallucinated) or are one-letter look-alikes of popular packages (typosquats), versions reported as malware, versions published less than 48 hours ago, and npm versions that lost the provenance their earlier versions had. npm ci, uv sync, pip install -r and other lockfile installs get the malware check over every locked package. It asks you before installs it cannot verify: git and URL sources, registries it does not know, and lookups that fail.
  • Before the agent adds an MCP server (claude mcp add, codex mcp add, gemini mcp add, or an edit to .mcp.json, .cursor/mcp.json and the other MCP configs), Skylos checks the package the server would run for malware, release age and existence, and requires an exact version: an unpinned npx -y pkg is blocked with the pinned command to use instead. Before the agent adds a command that runs on its own (a SessionStart hook in .claude/settings.json, a folderOpen task in .vscode/tasks.json), Skylos asks you.
  • At each prompt, Skylos reports agent config changes it did not see the agent make and re-checks configured MCP servers (what an unpinned one would fetch today).
  • Before a git command, Skylos blocks ways around the repository's git hooks: --no-verify, HUSKY=0, core.hooksPath=/dev/null and similar.
  • When the agent says it is done, Skylos blocks the stop while issues the agent added in this session are still open.

Everything runs locally. It needs no account, no Docker and no API key. The only network calls are package-registry and OSV (api.osv.dev) lookups, and only for install commands, MCP servers and new imports.

Install

skylos setup installs the Claude Code and Codex hooks for the project (.claude/settings.json and .codex/hooks.json; --no-codex skips Codex) with the hook command skylos, resolved on each machine's PATH, so the committed files work for every teammate. It runs the same check as the installer below: the skylos on PATH must support skylos hook, or nothing is installed. The commands below install one agent at a time, or Cursor, or the user-level config:

pip install skylos
cd your-project

skylos agent install-hooks                 # Claude Code, this project (.claude/settings.json)
skylos agent install-hooks --user          # Claude Code, all projects (~/.claude/settings.json)
skylos agent install-hooks --codex         # Codex (.codex/hooks.json)
skylos agent install-hooks --cursor        # Cursor (.cursor/hooks.json)

The installer merges its entries into the existing file. It keeps every other hook and setting, and running it again changes nothing. If the file is not valid JSON, the installer stops and leaves the file unchanged. --dry-run prints the result without writing it.

The hook command names the Skylos that ran the installer by absolute path (its console script, or <python> -m skylos.entry), so an older skylos earlier on the agent's PATH cannot shadow it. Before writing, the installer runs that command once (hook help) and refuses to install if it does not support skylos hook. --skylos-bin PATH picks another executable (a relative path is made absolute; a bare name such as skylos means "resolve on PATH at run time"). --no-check skips the check.

Every command is wrapped so that a Skylos that cannot run never blocks the agent: ... hook post-edit --client claude || exit 0 (Stop hooks print {}, Cursor permission hooks print {"permission":"allow"}). Skylos itself always exits 0 and puts decisions in JSON, so a non-zero exit only means "not installed / too old / broken here", which becomes a silent no-op.

Committed settings. .claude/settings.json (and .codex/, .cursor/) is usually committed. The absolute path is this machine's; on a teammate's machine without it the hooks silently do nothing. Teammates who want the checks run skylos agent install-hooks themselves, or you install with --skylos-bin skylos so each machine uses its own PATH (an old or missing skylos there is still a no-op, never a block).

For a project install inside a Git repo, the installer also keeps hook state out of Git: it appends .skylos/cache/, .skylos/agent-session.* and .skylos/hook.log* to .gitignore (idempotent), or writes .skylos/.gitignore if the repo has no .gitignore. It does not ignore all of .skylos/, which also holds committed config and the AI contract.

  • Claude Code: the new hooks load in the next session. Run /hooks to see them.
  • Codex: Codex skips new hooks until you trust them. Open /hooks in Codex and trust the Skylos entries.
  • Cursor: Cursor reloads hooks.json automatically.

Uninstall

skylos agent install-hooks --uninstall            # add --user / --codex / --cursor to match the install

This removes only the Skylos entries: any hook whose command runs skylos hook <event>. All other hooks stay.

Check the hooks

Because every hook falls back to "allow" when Skylos cannot run, a deleted venv or a moved install leaves hooks that look installed and do nothing. skylos doctor checks them:

skylos doctor                 # "Agent hooks" section
skylos doctor --format json   # checks.agent_hooks

For Claude Code, Codex and Cursor, at project scope (the Git root of the current directory) and user scope (~), it reports:

  • whether Skylos hooks are installed, in which file, and how many of the installer's hooks are there (9 of 9); missing ones are named;
  • whether the Skylos executable the hook commands call still exists;
  • a self-test of the pre-bash hook. Doctor sends it two payloads in a throwaway directory: ls (expected: allowed) and cat .env, where .env holds a token generated for the test (expected: blocked). The commands are described to the hook, never run. It also prints how long each answer took.
  Agent hooks
  OK  Claude Code: 9 of 9 hooks in .claude/settings.json (project) → /home/me/proj/.venv/bin/skylos
      Self-test (passed): pre-bash allowed `ls` (0.2 s) and blocked `cat .env` of a file with a token (0.2 s)
  FAIL Codex: ~/.codex/hooks.json (user): points at a missing Skylos executable /old/venv/bin/skylos; these hooks do nothing (they fall back to allow)
      Reinstall: skylos agent install-hooks --codex --user
  --  Cursor: not installed (optional: skylos agent install-hooks --cursor)

Not installed is information, not a failure. A missing executable, an unreadable config file, or a self-test that answers wrongly or takes longer than 10 seconds makes doctor's status degraded and prints the reinstall command. When SKYLOS_HOOKS_DISABLE turns pre-bash off in doctor's environment, the self-test says so instead of running.

Doctor only reads the config files. It runs the self-test only when a hook command is exactly what the installer writes (the executable, hook pre-bash --client <client> and the fallback). It runs that executable directly, without a shell, and does not run one that is a file committed to the repository, because a project config is repository content. Other commands are listed as "not checked". Doctor cannot see whether a client has loaded or trusted the hooks (Codex asks you to trust them in /hooks), or whether a client update stopped calling them; the self-test shows only that the hook answers when called.

Turn one hook off

Set SKYLOS_HOOKS_DISABLE in the environment the agent runs in. Its value is a comma-separated list of hook names, or all:

export SKYLOS_HOOKS_DISABLE=pre-read          # keep the others
export SKYLOS_HOOKS_DISABLE=pre-bash,stop
export SKYLOS_HOOKS_DISABLE=all

To remove one hook for good, delete its entry from the config file. The entries are easy to find because every Skylos command contains skylos hook <name>.

What each hook does

The installer writes eight hooks. Five of them check and can block:

Hook Claude Code Codex Cursor What it does
post-edit PostToolUse on Edit|Write|MultiEdit PostToolUse on apply_patch|Edit|Write afterFileEdit Verifies the changed lines and reports failures to the agent
pre-read PreToolUse on Read not available (Codex reads files through the shell; pre-bash covers that) beforeReadFile Blocks reading a file that contains secrets
pre-bash PreToolUse on Bash|PowerShell PreToolUse on Bash beforeShellExecution Blocks commands that would print a secret file or variable, installs of hallucinated, typosquatted, malicious or too-new package versions, unpinned or unsafe MCP servers, and git-hook bypasses; asks before installs it cannot verify
pre-edit PreToolUse on Edit|Write|MultiEdit PreToolUse on apply_patch|Edit|Write not available Blocks edits to agent configs that add unpinned or unsafe MCP servers; asks before new agent hooks and folderOpen tasks (MCP servers and agent configs). It also records the file before the edit for skylos provenance
stop Stop Stop stop Blocks "done" while issues this session added are still open

The other three never block:

Hook Claude Code Codex Cursor What it does
session-start UserPromptSubmit UserPromptSubmit beforeSubmitPrompt Records the starting checkout, so stop can tell the agent's changes from earlier ones (with a committed [tool.skylos.done] table; see Done gate). Tells Claude Code the blocking checks once per session, and reports agent config changes and MCP server problems at every prompt (below)
post-bash PostToolUse on Bash|PowerShell PostToolUse on Bash not available Files a shell command changed (their lines stay unattributed)
post-failure PostToolUseFailure on Edit|Write|MultiEdit and on Bash|PowerShell not available not available Partial changes from a failed edit or command (their lines stay unattributed)

On the first prompt of a session, Claude Code gets at most six lines explaining which Done checks block in this repository (the block checks of the committed table, or that Done tests are not configured), what the edit and pull request gates block, and the command to run before finishing (skylos done --base <base>, using the base skylos open would use). These instructions are sent once per session and only to Claude Code. Agent config and MCP server warnings still run at every prompt for Claude Code, Codex and Cursor.

skylos hook recheck FILE... [--range L1:L2] and skylos hook recheck --session are commands for the agent, not hooks; see post-edit.

post-edit

Skylos works out which lines the edit added:

  • Claude Code: from the tool result's structuredPatch, or by finding new_string in the file.
  • Codex: from the + lines of the apply_patch envelope.
  • Cursor: from edits[].new_string.

A Write that creates a new file counts as all new lines. Skylos then runs skylos verify on the file with security and secret checks on, and keeps only the findings on the changed lines. Existing debt elsewhere in the file is never reported. Findings on the same line are merged into one item.

What blocks, and what is only a note

verify's taint rules treat every function parameter as tainted, so a plain helper like def load(path): return open(path).read() is reported as path traversal. The hook does not block on that. It blocks only on:

  1. Secrets (SKY-S*).
  2. Real untrusted input reaching a sink (SKY-D211/212/215/216/217/230/...): Skylos checks the enclosing function on the AST for a web-route, CLI or MCP-tool parameter (@app.get, @router.post, @click.command, @mcp.tool, ...), request.* / a Request-typed parameter, input(), sys.argv, os.environ/os.getenv, sys.stdin, or parse_args(), and follows simple assignments to the sink. For other languages it uses the finding's security_evidence.source.
  3. Sinks dangerous whatever the input: unsafe deserialization (pickle.loads, SKY-D204/205/233), Trojan Source (SKY-D344), disabled TLS verification (SKY-D210 / Go SKY-G210: verify=False, InsecureSkipVerify) and disabled JWT verification (SKY-D232, JS/TS SKY-D246), which agents add to silence an error, and eval/exec/os.system/shell=True/yaml.load with a non-constant argument. os.system("clear") is not blocked.
  4. Hallucinations: nonexistent dependencies, versions, APIs and references (SKY-D222/224/225, SKY-L012/L023), and violations of your own AI contract (SKY-A105).

Other findings on the changed lines are notes: Claude Code gets them as non-blocking additionalContext; they are not re-raised at stop.

You can opt into blocking specific built-in quality rules with skylos agent install-standards --enforce RULE_ID. Selected quality findings then block on agent-added lines and remain open at stop until fixed. The project-wide skylos agent check-standards . command checks the same selected rules across the whole project for CI. See project standards.

For source files (Python, TS/JS, Java, Go, PHP, Rust, Dart, C#, Kotlin, C++, shell), Skylos runs the full verify check set. For config files (.env, YAML, JSON, TOML and similar), it runs only the secrets scanner.

If an edit fails, Claude Code and Codex get a block message with at most 10 items:

Skylos found 2 issue(s) in the lines you just changed. Fix them before moving on:
- app.py:6 SKY-D212 Possible command injection (os.system): tainted input. -> Remove the unsafe sink or validate, escape, or parameterize the untrusted input.
- app.py:9 SKY-S101 Potential AWS secret access key detected -> Remove the hard-coded credential, load it from the environment or a secret manager, and rotate it if it was ever committed or shared.
Check again with: skylos hook recheck app.py

skylos hook recheck FILE... [--range L1:L2] applies exactly this policy to the files on disk and prints a few lines: exit 0 when nothing blocking is left (the hook will not block on it), 1 otherwise. skylos hook recheck --session rechecks every file where agent edits introduced issues. The hint names the same Skylos the hook runs, by path when skylos on PATH is a different one. (skylos verify reports every finding and may say "needs review" after a correct fix, so it is not the recheck command.)

If the edit passes, the hook prints nothing. Cursor's afterFileEdit has no way to send feedback, so on Cursor this hook only records the result, and the agent sees the findings at stop.

pre-read

This hook runs the Skylos secrets scanner on the file the agent is about to read. If it finds a secret, it blocks the read. The block message names the file, the line numbers and the kind of secret, never the value or a preview of it. If the agent's Read uses offset/limit to skip the secret lines, the read is allowed, and the block message tells the agent it can do that. Unlike skylos -a, test files are scanned too (a live key in tests/conftest.py reaches the model provider just the same). Binary files and files over 2 MB are skipped.

post-edit does not block writing a secret into a .env* file that Git ignores (git check-ignore): that is where the key belongs. Writing it into a tracked file (source, .env.example) is still blocked.

pre-bash

This hook checks two things.

Secrets the command would print. Skylos works out what the command prints from files and environment variables and scans that text with the same secrets scanner as pre-read. If a secret would reach the output, the command is blocked. The block message names the file and line numbers (or the variable) and the kind of secret, never the value. This closes the shell route around pre-read, and on Codex, which reads files through the shell, it is the read check. It follows:

  • programs that print files: cat, less, nl, head/tail, grep/rg/ag, sed, awk, cut, base64, xxd, sort, diff and similar, including cmd < file, cat <<< "$VAR", globs and braces (cat .env*, .env{,.local}), cd dir && ..., $(...), loops (for f in .env*, while read ...; done < .env), bash -c '...' and eval
  • grep -r over a directory, and rg/ag with --hidden (except files Git ignores, which they skip), for .env* files
  • the environment: env, printenv, export -p, declare -p, set, and echo/printf of $NAME, including values loaded by the same command (source .env, export $(cat .env | xargs))

Only what is printed counts, after grep, head/tail, cut, simple sed scripts (-n '10,40p', /re/p, s/=.*//) and simple awk programs (NR<=40, -F= '{print $1}'). So these run: sed -n '1,200p' app.py when the secret is further down, cat .env | grep PORT when the PORT line holds no secret, grep -c, cut -d= -f1 .env, sed 's/=.*//' .env, grep -rn KEY . | cut -d: -f1, > /dev/null, | wc -l, echo ${TOKEN:+set}, and export $(cat .env | xargs), which loads values without printing them. A pipe into a program Skylos does not know counts as not printed. Only the printed lines are scanned, at most 2 MB per command.

This guards the commands agents usually write; it is not a sandbox. Not followed: a program that opens the file itself (python -c "print(open('.env').read())"), find ... -exec cat, ... | xargs cat, git show HEAD:.env, docker compose config, a copy read back under another name, and files the secrets scanner does not read (.npmrc, ~/.aws/credentials), which pre-read does not check either.

Package installs and one-shot runners. Skylos reads the command the way the shell would (pipes, &&/;, line continuations, VAR=1 cmd, export VAR=1, sudo/env/timeout/xargs, bash -c '...', eval, $(...)) and finds every package it would fetch:

Ecosystem Commands
PyPI pip/pip3/pip3.12 install, python -m pip install, uv pip install, uv add, uv tool install, uv tool run, uvx, uv run --with, poetry add, pdm add, pipenv install, pipx install/run/inject
npm npm install (and its aliases, i, add, install-test), npm exec/npm x, npm init/npm create <initializer> (runs create-<initializer>), npx, pnpm add/install <pkg>/dlx/create, pnpx, yarn add/global add/dlx/create, yarn workspace <ws> add, bun add/install <pkg>/x/create, bunx, deno run/install/add with npm: specifiers
JSR deno add/install/run with jsr: specifiers (and deno add @scope/name)
Go go get, go install, go run pkg@version

Options before the package name (npx -y --package=foo bar, uvx --from foo bar, pip install -U -r reqs.txt pkg, pnpm --filter web add x), several packages in one command, version pins, scoped npm names, pkg[extra], PEP 508 markers and npm aliases (foo@npm:bar@1) are handled. For a runner, only the package is checked; the arguments after it belong to the program it runs.

Each command gets one of these outcomes:

Outcome Examples What happens
Package does not exist, pinned version does not exist, or one-edit look-alike of a popular package (SKY-D222/D225) pip install fastapi-authz, npx -y cowsy, npm create foo when create-foo is not published Blocked on every agent
Version reported as malware npm install chalk@5.6.1, pip install aiocpa==0.1.13, npm i c@npm:chalk@5.6.1, npx -y xrpl@4.2.1, npm install chalk while latest is a malicious release Blocked on every agent (see Supply-chain checks)
Version younger than the release cooldown (default 48 hours) npm install typescript@next six hours after a nightly, pip install openai the day of a release Blocked; the message names the newest older version to install instead
npm version published without the provenance its earlier versions had a release pushed from a stolen token instead of the project's CI Blocked
Direct source: code from outside a registry npm install github:user/repo#b181e0, npm install user/repo, pip install git+https://..., uvx --from git+https://..., a tarball or wheel URL, deno run https://..., an archive outside the project, an archive downloaded by the same command (curl -LO ... && npm i ./x.tgz) direct_source policy (default: ask)
Untrusted registry or index --index-url/--extra-index-url/-i/-f URL, --registry, --@scope:registry=, PIP_INDEX_URL=, UV_INDEX_URL=, NPM_CONFIG_REGISTRY=, GOPROXY=, GOSUMDB=off on the command line direct_source policy (default: ask), unless the registry is in trusted_registries
Could not verify registry unreachable, timeout, HTTP 429/5xx; package named at run time (pip install $PKG, xargs npm i, npx $(...)); a name Skylos cannot read; more than 25 packages in one command; a package missing from the public registry while your configuration points at a private one; an install or git command longer than Skylos reads (16,384 characters, not counting here-document bodies) on_unverified policy (default: ask)
Not fetched from a registry npx tsc when tsc is the project's own bin, in node_modules/.bin (this directory or any parent) or a global npm bin, as npm itself resolves it; npx --no; local paths and archives inside the project (pip install -e ., npm i ../lib, workspace:/file:/link:); pip install --no-index allowed
Lockfile install npm ci, npm install (with or without packages), pnpm install/add, yarn, yarn add, bun install/add, uv sync, uv run, uv add/remove, uv pip sync, poetry install/add, pipenv sync/install, pip install -r requirements.txt the malware check runs over every locked package, whatever source the lockfile records (see Supply-chain checks); a malicious one is blocked, and a tarball, git or URL source from an unknown host is "could not verify" (direct_source). Global installs (npm i -g) and uv run --no-sync do not read the project lockfile. No lockfile: allowed as before, unless an earlier part of the same command could have written it. go mod download and package.json ranges without a lockfile are not checked here; skylos . -a and skylos done check manifests

A git commit hash ref (github:cline/cline#b181e0) is called out in the message: GitHub serves commits from any fork through the parent repository's URL, so a commit ref can point at a fork's code.

What "ask" means for each agent:

Agent ask deny allow
Claude Code permissionDecision: "ask": you approve or reject in the permission prompt, which shows the reason; Claude also gets it as additionalContext. In auto mode the hook's ask still forces a prompt. In -p runs, where nobody can answer, Claude Code denies the call and Claude reads the reason permissionDecision: "deny" runs through your normal permission flow, with a note (systemMessage + additionalContext)
Cursor permission: "ask" with user_message/agent_message permission: "deny" permission: "allow"; the note goes to the Hooks output channel
Codex denied: Codex does not support ask in PreToolUse and would run the command, so Skylos denies and says so permissionDecision: "deny" runs, with a systemMessage note

An allow is never silent: the agent and you are told the install was not verified. Cursor documents ask for beforeShellExecution; if your Cursor version or a cloud agent runs the command without asking, set direct_source = "deny" and on_unverified = "deny".

Policy. Set it in pyproject.toml at the project root:

[tool.skylos.hooks]
direct_source = "ask"        # git/URL/tarball installs and untrusted registries: "ask" | "deny" | "allow"
on_unverified = "ask"        # registry unreachable, run-time names: "ask" | "deny" | "allow"
block_hook_bypass = true     # see "Git hook bypass" below
trusted_registries = ["https://pypi.corp.example/simple", "npm.corp.example"]

A value that is not one of these falls back to the default (which never allows), and the message says so. trusted_registries entries match a registry by host, and by path prefix when the entry has a path. Packages installed from a trusted registry (on the command line or in your configuration) skip the public check.

Your own registry configuration. "Not on npmjs.org" is not evidence of a hallucination when your configuration fetches from somewhere else. Skylos reads registry= and @scope:registry= from .npmrc (from the working directory up to the project root, and ~/.npmrc) and npm_config_registry for the npm tools, and for Python only the configuration the installing tool itself reads: PIP_INDEX_URL/PIP_EXTRA_INDEX_URL and pip.conf/pip.ini for pip (and pipx, pipenv); UV_*INDEX*, uv.toml and [tool.uv] for uv; [[tool.poetry.source]] for poetry; [[tool.pdm.source]] for pdm. Go reads GOPROXY/GOPRIVATE/GONOPROXY (environment or go env -w). Public mirrors (registry.yarnpkg.com, registry.npmmirror.com, the common PyPI mirrors) count as the public registry and get every check. With another registry configured:

  • a scoped npm package whose scope has its own registry is never sent to npmjs.org; it is allowed if that registry is trusted, otherwise it is "could not verify";
  • a GOPRIVATE module is never sent to the Go proxy and is allowed;
  • any other package missing from the public registry becomes "could not verify" (ask) instead of a block. Look-alikes of popular packages are still blocked;
  • a package that exists publicly gets every check when the registry is declared (trusted_registries), unless its name matches internal_packages. When the registry is not declared, a pinned version still gets the malware check, and Skylos adds a one-line note that the release age was not checked.

To allow your own names (internal packages, deliberate look-alikes) without any check, list them in pyproject.toml:

[tool.skylos]
hooks_allow_packages = ["internal-pkg", "npm:my-reactt"]   # optional npm:/pypi:/go:/jsr: prefix

PyPI names match after PEP 503 normalisation (Foo_Bar = foo-bar); npm, Go and JSR names match exactly, ignoring case, so allowing acme-utils does not allow the different npm package acme.utils.

Well-known packages that sit one edit from a popular name (preact, pyaml, react-dom, ...) are never flagged, and neither is any package in the popular list itself. Registry answers that settle the question (exists, does not exist, version does not exist) are cached in .skylos/cache/dependency_versions.json; "could not verify" answers are retried next time. A PEP 440 local version (torch==1.11.0+cu113) is never on PyPI, so only the public version (1.11.0) is checked.

Supply-chain checks

Every package version the command would install, and every package in the lockfile a lockfile install reads, is checked before the command runs:

  • Malware. One OSV querybatch with fresh data (no cache). A version is malware when OSV lists a MAL-* record or alias for it, a record with malicious-packages-origins, or a record with CWE-506 (embedded malicious code); withdrawn records do not count, and ordinary CVEs never block an install (skylos . -a reports those). When OSV does not answer, the installed ca9 feed answers instead (ca9 feed update); with neither, the package is "could not verify" (on_unverified). A malicious version that the registry already removed is reported as malware, not as a missing version.
  • Release cooldown. A version published less than min_release_age_hours ago (default 48) is blocked. Most hijacked releases (chalk and debug in September 2025, the Shai-Hulud worm) were found and pulled within hours; two days also covers the ones found on the second or third day (Shai-Hulud 2.0, tj-actions). The message names the newest older version that has no malware report, for example Install typescript@7.0.2 instead. An unpinned install is checked at the version the manager would install: npm's latest dist-tag (or the tag from --tag, NPM_CONFIG_TAG or .npmrc tag=) or the version a range resolves to; PyPI's newest final release that matches the specifier (yanked releases skipped), a prerelease with --pre/PIP_PRE/ --prerelease allow, and the pin from a constraints file (-c, PIP_CONSTRAINT, UV_CONSTRAINT). A constraints file Skylos cannot read is "could not verify".
  • npm provenance. A version published without a provenance attestation when the releases before it had one is blocked; the message names the newest earlier version with provenance. When the registry does not answer, nothing is blocked.
[tool.skylos.supply_chain]
block_malware = true          # false: known malware asks instead of blocking
min_release_age_hours = 48    # 0 turns the cooldown off; the hook default is 48
check_provenance = true       # npm only
internal_packages = ["acme-*", "@acme/*"]   # kept private when served by a declared registry

pip download, pip wheel and npm pack <spec> fetch the package too, so they get the same checks as an install (pip download evil==1.0 && pip install ./evil.whl is blocked at the download). corepack pnpm add x is read as pnpm add x.

Lockfiles and requirements files. Every locked entry with a name and version is checked for malware, wherever the lockfile says it came from (registry.npmjs.org, a mirror, an Artifactory URL, a private uv index), except entries from a declared registry whose name matches internal_packages. A tarball, git or URL source from a host that is neither public nor declared is also "could not verify" (direct_source), because its contents need not match the version it claims. Requirements files follow pip: index options never switch the check off (--index-url https://pypi.org/simple, --extra-index-url https://download.pytorch.org/... are checked as usual); only an exclusive private --index-url keeps internal_packages names away from OSV. name @ url, git+... and URL lines are direct sources, like pip install <url>. A constraint pin (-c) is the version of an unpinned requirement.

When an earlier part of the same command line may write the lockfile, its manifest, the requirements file or anything it includes (curl -o, cp, mv, tee, >, sed -i, git checkout, git pull, patch, unzip, tar, or any other command that names the file), Skylos does not read it: the install is "could not verify". Read-only commands such as cat, grep or git diff count only through a redirect. A script that writes the file without naming it is not detected.

A synced Skylos Cloud policy (supply_chain in .skylos/config.yaml) can only tighten these values. When it sets trusted_registries or private_registries, those lists replace [tool.skylos.hooks] trusted_registries, so a repository cannot trust a registry Cloud does not. When Cloud sets block_malware, hooks_allow_packages no longer skips the malware check (it still skips the existence, release-age and provenance checks); without Cloud, it skips them all. Packages from a trusted registry on the command line are never sent to OSV or the public registry; a pinned version from an untrusted --registry/--index-url gets the malware check as well as the direct_source question. Release age and provenance come from the ca9 engine (ca9.api, installed with Skylos); an older ca9 without it makes those packages "could not verify" until you run pip install -U ca9.

Limits: the whole install check (registry lookups included) shares a 20-second budget inside the 30-second hook timeout, and at most 5,000 locked packages are checked per lockfile; anything not checked in time is "could not verify", never passed. bun.lockb (binary) is not read; use the text bun.lock. Shell aliases and functions that wrap an install command are not followed.

Git hook bypass. Agents skip a failing pre-commit hook instead of fixing it. With block_hook_bypass = true (the default), pre-bash blocks:

  • --no-verify (and git's abbreviations such as --no-veri) on git commit, merge, pull, push, rebase and am; -n on commit and am, including short-option clusters (-anm "msg"; in -amn the n is the message, so it is not a bypass);
  • git -c core.hooksPath=..., --config-env=core.hooksPath=..., and the GIT_CONFIG_COUNT/GIT_CONFIG_KEY_<n> and GIT_CONFIG_PARAMETERS environment forms, when the new path has no hooks;
  • hook managers' skip switches on a git commit/push/merge/pull/ rebase/am command: HUSKY=0 and HUSKY_SKIP_HOOKS (husky), SKIP=... and PRE_COMMIT_ALLOW_NO_CONFIG (pre-commit; SKIP is also overcommit's), LEFTHOOK=0/false and LEFTHOOK_EXCLUDE (lefthook), SKIP_SIMPLE_GIT_HOOKS (simple-git-hooks), OVERCOMMIT_DISABLE (overcommit), whether as a prefix (HUSKY=0 git commit) or exported earlier in the same command (export HUSKY=0 && git commit). A switch counts only when its manager is in use: its config file or folder is at the top of the repository (.husky/, .pre-commit-config.yaml, .overcommit.yml, lefthook.yml and the other lefthook names, .simple-git-hooks.json or a simple-git-hooks key in package.json), the hooks directory is inside .husky, or an installed hook script names the manager. A plain .git/hooks/pre-commit never reads HUSKY, so HUSKY=0 git commit is allowed there;
  • persistent changes: git config core.hooksPath <path without hooks> (or /dev/null), git config --unset core.hooksPath when a hooks path is set, and a git alias whose value adds --no-verify;
  • removing a hook, or taking away its execute bit, in the active hooks directory (rm .git/hooks/pre-commit, chmod -x .husky/_/pre-commit).

A bypass only counts when a hook it would skip is installed and executable in the directory git runs hooks from (git rev-parse --git-path hooks, so core.hooksPath and husky's .husky/_ are followed; for husky, a hook counts when its .husky/<hook> script exists). In a repository without hooks --no-verify changes nothing and is allowed. HUSKY=0 npm ci (skipping hook installation in CI) is allowed. The block is a deny on all three agents; the message names the hooks that would not run and tells the agent to fix what the hook reports, or to stop and tell you if the hook fails for an unrelated reason.

MCP servers and agent configs

An MCP server started with npx -y pkg or uvx pkg fetches whatever the newest release is on every launch, and a hook planted in .claude/settings.json or .vscode/tasks.json runs as soon as the agent or editor opens the project. Skylos checks both when the agent changes them.

Which changes are checked. In pre-bash: claude mcp add in all its forms (-s/--scope, --transport, -e KEY=V, -- before the command, add-json, global options such as --debug before mcp; add-from-claude-desktop always asks, because Skylos cannot see what it imports), codex mcp add (also after -c k=v) and gemini mcp add, including with an environment prefix, inside bash -c, or run through npx @anthropic-ai/claude-code. A command whose program is only known at run time (c=claude; $c mcp add ...) asks. claude plugin install, claude plugin marketplace add and gemini extensions install|link ask, because plugins and extensions load code into the agent. In pre-edit: edits to .mcp.json, .cursor/mcp.json, .vscode/mcp.json, .vscode/tasks.json, .gemini/settings.json, .claude/settings.json, .claude/settings.local.json, .claude/agents/*.md, .cursor/hooks.json, .codex/hooks.json, .codex/config.toml, the same files in your home directory, and ~/.claude.json (user scope and every project's scope). Skylos applies the edit to the current text and has ca9 read the file before and after, so JSON with comments and trailing commas is read the way the agents read it. A file with duplicate keys asks: agents keep the last value, so Skylos cannot be sure which server or hook runs. Cursor has no pre-edit hook, so a Cursor edit to these files is reported at the next prompt.

A shell command that writes one of these files itself asks, because the hook cannot see what it writes: a redirect, tee, sponge or any program naming the file (globs such as .claude/setting*.json included), cp/mv/rsync into an agent config folder or of a config-named file into the folder that holds it, curl -o/-O and wget saving under a config name, inline code naming one (python3 -c "open('.mcp.json','w')..."), sed -i/perl -i, git checkout|restore ... -- .claude, git apply/am/patch of a patch that touches an agent config (or one Skylos cannot read), and archive extraction (tar x, unzip). Read-only commands (cat, jq, git diff, git add) and plain branch switches pass; a branch switch or pull that changes these files is reported at the next prompt.

What each MCP server gets. Skylos first unwraps the launch (timeout, sudo, nohup, env, nice, time, stdbuf, sh -c ...); ca9 then reads the launcher (npx, npm exec, pnpm dlx, yarn dlx, bunx, uvx, uv tool run, pipx run, docker run, cmd /c). Registry flags (--registry, --index-url) and registry variables in the server's env or -e (npm_config_registry, PIP_INDEX_URL, UV_INDEX_URL) are kept: a registry you have not declared in trusted_registries asks instead of being checked against the public registry.

Server Result
Package with an exact version (pkg@1.4.2, pkg==2.1.0) Same checks as an install of that version: existence, malware, release age, npm provenance. Clean passes; otherwise blocked
Package without an exact version (npx -y pkg, @latest, @^1, uvx --from pkg tool) Checked at the version the launcher fetches today, then blocked with the pinned command, for example claude mcp add x -- npx -y some-mcp@1.4.2. When that version is too new, the pin is the newest older version without a malware report
Git or URL source, untrusted registry, image without a digest, a launcher Skylos cannot read Asks (direct_source / on_unverified)
A wrapper that starts more than one program (sh -c "curl ... | sh"), inline code (node -e, python -c), uv run --with, a program outside the project (node /opt/x/server.js, a binary on PATH) Asks
ca9 flags it: a script in a hidden home folder, a package name imitating a vendor Asks (malware still blocks)
Script inside the project (node ./server.js), installed module (python -m pkg) Passes; it fetches nothing
Remote server (--transport http, "url") Passes with a note; the note says "could not verify" for plain http:// to a host that is not local

Commands and settings that run code. Adding or changing any of these asks you:

  • a hook command in an agent's settings (any event, plus statusLine, apiKeyHelper, awsAuthRefresh, awsCredentialExport and otelHeadersHelper in Claude Code), hooks or MCP servers in .claude/agents/*.md frontmatter, Codex notify, and a folderOpen task in .vscode/tasks.json;
  • settings env that changes what runs or where traffic goes: PATH, BASH_ENV, PYTHONPATH, NODE_OPTIONS, HTTPS_PROXY/HTTP_PROXY, npm_config_registry and other registry variables, CLAUDE_CODE_SHELL_PREFIX, LD_*/DYLD_*, ANTHROPIC_BASE_URL, OPENAI_BASE_URL;
  • enabledPlugins, extraKnownMarketplaces, enabledMcpjsonServers and enableAllProjectMcpServers: true;
  • removing Skylos's own hooks or weakening them (another event, matcher or a shorter timeout), in an edit or through skylos agent install-hooks --uninstall run by the agent, and disableAllHooks: true.

Removing other entries is allowed. A hook counts as Skylos's own only when its command is, character for character, what skylos agent install-hooks writes on this machine (the running Skylos console script, or skylos on PATH), outside the project and outside temp folders, in a settings file whose env sets no PATH or loader variable. python -m skylos.entry never counts (-m imports from the project folder), and neither does a symlink the project commits. curl ... | sh; skylos hook pre-bash ... or a skylos binary somewhere else is asked about like any other command. The scanner (SKY-D365) uses the same rule, without the "this machine" part. Codex cannot ask; Skylos blocks there instead.

Without a ca9 that reads agent configs (ca9.api.agent_config and parse_mcp_server), every MCP addition and every edit to these files is "could not verify" (asks) until you run pip install -U ca9.

At each prompt (session-start)

session-start keeps a snapshot of what these files run in .skylos/cache/agent-configs.json: names and hashes only, never commands, URLs or environment values. At each prompt it reports, one line each, what changed since the snapshot without a checked agent edit or command: servers added, changed or removed, new hook commands and code-loading settings, removed or changed Skylos hooks, duplicate keys. That covers changes made by another program, such as a malicious package writing a server into ~/.cursor/mcp.json, Cursor's edits, branch switches, and edits the agent made through the shell. Only the exact change Skylos checked is folded into the snapshot after it lands; anything else written at the same time is still reported. The first run only records the snapshot.

Once per session (or hourly, or when a server changes), every configured MCP server is checked again at the version it would run now: known malware, a release younger than the cooldown, or a package that no longer exists is reported. Unpinned servers that pass are not repeated each session; servers that could not be checked in the time budget (8 seconds) are counted as "could not be verified". The report never blocks the prompt. In Claude Code it reaches you and the agent; in Codex you; in Cursor the Hooks output channel.

Harden the agents' own settings

skylos agent harden            # print (default; writes nothing)
skylos agent harden --offline  # no version lookups
skylos agent harden --write    # merge the JSON settings, after you confirm, in a terminal

skylos agent harden prints each agent's native settings for this project:

  • Claude Code, ~/.claude/settings.json: permissions.deny Read rules for ~/.ssh, ~/.aws, ~/.config/gcloud, ~/.npmrc, ~/.pypirc and ~/.claude.json, and the sandbox with credentials.files denies for the same paths, failIfUnavailable: true and allowUnsandboxedCommands: false.
  • Claude Code, .claude/settings.json: Read(./.env) and Read(./.env.*) denies, and allowedMcpServers with each MCP server in this project's configs as an exact serverCommand (unpinned ones pinned to the version that passes the malware and release-age checks; ones that fail are left out with the reason) or serverUrl.
  • Cursor, .cursor/sandbox.json: "readBoundary": "workspace" (Cursor 3.23+), so the agent asks before reading outside the project.
  • Codex, ~/.codex/config.toml (printed only): sandbox_mode = "workspace-write", approval_policy = "on-request", no network.

This is policy and audit, not protection, and Skylos enforces none of it. Claude Code's Read rules cover its own file tools and the file commands it recognizes, not a Python or Node script the agent runs; its sandbox covers shell commands, not hooks, MCP servers, the status line or apiKeyHelper. Servers started through a wrapper (timeout, sudo, sh -c), with inline code, or from outside the project are left out of allowedMcpServers. allowedMcpServers only binds when an admin sets it in managed settings with allowManagedMcpServersOnly; in project settings anyone who edits a settings file can widen it, and it also blocks servers you added in other scopes. It matches the command exactly, so change the MCP config to the pinned command too. Codex documents no read deny list (it can read ~/.ssh), and neither Codex nor Cursor has an MCP allowlist Skylos can pin by version, so none is generated for them.

--write merges into the three JSON files (lists gain the missing entries, other keys are kept). It runs only from an interactive terminal after you answer y, so an agent cannot run it.

stop

Each post-edit records a hashed identity (rule plus the hash of the source line, never the text) for every issue the agent added. It saves these in .skylos/agent-session.json, under the agent's session ID. At stop, Skylos re-verifies every file that still has an issue the agent added, whether or not that file changed: a fix can land in another file (defining a missing crud.delete_item in crud.py fixes the call in items.py). This is the same check skylos hook recheck runs, so the two always agree. If an issue the agent added is still there, the stop is blocked with the list. The hint names every file with open issues; past five it points to skylos hook recheck --session, which rechecks all of them.

The hook doesn't loop forever. If the agent already continued once because of this hook and the issues are unchanged:

  • Claude Code: Skylos lets the agent stop and shows you a warning.
  • Codex: Skylos lets the agent stop and shows you a warning.
  • Cursor: Skylos sends no follow-up message. Cursor's own loop_limit also applies; the installer sets it to 10.

With a committed [tool.skylos.done] table, stop also runs the Done checks and your tests (see Done gate). When they pass, Claude Code shows you Skylos Done passed: 4 tests run; receipt .skylos/receipts/latest.json; Codex and Cursor show nothing. A second stop on the same tree, policy and Skylos version, while that session's passing receipt is still .skylos/receipts/latest.json, reuses the pass instead of running the static checks and tests again: the recorded-edit recheck still runs, no new receipt is written, and the hook log line carries done_reused: true. Any difference runs everything again, and a failed or unfinished Done is never reused. A blocking Done message ends with the receipt path.

Hook contract used

Every hook exits 0 and signals through JSON on stdout.

Situation Claude Code / Codex output Cursor output
session-start, first prompt of a session Claude: {"hookSpecificOutput": {"hookEventName": "UserPromptSubmit", "additionalContext": "..."}}; Codex: no output {"continue": true}
session-start, later prompts no output {"continue": true}
pre-read / pre-bash block {"hookSpecificOutput": {"hookEventName": "PreToolUse", "permissionDecision": "deny", "permissionDecisionReason": "..."}} {"permission": "deny", "user_message": "...", "agent_message": "..."} (beforeReadFile: permission + user_message)
pre-bash ask (unverifiable install) Claude: {"hookSpecificOutput": {"hookEventName": "PreToolUse", "permissionDecision": "ask", "permissionDecisionReason": "...", "additionalContext": "..."}}; Codex: the deny shape above (Codex has no ask) {"permission": "ask", "user_message": "...", "agent_message": "..."}
pre-bash allowed by policy ("allow") Claude: {"systemMessage": "...", "hookSpecificOutput": {"hookEventName": "PreToolUse", "additionalContext": "..."}} (no permissionDecision); Codex: {"systemMessage": "..."} {"permission": "allow"}; the note goes to stderr
pre-read / pre-bash allow no output, so the normal permission flow applies (Skylos never sends "allow", which would skip your permission prompt) {"permission": "allow"} (Cursor treats empty output from permission hooks as a deny)
post-edit fail {"decision": "block", "reason": "..."} none (afterFileEdit can't send feedback)
post-edit, notes only Claude: {"hookSpecificOutput": {"hookEventName": "PostToolUse", "additionalContext": "..."}}; Codex: none none
post-edit pass no output no output
stop, issues open {"decision": "block", "reason": "..."} {"followup_message": "..."}
stop, clean {} (Codex requires JSON from Stop) {}
stop, Done passed Claude: {"systemMessage": "Skylos Done passed: ..."} (no decision, so the agent stops); Codex: {} {}
Skylos error (fails open) the allow/stop output above plus "systemMessage": "..."; Claude pre-read/pre-bash/post-edit also get hookSpecificOutput.additionalContext (no permissionDecision) the allow/stop output above; the message goes to stderr

References:

Failure behaviour and logs

Runtime hook failures fail open. If the JSON input is malformed, the event is unknown, the analyzer crashes or a lock is busy, Skylos allows the action and logs the error.

A fail-open is never silent, so an unchecked action can't pass for a checked one. When Skylos errors on a read, command, edit, prompt or stop, it says so:

Skylos could not check this edit: internal error (RuntimeError). It was allowed without a check.
  • Claude Code: systemMessage (shown to you) and, for pre-read, pre-bash and post-edit, additionalContext (shown to the agent). No permissionDecision is sent, so your normal permission prompt still applies.
  • Codex: systemMessage.
  • Cursor: stderr, which appears in Cursor's Hooks output channel (Cursor shows no message on an allowed action).

The reason names only the exception type, never its text. Each unchecked action is also recorded in .skylos/cache/hook-fail-open.json. At stop, Skylos reports the session's unchecked actions once, as a warning that never blocks:

3 actions were not checked by Skylos because it errored. They were allowed without a check:
- edit: internal error (RuntimeError) (2 times)
- command: internal error (OSError)

A hook turned off with SKYLOS_HOOKS_DISABLE stays silent and records nothing. Two other cases are still silent: an unknown hook name, and the shell wrapper's || exit 0 (a Skylos that is not installed or cannot start).

An explicitly configured but invalid agent standards policy gives Claude Code and Codex a repair message at post-edit and reports the problem to all three agents at stop; skylos hook recheck exits 2. Hook timeouts set by the installer are 15 s (pre-read), 30 s (session-start, pre-edit, pre-bash, post-bash, post-failure), 120 s (post-edit) and 9,060 s (stop). The stop timeout covers the largest trusted budgets the Done gate allows when it runs checks at stop: 3,600 s for the test command, 1,800 s for changed-line mutation checks and 1,800 s for rerunning failing tests on the session's starting commit, 1,800 s for optional type checking, plus 60 s to save the receipt. Without a committed [tool.skylos.done] table, stop runs no tests and only rechecks recorded issues. All three agents treat a timeout as a non-blocking failure.

Each hook call appends one JSON line to .skylos/hook.log with the time, event, client, outcome, counts and duration. pre-bash outcomes are skip, pass, ask, note (allowed by policy), block and block-bypass, with counts of packages, findings, direct, unverified and bypasses. The log never holds file contents, secrets or shell commands. It rotates at 512 KB.

The session file and log live in the project's .skylos/ only when the project is inside a Git repo. A --user install also fires in directories that are not repos (your home directory, a scratch folder); there they go under $XDG_CACHE_HOME/skylos/projects/<hash>/ (default ~/.cache) instead, together with every analyzer cache the hook would otherwise write to <dir>/.skylos/cache/ (module index, API surface, registry answers).

Latency

These times were measured on an Apple Silicon laptop (Python 3.14) by running skylos hook as a subprocess, the way the agent does, 10 runs each:

Hook Target p50 p95
post-edit 13-line Python file in a small project (fails: injection) 0.54 s 0.68 s
post-edit 25-line file inside the Skylos repo (~1,300 Python files), warm index 1.14 s 1.21 s
post-edit 330-line file inside the Skylos repo, warm index 1.30 s 1.49 s
post-edit 60-line file with 14 security findings (blocking policy applied) 0.61 s 0.71 s
post-edit same file, first run with no index (one-time) 5.7 s 6.5 s
pre-read small file containing secrets (blocked) 0.11 s 0.11 s
pre-bash unrelated command (ls -la) 0.08 s 0.08 s
pre-bash pip install requests fastapi (registry answers cached) 0.29 s 0.40 s

Install hook v2 was measured on 13 Oct 2026 on a heavily loaded machine (load average 10-30), interleaving the new code with the previous release run by run, so compare the columns rather than the absolute numbers (warm cache):

pre-bash command new p50 / p95 previous p50 / p95
ls -la (unrelated) 0.30 s / 0.39 s 0.32 s / 0.39 s
pip install requests fastapi 0.95 s / 2.59 s 0.88 s / 2.40 s
npx -y cowsay hi (newly checked) 0.84 s / 1.64 s 0.40 s / 0.49 s (not checked)
uvx ruff check . (newly checked) 0.78 s / 1.64 s 0.41 s / 0.51 s (not checked)
npx tsc --noEmit (local binary) 0.48 s / 0.68 s 0.54 s / 0.72 s
pip install -r requirements.txt 0.49 s / 0.74 s 1.70 s / 2.17 s
npm install github:cline/cline#b181e0 (asks) 0.38 s / 0.43 s 1.14 s / 1.22 s (not checked)
git commit --no-verify -m x (blocked) 0.39 s / 0.54 s 0.43 s / 0.55 s (not checked)

Commands that need no registry lookup (local binaries, manifests, git sources, hook bypasses) are decided without loading the registry checker. | stop | one edited file, unchanged since post-edit | 0.09 s | 0.14 s |

post-edit checks the edited file against the whole project's module surface so it can catch calls to functions that don't exist. Skylos keeps that surface in a per-file index at .skylos/cache/module-facts.json, so each edit re-parses only files that changed since the last check. The first check in a project builds the index. On a large repo, run this once after installing the hooks so the first edit is fast too:

skylos agent warm-cache

An index entry is reused only while the file's size, mtime, ctime and inode match, it maps to the same module name, and the imports it resolved still resolve the same way (adding or removing a module invalidates the entries that depend on it). A new Skylos or Python version rebuilds the whole index. Cached and uncached checks report the same findings.

Installed-package metadata used for hallucinated-import checks is reused in memory during the current analysis session. The snapshot is keyed by the interpreter and environment directory metadata; environment changes invalidate it. Repository cache files do not supply trusted installed-package mappings.

skylos hook runs without loading the rest of the CLI. After upgrading from an older Skylos, reinstall it (pip install -U skylos, or pip install -e . for a source checkout) so the skylos command picks up the lighter entry point.

Checking a very large edited file still takes longer, because the file itself is analyzed in full on every edit. skylos/analyzer.py (about 5,000 lines) takes about 3 s with a warm index.

What it doesn't do

  • It doesn't undo an edit. PostToolUse runs after the file is written. The hook reports; the agent fixes.
  • It doesn't report pre-existing findings. Only lines the agent changed in this session count. A deletion that removes a sanitizer elsewhere in the file is not attributed to the edit.
  • It doesn't guard every way to read a file. pre-read covers Claude Code's Read tool and Cursor's beforeReadFile, but cat .env through the shell and Codex file reads are not blocked.
  • It checks the packages inside lockfiles and requirements files (npm ci, uv sync, pip install -r) for malware only, not for existence or release age; skylos . -a and skylos done check the rest. A requirements file named by URL (pip install -r https://...) is a direct source.
  • An exact MCP server pin freezes that package, not its dependencies. A config written by a script that does not name the file, or by an edit in Cursor (which has no pre-edit hook), is only seen at the next prompt.
  • It doesn't follow dependencies declared inside a script (uv run script.py with inline PEP 723 metadata), cargo, gem or composer installs, conda, or package managers' own lifecycle scripts.
  • It is not a sandbox. A command that downloads and runs code in a way it does not parse (a script that calls pip, npm run scripts that install, curl ... | sh) is not checked; npx/uvx resolve the package at run time, so a package that exists but is malicious is not caught by an existence check.
  • It doesn't check edits made through the shell (sed -i, heredocs) at edit time. stop still re-checks files that earlier post-edit calls recorded, if they changed on disk.
  • It doesn't check files outside the project root.
  • It doesn't give feedback on each edit in Cursor. Findings arrive at stop as a follow-up message.
  • It doesn't use Cursor's generic preToolUse/postToolUse events, or Codex MCP-tool hooks. Only the events listed above are used.