Hooks

Hooks & Pre-Write Checks

How Septum's pre-write hook and Git pre-commit check validate imports before edits land.

septum init can scaffold editor/agent pre-write hooks and a Git pre-commit hook (septum check --staged) while preserving your existing unrelated hooks.

Pre-Write Hook (septum hook pre-write)

septum hook pre-write reads a JSON edit payload from stdin, reconstructs the proposed file content, extracts its imports, and checks them against the module rules stored in .septum/septum.db.

  • Supported payload formats: Full file content (content / CodeContent), targeted string replacements (old_string / TargetContent), multi-chunk edits (edits / ReplacementChunks), and Codex apply_patch diffs.
  • Exit codes & client modes:
    • Policy violations exit with code 1 (or 2 when passed --exit-code-2, --claude, --cursor, --codex, or --opencode).
    • Default mode prints {"decision": "deny", "reason": "..."} to stdout; client flags (--claude, --cursor, --codex, --opencode) write the reason to stderr so stdout stays clean.
    • If .septum/septum.db does not exist or the file is outside any mapped module, the hook exits 0 without blocking.
  • Scope limits: The pre-write hook checks proposed import rules only—not full dependency cycles or runtime behavior. Use septum_boundary or septum check --staged for full audits.

Git Pre-Commit Check

The generated Git pre-commit hook runs:

septum check --staged
  • In warn mode (default), septum check reports violations and exits 0 (advisory).
  • In strict mode (septum check --staged --strict), violations, unresolved imports, or unindexed workspaces exit 1 and block the commit.

Index Freshness & Watcher

While the MCP server is running, Septum's built-in file watcher keeps .septum/septum.db updated in-process—so default harness configs do not need a separate PostToolUse shell hook. For CLI-only workflows, septum-post-write.sh is still available and coalesces bursts using .septum/sync.lock.