Open source hooks library for AI coding agents - Install safety, quality, and automation hooks with a single command
npm install -g @hasna/hookshooks --helphooks installhooks listhooks searchhooks removehooks categorieshooks infohooks doctorhooks run
@hasna/hooks includes unprefixed Codewith-native hook names:
session-start—SessionStartdigest and additional context.prompt-guard—UserPromptSubmitguard for pasted fake policy/freeze/run-this-now content.pre-bash—PreToolUseBash gate for staged secrets scans, scoped destructive-operation blocks, and risky-op comms checks.worktree-guard—PreToolUseguard for managed repos worktree boundaries and file-tool-like payloads touching protected Hasna scopes.stop-sync—Stopturn-end heartbeat/evidence best effort.knowledge-context— deterministic Knowledge context packs forSessionStart,UserPromptSubmit, andSubagentStart.
For Codewith, the installer is renderer-safe by default: it emits a TOML
fragment instead of mutating managed ~/.codewith/config.toml.
hooks install session-start prompt-guard pre-bash worktree-guard stop-sync knowledge-context --target codewithThe scoped destructive-operation guard does not block every cleanup command. It
blocks resolved shell/file-tool targets that threaten ~/.hasna, configured
workspace roots, Hasna division/scope roots, or active repo/worktree roots,
including recursive rm, rsync --delete, destructive find, and destructive
git clean / git reset --hard forms.
Apply that fragment through open-configs or the managed config renderer. A
direct write path exists only for explicit local/test use:
hooks install knowledge-context --target codewith --apply-codewith --codewith-config /tmp/codewith-config.tomlHooks stores data locally by default in ~/.hasna/hooks/ and uses SQLite
directly for hook event history. The package owns its database schema and
migrations; it does not depend on the deprecated shared runtime or its CLI.
The repo includes its own PostgreSQL migration definitions for optional remote
storage deployments. Use the hooks log commands to inspect local hook event
data.
hooks storage status --json
HASNA_HOOKS_DATABASE_URL=postgres://... hooks storage push --tables hook_events,feedback --json
hooks storage pull --json
hooks storage sync --jsonConfigure database storage with HASNA_HOOKS_DATABASE_URL or fallback
HOOKS_DATABASE_URL. Optional storage mode env vars are
HASNA_HOOKS_STORAGE_MODE and HOOKS_STORAGE_MODE, with local, hybrid, or
remote values.
This package is an npm/local CLI, MCP server, and static dashboard package. It does not require a deployed cloud or self-hosted runtime to install or run hooks.
Data is stored in ~/.hasna/hooks/.
Apache-2.0 -- see LICENSE