Contributing: this repository owns the shared runtime core. Private deployments consume a pinned public revision and keep their settings and data separate. See CONTRIBUTING.md.
WorkflowHooker runs small, configurable workflow checks at lifecycle events
exposed by supported coding-agent hosts. It is local-first, performs no
network requests in its built-in checks, uses hook-master for provider formatting, and is silent until checks are
explicitly enabled.
closing_gate: reports an active project lock or an uncommitted working tree.drift_warning: warns when changes span more top-level directories than a configured threshold.scope_guard: warns when the number of changed files exceeds a configured threshold. Withprotected/allowedpath lists it also denies Edit, Write, MultiEdit and NotebookEdit on those paths (PreToolUse, Claude Code plugin orinstall-snippet --variant action-guard).- File, Git, and task-plan state sources with a configurable source order.
- Provider adapters for Claude Code, Codex CLI, Kimi Code CLI, Git, and manual execution.
- Per-session message budgets, cooldowns, and idle self-disabling.
- An opt-in action guard whose failures deny only the matched critical file action, independently of advisory budgets.
- An opt-in completion gate that requests exactly one evidenced rework round
(Claude Code:
{"decision": "block", "reason": ...}, so the finding reaches the model) and then reports residual findings without another stop loop.
The drift and scope checks are heuristics. They report observable counts; they do not claim to understand the user's task or whether tests ran.
WorkflowHooker requires Python 3.10 or newer.
python -m pip install .For development:
python -m pip install -e ".[dev]"
python -m pytestCreate workflowhooker.toml:
[mode]
checks = ["closing_gate"]
max_messages_per_session = 3
cooldown_minutes = 5
idle_disable_after = 20
[sources]
order = ["files", "git", "taskplan"]
[identity]
owner = "agent-or-operator-id"
scope = "ticket-or-task-scope"
host = "host-id"
target = "canonical-target-id"
[action_guard]
enabled = false
[stop_gate]
enabled = false
ownership = "lock" # "session": changes since the session's first hook count as own, no lock needed
max_rework_rounds = 1
[checks.drift_warning]
max_touched_dirs = 4
[checks.scope_guard]
max_changed_files = 15
# Path rules, relative to the project folder; active when "scope_guard" is in [mode] checks.
# protected = ["vendor/", "*.lock"] # Edit/Write/MultiEdit/NotebookEdit on these paths are denied
# allowed = ["src/", "tests/"] # if set, nothing else may be edited (also outside the project)Path patterns: dir/ or dir/** (a folder and everything below it), an exact relative path, or a glob such as
*.lock (a pattern without / also matches the file name in any folder); matching ignores case. Shell commands
(Bash, PowerShell) are not inspected, so the path rules are a guard rail against edits, not a sandbox.
Patterns with a / are anchored at the project root: vendor/ protects <project>/vendor/ and everything below
it, but not src/vendor/. List every folder you mean (protected = ["vendor/", "src/vendor/"]). ** has no
recursive meaning (matching is fnmatch on the relative path), so **/vendor/ is not a way around this. Only
patterns without / (such as *.lock or .env) match the file name in any folder. Chosen over glob support
because it is the existing, predictable contract and one extra line per folder is cheap; a silently
over-matching glob would turn a guard rail into a surprise lock-out.
The scope guard is a guard rail, not a security boundary, and no lock may need the user to be lifted. So:
- Fail-open with a visible notice (
systemMessage): the configuration cannot be loaded (TOML syntax error, invalid value such asownership), the hook payload is unreadable, or the target path cannot be determined. The edit goes ahead; the message names the file and the cause and says the guards are inactive until the configuration is repaired. It repeats on every edit until then. - Always editable:
workflowhooker.tomlitself, even whenalloweddoes not list it. - Still denies: an edit that a readable
protected/allowedrule matches (the reason reaches the model), and - only if you enabled[action_guard]and the configuration is readable - a foreign hard lock or an unreadable payload on that opt-in guard. - The Stop gate never blocks more than one round; when no round was triggered (only foreign or unclear state), the message says "remaining findings (no rework round triggered)" instead of claiming a round ran.
Without a configuration file, checks is empty and the program emits no
workflow warnings.
python -m workflowhooker --config workflowhooker.toml check
python -m workflowhooker providers
python -m workflowhooker install-snippet --provider codex
python -m workflowhooker install-snippet --provider kimi
python -m workflowhooker install-snippet --provider codex --variant action-guardinstall-snippet prints a configuration fragment. It never edits a host
configuration. Review and merge the fragment manually, using an absolute
Python executable and explicit configuration/state paths where appropriate.
The generated default snippets do not install PreToolUse warnings. Kimi's
Stop adapter uses the host's blocking exit contract, while prompt-time
messages use plain text. Provider behavior can change, so validate generated
snippets against the host version you deploy.
The action-guard variant is a separate, explicit opt-in. It evaluates only
file actions whose targets can be derived without guessing:
| Provider | Covered action channel | Native result |
|---|---|---|
| Claude Code | Edit, Write, MultiEdit, NotebookEdit path fields |
deny / native ask; silent allow keeps the host's normal permission flow |
| Codex | canonical path headers in apply_patch input |
deny; an internal ask safely falls back to deny because Codex PreToolUse does not currently implement ask |
| Kimi Code | WriteFile, StrReplaceFile, DeleteFile, MoveFile path fields |
exit 2 deny; an internal ask safely falls back to deny |
The adapters follow the providers' documented contracts rather than assuming one cross-provider schema: Claude Code hooks, Codex hooks, and Kimi Code hooks.
WorkflowHooker does not claim target-level guard coverage for Bash, PowerShell, unified exec commands, or arbitrary MCP arguments. Those channels can carry paths inside free-form or tool-specific data that this release does not parse. Provider-native hook failures and timeouts may also be fail-open; the guard is therefore defense in depth, not the sole security boundary.
Internally, results retain separate surfaces for action guards, context,
stopping, and side effects. Evidence is clean, finding, or unknown, and
applicable decisions combine as deny > ask > allow. A technical failure on
an enabled hard action guard (readable configuration) is unknown + deny for that one matched action;
an unreadable configuration or scope-guard payload fails open with a visible notice (see above). An
advisory/context failure does not globally stop otherwise authorized work.
The optional stop gate correlates owner, scope, host, session, configured identity target, canonical project target, lock kind, and Git worktree state. Its one-round state is keyed by that full identity. A mismatched state hash or runtime identity is reported as unreliable residual state and cannot start a fresh round. The complete Stop load/evaluate/save transaction is serialized by a per-state-file process lock; lock failures or timeouts use the same non-blocking unknown residual. It checks the main clone when the event comes from an isolated worktree. Only an owned, correlated finding can request the one rework round.
Ownership has two sources. ownership = "lock" (default) accepts only an own
lock with the full identity above. ownership = "session" additionally
takes a baseline at the first UserPromptSubmit, SessionStart or
PreToolUse of a session (relative paths of the uncommitted files plus a
content hash) and counts what is new or different at Stop as the session's own
evidence; changes that were already open stay untouched and are only named.
Without a baseline (no such hook ran) the gate never blocks. The limit: the
baseline cannot tell two agents in the same working tree apart, and a file that
another process keeps rewriting counts as changed; use lock there. A second Stop, a host-provided
stop_hook_active, foreign state, or damaged state returns a residual warning
without another block. WorkflowHooker never deletes locks, resets diffs, or
otherwise cleans foreign work.
This repository is also the Claude Code plugin workflowhooker. It wires hook-run to Stop, PreToolUse
(matcher Edit|Write|MultiEdit|NotebookEdit), PreCompact and UserPromptSubmit and stays silent until the
project contains workflowhooker.toml; /workflowhooker:gates init creates a starter file (closing gate with one
rework round and ownership = "session", no taskplan source, commented path rules). Skill: workflow-gates.
What reaches Claude: on Stop the closing gate answers {"decision": "block", "reason": ...} once, so the open
points are in the model's context and it works one more round; on the second Stop (stop_hook_active, or the round
is spent) it only shows the residue to you and never loops. A denied edit carries permissionDecisionReason, which
Claude sees. Both need no lock file with the starter configuration.
/plugin marketplace add ellmos-ai/ellmos-plugins
/plugin install workflowhooker@ellmos
Data flow: local files and git only, nothing is sent over the network. Python 3.10+ is required (py -3 on Windows,
or set ELLMOS_PYTHON). Compatibility: Claude Code (hooks, command, skill); Codex through its own hook snippet
(install-snippet --provider codex). The plugin hooks read the hook payload, workflowhooker.toml, project files
and git status; they do not read conversation transcripts. They keep counters, hashes and, with
ownership = "session", the relative paths of the uncommitted files at session start with a content hash each,
in ~/.workflowhooker/ (override with WORKFLOWHOOKER_STATE_DIR). The plugin ships its one dependency,
hook_master, in vendor/ at the commit pinned in pyproject.toml (python tools/vendor_hook_master.py
regenerates it). Privacy and support: https://ellmos-ai.github.io/plugins.html.
Examples:
/workflowhooker:gates initin a git repository, then ask Claude to fix a bug and "tell me when you are done". If Claude stops with uncommitted changes of this session, the Stop is blocked once and the reason names them ("1 open change(s) from this session (calc.py) ... close it, e.g. commit, or give the reason"); Claude commits or explains. The same Stop a second time only reports. Changes that were already uncommitted before the session are named but not demanded. Reproduce without Claude:echo '{"session_id":"s","cwd":"."}' | python -m workflowhooker --config workflowhooker.toml hook-run UserPromptSubmit, edit a file, thenecho '{"session_id":"s","cwd":"."}' | python -m workflowhooker --config workflowhooker.toml hook-run Stop(needsPYTHONPATHwith the plugin folder andvendor/).- Add
"scope_guard"to[mode] checksandprotected = ["vendor/"]under[checks.scope_guard], then report a bug whose cause sits invendor/: the edit is denied with the rule as the reason and Claude has to fix the cause elsewhere or report back. - Add
"drift_warning"to[mode] checksand ask for a refactor that spreads across many folders. Once more thanmax_touched_dirstop-level folders have changes, the hook reports a drift hint naming them. /workflowhooker:gates statusruns the configured checks once and reports which gates are active and what they currently find.
WorkflowHooker reads local project state and stores a small JSON state file per
session. It does not transmit project data. Generated snippets may contain
paths supplied by the caller; inspect them before sharing logs or reports.
Guard diagnostics use fixed reason text and never echo hook inputs, lock-file
contents, or exception strings. Stop state is written through an atomic file
replacement and guarded by a small sibling .lock file so interrupted or
concurrent writes cannot silently reset the one-round gate. The round count and
evidence fingerprint are included in the runtime integrity digest.
See SECURITY.md for private vulnerability reporting and PROVENANCE.md for source-history and BACH lineage notes.
- COMA: Local, file-based agent-job coordination and process startup/status; complements WorkflowHooker's lifecycle checks.
MIT. See LICENSE.
Enable [compaction] enabled = true in a TOML file. The notice uses Codex
SessionStart with source = compact and hookSpecificOutput.additionalContext.
Redisplayed user messages may be historical; the model should reconcile completed
work and current goal status while respecting genuinely new corrections. This is
model guidance, not a guarantee against loops. PostCompact is not the context
channel.
python -m workflowhooker install-snippet --provider codex --variant compactionThe registration contains only SessionStart, matcher ^compact$, timeout 10.
Set the installed interpreter and an absolute config path in both command
fields, preserving shell-appropriate quoting. For a Windows PowerShell session,
commandWindows needs the call operator before a quoted executable:
& "C:/path/to/venv/Scripts/python.exe" -m workflowhooker --config "C:/path/to/workflowhooker.toml" hook-run SessionStart --provider codexKeep the POSIX command without &. The shared hook-master provider adds the
operator when generating Codex Windows snippets; this also covers the normal,
session-start and action-guard variants. Codex shadow commands apply the same
rule. Bare executable names get no &; the exit-code wrapper below applies to them too. A changed definition must
be reviewed again through /hooks before Codex runs it.
Generated commandWindows entries also keep the native exit code. Codex runs
Windows hooks through pwsh -Command, which reports every non-zero exit as 1,
so an exit-code block (exit 2, for example hook-run Stop --block) would show
up as a failed hook instead of a block. The generated form is
$global:LASTEXITCODE = 0; <command>; $hookOk = $?; if ($LASTEXITCODE) { exit $LASTEXITCODE }; if (-not $hookOk) { exit 1 }.
Hand-written Codex configurations need the same wrapper. The PreToolUse guard
is not affected: it answers Codex with a JSON permissionDecision and exit 0.
Keep exactly one matching handler. Replace an older wildcard registration of this
same command with the session-start variant before combining both variants;
its matcher excludes compact. --existing produces only a hooks-only merge,
not a replacement for the host configuration. Preserve other settings and trust
data; do not bypass Codex's native hook trust checks.
The compact path reads only input/configuration, never project sources or advisory state. It emits per valid invocation even after the message budget is exhausted. Malformed input is silent. Roll back by disabling the option or removing only this registration. Real manual and automatic compaction must be accepted against the installed Codex version; unit tests alone are not runtime acceptance.
goal reads local goal/task files; loop-briefing formats current work.
[injectors] goal = true enables PreCompact briefings. Policy/location injectors
are independently opt-in (policy = true, location = true) and require
install-snippet --variant session-start. Registry inputs remain local. Scope
inference supports .TOPICS/<scope> and _Local_DEV/repos/<name>; unknown layouts
produce no inferred scope. Optional taskplan and source_resolver integrations
are not bundled.
candidate-collect, candidate-extract, provider-shadow, and boot-context-lint
expose local lifecycle/extraction and lint tools; consult each command's --help.
Candidate recording requires [candidates] enabled = true. No extractor runner
is scheduled automatically. Default hooks and existing action/stop guards retain
their contracts.