AGENT SKILL

agentworks-author-hook

How to write or edit a lifecycle hook in this AgentWorks project: hook.md frontmatter, choosing vendor-specific event names, matchers and timeouts, the command it runs, and safety review. Use when creating or changing anything under hooks/.

License 许可
MIT
最近更新
2026-10-07
Stars
★ 0
Forks
0

01 前言 Front Matter

name
agentworks-author-hook
description
How to write or edit a lifecycle hook in this AgentWorks project: hook.md frontmatter, choosing vendor-specific event names, matchers and timeouts, the command it runs, and safety review. Use when creating or changing anything under hooks/.

03 SKILL.md 正文

Authoring a hook

A hook runs a shell command automatically on a harness lifecycle event (before a tool runs, at session start, after a file edit, ...).

Create it

agentworks new hook <name> --description "What it enforces or reports, and on which event"

Or --from-template <id> (pre-commit-lint, notify-webhook).

hooks/<name>/hook.md

hook.md frontmatter

---
kind: hook
name: pre-commit-lint         # required; matches directory
description: Runs the linter before a tool use proceeds, blocking on failure.
version: 0.1.0
events: [PreToolUse]          # required together with command
command: ./scripts/lint.sh
---

That events + command form is shorthand for one handler per event. For a matcher, a timeout, or different commands per event, list handlers instead:

handlers:
  - event: PreToolUse
    matcher: Bash               # optional filter; a regex for tool events on most vendors
    command: ./scripts/check-bash.sh
    timeout: 30                 # optional, seconds
  - event: SessionStart
    command: ./scripts/hello.sh

Rules:

  • Use either handlers or the events + command shorthand, never both. The shorthand's two fields must be set together; validate fails if only one is set, and export fails if the hook declares no handlers at all. Every handler needs an event and a command; timeout is seconds and never negative.
  • events values are passed through to the target unchanged, so use that vendor's own names:
    • Claude Code and GitHub Copilot: PreToolUse, PostToolUse, SessionStart, ... (Copilot accepts PascalCase or camelCase).
    • Cursor: beforeShellExecution, afterFileEdit, preToolUse, ...
    • Gemini CLI: its own set. Check the vendor docs. A hook meant for several vendors may need one hook artifact per vendor.
  • A matcher filters when a handler fires; without one it fires for every occurrence of the event. All four hook-capable targets support matcher and timeout (AgentWorks converts seconds to Gemini CLI's milliseconds). Cursor honors matcher only on some events; see its docs.
  • A hook can bundle a script: put it in the hook's directory and refer to it as "${ARTIFACT_DIR}"/scripts/check.sh in the command. claude-code ships the files and resolves the path; other targets skip such a hook with a warning (they have no documented way to locate a plugin's files), so use an inline command for a hook meant for them.
  • If several hooks share an event, all run; none replaces another.

Safety

command runs on every trigger with the user's permissions. agentworks validate flags patterns like curl | sh, base64 -d, eval $(...), /dev/tcp, nc -e, chmod +s, and sudo; treat each warning as a real review item. Keep commands short, call a script kept in the repo, and never inline secrets — reference env vars.

Body

Explain what the hook does, why, and how to disable it. Nothing in the body is executed.

Finish

agentworks doctor hooks/<name> (is the command's binary on PATH?), agentworks validate, agentworks export.

04 同仓库更多 Skills

mtfuller
mtfuller/agentworks

agentworks-evals

How to write and run behavior-eval cases for a skill or agent in this AgentWorks project: the evals/*.yaml format, text, tool-call, and activation assertions, trigger cases, rubrics and a judge, runner protocols (text and json), repeated runs, and agentworks eval. Use when asked to test, evaluate, or regression-check how a skill or agent responds, or whether its description makes a model choose it.

★ 0
mtfuller
mtfuller/agentworks

agentworks-cli

How to scaffold, validate, build, test, run, export, import, and publish this project's agents, skills, MCP servers, and hooks with the agentworks CLI. Use whenever asked to add, change, check, ship, or import an artifact in this project.

★ 0
mtfuller
mtfuller/agentworks

agentworks-author-skill

How to write or edit a skill in this AgentWorks project: skill.md frontmatter, the description that decides when it triggers, entrypoint/scripts/tests layout, and build/test commands. Use when creating or changing anything under skills/.

★ 0
mtfuller
mtfuller/agentworks

agentworks-author-mcp

How to write or edit an MCP server in this AgentWorks project: mcp.md frontmatter, local (stdio) versus remote (http/sse) servers, command, args, env and auth, source and tests layout, and the build, test, doctor, and run loop. Use when creating or changing anything under mcp/.

★ 0
mtfuller
mtfuller/agentworks

agentworks-author-agent

How to write or edit an agent (subagent) in this AgentWorks project: agent.md frontmatter, portable tools and model settings, writing the instructions, and resources. Use when creating or changing anything under agents/.

★ 0
mtfuller
mtfuller/agentworks

csv-analyzer

Analyze a CSV file and flag rows that stand out.

★ 0