A Claude Code hook is a command, listed under hooks in .claude/settings.json, that Claude Code runs on a fixed event such as PreToolUse or Stop and that can block the action. This is the full hook block skylos agent install-hooks writes, captured from --dry-run on Skylos 4.47.1:

{
  "hooks": {
    "UserPromptSubmit": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "skylos hook session-start --client claude || exit 0",
            "timeout": 30
          }
        ]
      }
    ],
    "PreToolUse": [
      {
        "matcher": "Read",
        "hooks": [
          {
            "type": "command",
            "command": "skylos hook pre-read --client claude || exit 0",
            "timeout": 15
          }
        ]
      },
      {
        "matcher": "Bash|PowerShell",
        "hooks": [
          {
            "type": "command",
            "command": "skylos hook pre-bash --client claude || exit 0",
            "timeout": 30
          }
        ]
      }
    ],
    "PostToolUse": [
      {
        "matcher": "Edit|Write|MultiEdit",
        "hooks": [
          {
            "type": "command",
            "command": "skylos hook post-edit --client claude || exit 0",
            "timeout": 120
          }
        ]
      }
    ],
    "Stop": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "skylos hook stop --client claude || echo '{}'",
            "timeout": 5460
          }
        ]
      }
    ]
  }
}
Event and matcherSkylos hookWhat it does
PreToolUse on Bash|PowerShellpre-bashDenies pip/uv/poetry/npm/pnpm/yarn/bun/go installs of packages that don't exist or look like typosquats
PreToolUse on Readpre-readDenies reading a file that contains a hard-coded secret
PostToolUse on Edit|Write|MultiEditpost-editChecks only the lines Claude just changed and tells it what to fix
StopstopBlocks "done" while issues this session added are still open
UserPromptSubmitsession-startRecords the starting checkout so your own earlier edits aren't blamed on the agent

Everything below was run on Skylos 4.47.1 on 10 Oct 2026. Each hook was fed the JSON the client sends, in a scratch repository where we made the agent's edits by hand. You can copy the configs and the ideas even if you write your own hook scripts.


Install

pip install skylos
cd your-project

skylos agent install-hooks              # Claude Code, this project: .claude/settings.json
skylos agent install-hooks --codex      # Codex: .codex/hooks.json
skylos agent install-hooks --cursor     # Cursor: .cursor/hooks.json
skylos agent install-hooks --user       # Claude Code, every project: ~/.claude/settings.json
skylos agent install-hooks --dry-run    # print the merged config, write nothing

This is what the first command printed in a scratch repository:

Installed 5 Skylos hook(s) in .../.claude/settings.json (skylos 4.47.1).
Wrote .../.skylos/.gitignore so hook state stays out of Git.
.claude/settings.json is usually committed. The hook command uses this machine's Skylos path; on a machine without it the hooks do nothing (they never block). Teammates who want the checks run `skylos agent install-hooks` themselves, or install with `--skylos-bin skylos` to use PATH.
Claude Code picks up settings changes on the next session; run /hooks to review them.

The installer merges its entries into the existing file and keeps your other hooks. Running it again prints "already installed ... (no change)". Without --skylos-bin skylos, the command in the file is the absolute path of the Skylos that ran the installer, so an older skylos earlier on the agent's PATH can't shadow it.

No account, API key or Docker is needed.


Example 1: a PreToolUse hook that blocks a made-up package

Claude Code sends the hook the pending tool call as JSON on stdin:

{"session_id": "c2-demo", "hook_event_name": "PreToolUse", "tool_name": "Bash",
 "tool_input": {"command": "pip install skylos-c2-demo-pkg-does-not-exist-4b7e"}}

skylos hook pre-bash --client claude answered:

{
  "hookSpecificOutput": {
    "hookEventName": "PreToolUse",
    "permissionDecision": "deny",
    "permissionDecisionReason": "Skylos blocked this install: 1 package looks hallucinated or typosquatted.\n- PyPI package 'skylos-c2-demo-pkg-does-not-exist-4b7e' does not exist on PyPI (likely hallucinated; an attacker can register it).\nCheck the real package name (docs, registry search) and retry. If the package is internal, install it with your private index/registry flag so Skylos skips the public-registry check. If this package is correct, add it to [tool.skylos] hooks_allow_packages in pyproject.toml."
  }
}

The same hook, on other commands from the same run:

CommandResult
pip install reqeustsdenied: "'reqeusts' does not exist on PyPI"
uv add numpyydenied: "'numpyy' does not exist on PyPI"
npm install expresssdenied: "'expresss' exists but is a possible typosquat: Name closely resembles popular npm package 'express'"
pip install requests fastapiallowed (no output)
ls -laallowed without a registry lookup

The hook only looks at install commands: pip/pip3/pipx install, python -m pip install, uv pip install, uv add, poetry add, npm install|i|add, pnpm add, yarn add, bun add, go get and go install. For exact pins it also checks that the version exists. This is the defence against slopsquatting: a model invents a package name, and someone registers it.

Allow your own names (internal packages, deliberate look-alikes) in pyproject.toml:

[tool.skylos]
hooks_allow_packages = ["internal-pkg", "npm:my-reactt"]

If the command points at a private index or registry (--index-url, --registry, PIP_INDEX_URL= and similar), Skylos skips the public-registry check. An unreachable registry never blocks an install.


Example 2: a PreToolUse hook that blocks reading a secret

The test repository had a GitHub token on line 3 of pkg/settings_local.py. When Claude's Read tool asked for that file, skylos hook pre-read --client claude answered:

{
  "hookSpecificOutput": {
    "hookEventName": "PreToolUse",
    "permissionDecision": "deny",
    "permissionDecisionReason": "Skylos blocked reading pkg/settings_local.py: it contains 2 likely secret(s) (generic secret; github secret) on line(s) 3. Reading it would send the credential to the model provider. Read only the lines you need with offset/limit that skip those lines, or ask the user to move the secret into the environment or a secret manager."
  }
}

The message names the file, the lines and the kind of secret, never the value. A Read whose offset/limit window stays at least one line clear of the secret is allowed (Skylos adds one line of slack because clients count lines differently). Test files are scanned too. Binary files and files over 2 MB are skipped.

Since Skylos 5.7.0, pre-bash blocks the shell route too. Asked to run cat .env on a file with a GitHub token on line 2, skylos hook pre-bash --client claude answered:

{
  "hookSpecificOutput": {
    "hookEventName": "PreToolUse",
    "permissionDecision": "deny",
    "permissionDecisionReason": "Skylos blocked this command: it would print 1 likely secret(s) (github secret) from .env line(s) 2. Command output goes to the model provider. List variable names without values (cut -d= -f1 .env), print only the lines you need (sed -n '10,40p', grep, head/tail) skipping those lines, check a variable is set without printing it (test -n \"$NAME\" && echo set), or ask the user."
  }
}

Commands that print only the lines without the secret still run, such as cat .env | grep PORT or cut -d= -f1 .env. It is not a sandbox: a program that opens the file itself, such as python -c "print(open('.env').read())", gets through.


Example 3: a PostToolUse hook that checks the lines Claude just wrote

Claude wrote os.system('echo hi ' + name) into a Click command. skylos hook post-edit --client claude answered:

{
  "decision": "block",
  "reason": "Skylos found 1 issue(s) in the lines you just changed. Fix them before moving on:\n- pkg/tool.py:8 SKY-D212/SKY-D203 Possible command injection (os.system): tainted input. -> Remove the unsafe sink or validate, escape, or parameterize the untrusted input.\nCheck again with: skylos hook recheck pkg/tool.py"
}

PostToolUse runs after the file is written, so this doesn't undo the edit; it tells Claude to fix it. The hook runs skylos verify on the changed lines with security and secret checks on, and keeps only findings on those lines, so existing debt elsewhere in the file is never reported.

It blocks only on secrets (SKY-S*); untrusted input (a web-route, CLI or MCP-tool parameter, request.*, input(), sys.argv, environment variables, stdin or parse_args()) reaching a dangerous call; calls that are dangerous whatever the input (pickle.loads, disabled TLS or JWT verification, Trojan Source characters, and eval/exec/os.system/shell=True/yaml.load with a non-constant argument); and references that don't exist (SKY-D222, D224, D225, L012, L023). Other findings on the changed lines go to Claude as non-blocking notes in additionalContext. Writing a secret into a Git-ignored .env file is not blocked; writing it into a tracked file is.


Example 4: a Stop hook that won't let Claude finish with open issues

Without fixing pkg/tool.py, Claude tried to stop. skylos hook stop --client claude answered:

{
  "decision": "block",
  "reason": "Skylos: 1 issue(s) you introduced in this session are still open. Fix them (or explain why they are false positives) before finishing:\n- pkg/tool.py:8 SKY-D203/SKY-D212 Use of os.system() -> Remove the unsafe sink or validate, escape, or parameterize the untrusted input.\nCheck again with: skylos hook recheck pkg/tool.py"
}

On the next attempt, with stop_hook_active: true and nothing changed, it let Claude stop and warned you instead of looping:

{"systemMessage": "Skylos: 1 issue(s) introduced this session are still open. Check again with: skylos hook recheck pkg/tool.py"}

After Claude replaced os.system with subprocess.run([...]), the post-edit hook was silent and the stop hook answered {}.

If you commit a [tool.skylos.done] table to pyproject.toml, the same stop hook also runs the done checks: it re-runs your tests and blocks when tests were deleted or skipped. That is why its timeout is long. A minimal test-running Stop hook script, and the real output when Claude deletes a failing test, are on the Claude Code Stop hook page.


Example 5: pre-commit hooks for AI agents

For secret scanning in pre-commit across file types, the other scanners you can use and what --no-verify skips, see secret scanning in pre-commit.

A Git pre-commit hook runs on git commit, including commits the agent makes. Skylos ships a staged-files check for it:

# .git/hooks/pre-commit (chmod +x)
#!/bin/sh
exec skylos agent pre-commit

In a test repository, we staged a change that "tidied" a Django view and dropped @login_required. The commit was refused (git commit exited 1):

Commit check: reviewing 1 source staged file(s). Checks security, secrets, and
high-signal quality regressions on production source/config.
1 issue(s) found in staged files (1 quality):
  HIGH app/views.py:5 Security control regression: Auth decorator
@login_required was removed

The weakness is well known: git commit --no-verify skips the hook. This 15-line PreToolUse hook refuses that, and the core.hooksPath override, before the command runs:

#!/usr/bin/env python3
"""PreToolUse hook: refuse git commands that skip the pre-commit hook."""
import json
import re
import sys

command = json.load(sys.stdin).get("tool_input", {}).get("command", "")
if re.search(r"\bgit\b.*(--no-verify\b|core\.hooksPath)", command):
    print(json.dumps({
        "hookSpecificOutput": {
            "hookEventName": "PreToolUse",
            "permissionDecision": "deny",
            "permissionDecisionReason": "Don't skip the pre-commit hook. Fix what it reports, then commit again.",
        }
    }))
sys.exit(0)

Fed git commit -m "wip" --no-verify and git -c core.hooksPath=/dev/null commit -m wip, it printed the deny; for git commit -m "add tests" it printed nothing. Register it as another PreToolUse entry with "matcher": "Bash". It is a pattern match, not a sandbox: an agent that wants to can still delete .git/hooks/pre-commit. That is why the pull request needs its own check (below).


Codex hooks

skylos agent install-hooks --codex writes .codex/hooks.json. This is the dry-run output:

{
  "hooks": {
    "UserPromptSubmit": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "skylos hook session-start --client codex || exit 0",
            "timeout": 30,
            "statusMessage": "Skylos: recording the starting checkout"
          }
        ]
      }
    ],
    "PreToolUse": [
      {
        "matcher": "^Bash$",
        "hooks": [
          {
            "type": "command",
            "command": "skylos hook pre-bash --client codex || exit 0",
            "timeout": 30,
            "statusMessage": "Skylos: checking packages"
          }
        ]
      }
    ],
    "PostToolUse": [
      {
        "matcher": "apply_patch|Edit|Write",
        "hooks": [
          {
            "type": "command",
            "command": "skylos hook post-edit --client codex || exit 0",
            "timeout": 120,
            "statusMessage": "Skylos: verifying edit"
          }
        ]
      }
    ],
    "Stop": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "skylos hook stop --client codex || echo '{}'",
            "timeout": 5460,
            "statusMessage": "Skylos: checking session edits"
          }
        ]
      }
    ]
  }
}

Codex has no pre-read hook, because Codex reads files through the shell rather than a separate read tool. From 5.7.0, pre-bash covers those shell reads. The responses use the same JSON shapes as Claude Code (permissionDecision: "deny" for pre-bash, decision: "block" for stop). Codex skips new hooks until you trust them: open /hooks in Codex and trust the Skylos entries. Codex's own reference is developers.openai.com/codex/hooks.

For the full Codex walkthrough on Skylos 5.7.0 (where Codex looks for hooks.json, the /hooks trust step, real pre-bash and Stop output), see Codex hooks: examples, hooks.json and a merge check.


Cursor hooks

skylos agent install-hooks --cursor writes .cursor/hooks.json:

{
  "hooks": {
    "beforeSubmitPrompt": [
      {
        "command": "skylos hook session-start --client cursor || echo '{\"continue\":true}'",
        "timeout": 30
      }
    ],
    "beforeReadFile": [
      {
        "command": "skylos hook pre-read --client cursor || echo '{\"permission\":\"allow\"}'",
        "timeout": 15
      }
    ],
    "beforeShellExecution": [
      {
        "command": "skylos hook pre-bash --client cursor || echo '{\"permission\":\"allow\"}'",
        "timeout": 30
      }
    ],
    "afterFileEdit": [
      {
        "command": "skylos hook post-edit --client cursor || exit 0",
        "timeout": 120
      }
    ],
    "stop": [
      {
        "command": "skylos hook stop --client cursor || echo '{}'",
        "timeout": 5460,
        "loop_limit": 10
      }
    ]
  },
  "version": 1
}

Cursor's answers have a different shape. For a made-up package, beforeShellExecution got {"permission": "deny", "user_message": "Skylos blocked this install: ...", "agent_message": "Skylos blocked this install: ..."}; for ls -la it got {"permission": "allow"}. Cursor's afterFileEdit has no way to send feedback to the agent, so on Cursor the edit findings arrive at stop as a followup_message. Cursor reloads hooks.json by itself. More on Cursor's run modes and Bugbot: Cursor security scanner for Python.


Fail open, but never silently

Every hook command ends in || exit 0 (or the client's "allow" answer). Skylos always exits 0 and puts its decision in JSON, so a non-zero exit can only mean "not installed, too old or broken here", and the wrapper turns that into a no-op. A crashing checker doesn't stop your agent. An unchecked action is never shown as checked, though:

Skylos could not check this edit: internal error (RuntimeError). It was allowed without a check.

Unchecked actions are recorded in .skylos/cache/hook-fail-open.json and listed once at stop. Two cases stay silent: a hook you turned off on purpose, and a Skylos that isn't installed at all.


Latency

Skylos's own measurements, from docs/agent-hooks.md (Apple Silicon laptop, skylos hook run as a subprocess, 10 runs each):

HookCasep50
post-edit13-line file in a small project0.54 s
post-edit25-line file in a repo of about 1,300 Python files, warm index1.14 s
post-editfirst run in a project, no index yet (one-time)5.7 s
pre-readsmall file containing secrets (blocked)0.11 s
pre-bashunrelated command (ls -la)0.08 s
pre-bashpip install requests fastapi, registry answers cached0.29 s
stopone edited file, unchanged since post-edit0.09 s

On a large repo, run skylos agent warm-cache once after installing so the first edit doesn't build the project index.


What these hooks don't do

  • They are not a sandbox. They don't restrict which commands run, which files are touched or what the network can reach.
  • They don't undo an edit. PostToolUse runs after the file is written.
  • They only judge lines the agent added. A deletion that removes a sanitizer or an auth decorator is not attributed to the edit. The done checks don't report a removed @login_required either. Use the pre-commit check above or the removed-controls scan.
  • They don't guard every read. Common shell reads such as cat .env are blocked from 5.7.0, but a program that opens the file itself, find ... -exec cat, xargs cat and git show HEAD:.env are not, and neither are files the secrets scanner doesn't read (.npmrc, ~/.aws/credentials).
  • Lockfile and URL installs get lighter checks. npm ci, uv sync and pip install -r get the malware check over every locked package, and git or URL sources ask you first. go mod download and package.json ranges without a lockfile are not checked at install time. Scan manifests with skylos . -a.
  • They don't check shell edits at edit time (sed -i, heredocs). Stop still re-checks files that earlier edits recorded.
  • They cover Claude Code, Codex and Cursor only. There is no Skylos installer for GitHub Copilot's hooks.
  • An agent with file access can turn them off by editing its own hook config. skylos done reports edits to .claude/settings.json, .codex/hooks.json and .cursor/hooks.json as SKY-A114, but the real answer is a required check the agent can't edit.

Turn one off, or remove them

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

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

Uninstall removes only hooks whose command runs skylos hook <event>; for Cursor it printed "Removed 5 Skylos hook(s)" and left {"hooks": {}, "version": 1}. The installer also writes .skylos/.gitignore so the hooks' local state (cache/, agent-session.*, hook.log*, receipts/) stays out of Git.


Add the merge gate

Hooks catch problems while the agent works. The pull request still needs a check that runs whether or not anyone installed hooks:

skylos cicd init --no-upload

This writes .github/workflows/skylos.yml with a changed-line scan job ("Skylos Quality Gate") and, when Skylos finds a pytest project or a test_command, a "Skylos Done" job that runs your tests and checks for deleted or skipped tests. It needs no Skylos account or API key; --no-upload leaves out the Skylos Cloud upload job. Make the jobs required checks on your default branch.

One gap to know about in 4.47.1: the generated scan job runs with --diff, which keeps only findings on changed lines, and a removed decorator has no changed line left. In our test it did not report a deleted @login_required, and the job passed. Add the removed-controls job if a removed auth check must fail the PR.


Other ways to do this

You don't need Skylos to use hooks. Anthropic's hooks guide shows the event model and JSON fields; the pydevtools guide How to stop AI agents from bypassing pre-commit hooks walks through deny rules, a PreToolUse hook and a Git wrapper; and the block-no-verify-hook skill in wshobson/agents packages the --no-verify guard. Write your own when you need one rule; use an installer like Skylos's when you want the registry lookups, the secret scanner and the edit checks maintained for you.


References


Try it

pip install skylos
skylos agent install-hooks --dry-run    # see exactly what it would write
skylos agent install-hooks

Running this across a team? These checks are free in the CLI. Skylos Cloud keeps the results in one place: the Free plan adds a pass/fail check on pull requests and scan history for one project, and the Workspace plan adds up to 10 projects, approvals for findings you decide not to fix, pull request comments, and audit exports.