Skip to content
Back to skills

Hooks

BSecurity

Sets up the project's own automation in Antigravity (like Claude Code's hooks in settings.json): run tests or a formatter after edits, block changes to certain files, keep a checklist before finishing, add a reminder before each step, as .agents/hooks.json plus small scripts in the repository. Use when the user asks for something to happen automatically («пусть после каждой правки…», «всегда перед завершением…», «не давай трогать…», /hooks). Not on your own unless the user granted full access.

  • 2 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added December 3, 2026
developmentpythongo

Works with

  • claude code

Security analysis

B75/100
  • criticalPipes output to a shell interpreter

Pro shows the line behind each finding and how to fix it

Scanned December 3, 2026

npx -y skills add stxrmik/antigravity-plus --skill hooks --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Hooks?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Hooks
[![Security: B — Skills Directory](https://www.skillsdirectory.com/api/skills/stxrmik-hooks/badge)](https://www.skillsdirectory.com/skills/stxrmik-hooks)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: hooks
description: >-
  Sets up the project's own automation in Antigravity (like Claude Code's hooks in settings.json): run tests or a
  formatter after edits, block changes to certain files, keep a checklist before finishing, add a reminder before
  each step, as .agents/hooks.json plus small scripts in the repository. Use when the user asks for something to
  happen automatically («пусть после каждой правки…», «всегда перед завершением…», «не давай трогать…», /hooks).
  Not on your own unless the user granted full access.
---

# /hooks — automation for this project

> **Only on the user's request, or under full access:** it changes the project's configuration.

Antigravity runs hooks from `.agents/hooks.json` at the project root (and from plugins). A hook is a command that
gets a JSON payload on stdin and prints a JSON answer on stdout. The command runs via `sh -c` from the folder that
holds `hooks.json`.

## Events and answers
| Event | When | Answer (stdout) |
|---|---|---|
| `PreToolUse` (with `matcher`: tool name regex, e.g. `run_command`, `write_file\|edit_file`) | before a tool runs; payload has `toolCall {name, args}` (`args.Path`, `args.CommandLine`) | `{"decision": "allow"}` = no objection; `"deny"` + `"reason"` blocks (the agent sees the reason); `"ask"` / `"force_ask"` asks the user |
| `PostToolUse` (with `matcher`) | after a tool ran; payload adds `error` | `{}` |
| `PreInvocation` | before every model call | `{"injectSteps": [{"systemMessage": {"systemMessage": "…"}}]}` (or with `"metadata": {"user_markdown": "…"}`; empty `"systemMessage": ""` shows a UI-only banner at 0 model tokens) or `{}` |
| `Stop` | the agent ends its turn; payload has `terminationReason` (`NO_TOOL_CALL` = normal), `fullyIdle`, `executionNum` | `{"decision": "continue", "reason": "…"}` sends it back to work; `{}` lets it stop |
| `SessionStart` | a conversation starts | `{"injectSteps": [{"systemMessage": {"systemMessage": "…"}}]}` (also supports `"metadata": {"user_markdown": "…"}`) |

Every payload also has `conversationId`, `workspacePaths`, `transcriptPath`, `lastUserInput`.
**Pitfall:** for `PreToolUse`, an empty `{}` means **deny**. A hook that should only watch must print
`{"decision": "allow"}`.

## Steps
1. **Pin down the behavior** in one sentence: event, trigger, effect. If it's ambiguous, ask one question.
2. **Prefer the cheap event.** A full test run belongs in `Stop` (once per turn), not `PostToolUse` (every edit).
   A formatter on the changed file belongs in `PostToolUse`.
3. **Write the script** in `.agents/hooks/<name>.sh` or `.py`. Read the payload from stdin, act, print valid JSON, and
   exit 0 even on failure: a crashing hook must never block the agent. Keep it fast and set a `timeout` (seconds).
4. **Register it**: create or extend `.agents/hooks.json` (keep the other hooks), e.g.
   ```json
   {
     "project-format": {
       "PostToolUse": [{"matcher": "write_file|edit_file",
                        "hooks": [{"type": "command", "command": "sh hooks/format.sh", "timeout": 20}]}]
     },
     "project-tests-before-done": {
       "Stop": [{"type": "command", "command": "python3 hooks/tests_gate.py", "timeout": 300}]
     }
   }
   ```
   Paths in `command` are relative to `.agents/`. Add `"enabled": false` to switch a hook off.
5. **Test it locally** before reporting: pipe a sample payload into the script and check the JSON, e.g.
   `echo '{"toolCall": {"name": "edit_file", "args": {"Path": "app/main.py"}}}' | sh .agents/hooks/format.sh`.
6. **Report** in 2–3 lines: what runs when, how to switch it off, that it applies to new conversations.

## Recipes
- **Format after an edit** (PostToolUse): take `args.Path`; if it's a `.py` file, run `ruff format`, for `.ts`/`.js`
  run `npx prettier --write`. Print `{}`. The file changes after the agent's edit, so it has to re-read it before the
  next edit (Antigravity Plus asks it to).
- **Tests must pass before finishing** (Stop): if `terminationReason` is `NO_TOOL_CALL`, run the test command. On
  failure print `{"decision": "continue", "reason": "tests fail: <last lines>"}`. Count attempts in a file under
  `/tmp` keyed by `conversationId` and give up after 2, so the agent can't loop forever.
- **Protect files** (PreToolUse on `write_file|edit_file`): for paths matching `migrations/` or `*.lock`, print
  `{"decision": "deny", "reason": "<why and what to do instead>"}`; otherwise `{"decision": "allow"}`.
- **A reminder before each step** (PreInvocation): print `{"injectSteps": [{"systemMessage": {"systemMessage": "…"}}]}`
  (replaces deprecated `ephemeralMessage`, which Antigravity now converts into one). A `systemMessage` stays in the
  conversation for good (until compaction) and the model re-reads it on every later call, so inject only when
  something changed and keep it short; to
  show a user-only UI badge at 0 model tokens, set `"systemMessage": ""` and `"metadata": {"user_markdown": "…"}`.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.