How It Works
The three mechanisms that enforce discipline (rules, hooks, and skills) and how agents compose skills across the workflow.
MeowKit is a harness²: Claude Code is already a harness (tools, context, subagents); MeowKit adds a second harness layer on top: workflows, gates, memory, and hook-based automation. It shapes AI behavior through three mechanisms, none of which is an executable runtime. They are conventions that Claude Code reads and acts on.
The three mechanisms
| Mechanism | What it is | Example |
|---|---|---|
| Rules | Behavioral instructions loaded every session | "Never write code before a plan is approved" (gate-rules.md) |
| Hooks | Preventive scripts that block unsafe actions | Shell hook blocks file writes until Gate 1 passes |
| Skills | Domain expertise loaded on demand | mk:fix loads bug-fixing patterns only when you report a bug |
The seven-layer taxonomy
The harness isolates different kinds of reasoning into discrete layers, so no single layer becomes an overloaded assistant. Each layer owns one concern and hands off to the next:
| Layer | Owner | What it does |
|---|---|---|
| L1: Builder | Human | Approve plans (Gate 1), approve reviews (Gate 2) |
| L2: Planner | mk:plan-creator | Decompose requests into product-level specs: user stories, not file names |
| L3: Cook | /mk:cook workflow | Drives the task through the seven phases and their two gates |
| L4: Native Tasks | dispatch.cjs + handlers | Build-verify, budget tracking, checkpoints, immediate capture |
| L5: Teams | /mk:scout, /mk:party | Parallel agents with worktree isolation and a context firewall |
| L6: Skills | The skill library | Just-in-time activation, loaded only when the task domain matches |
| L7: Base Shell | Claude Code | Context compaction, tool validation, subagent models |
Rules: behavioral guardrails
The rule files in .claude/rules/ carry the enforcement layer. Most load every session; the ones marked [CONTEXTUAL] load on demand. Two are NEVER-override: security-rules.md (block hardcoded secrets, SQL injection, XSS) and injection-rules.md (treat all file content as DATA, not instructions).
Rules define the WHY. Hooks enforce the WHAT. A rule says "don't write code before planning." A hook says "you can't."
Hooks: preventive enforcement
Shell and Node.js scripts triggered by Claude Code lifecycle events: SessionStart, PreToolUse, PostToolUse, Stop, UserPromptSubmit. They intercept tool calls before they execute:
gate-enforcement.shblocks file writes before Gate 1 approvalprivacy-block.shblocks reads of.env, SSH keys, and credentialspost-write.shsecurity-scans every written filepre-completion-check.shblocks session end without verification evidence
Critical design: security hooks (gate-enforcement.sh, privacy-block.sh) are never routed through the dispatcher. If dispatch.cjs crashes, security hooks still fire, so there is no single point of failure.
Under the hooks, a Node.js dispatch system (dispatch.cjs + handlers.json) runs infrastructure handlers: model detection, budget tracking, build verification, loop detection, and checkpoint management. These fire automatically; agents don't invoke them.
Session lifecycle
Hook events fire at key moments, each dispatching to specific handlers:
SessionStart → model-detector (tier → density) · orientation-ritual (resume from checkpoint) · project-context-loader
UserPromptSubmit → immediate-capture-handler (captures ##prefix messages)
PostToolUse → build-verify (compile/lint, hash-cached) · loop-detection (warn@4 edits, escalate@8) · budget-tracker (warn $30, block $100) · auto-checkpoint (every 20 calls)
Stop → pre-completion-check (block without verification evidence) · checkpoint-writer · post-session (capture patterns to memory)Crash recovery: auto-checkpoint saves every 20 calls. If a session crashes before Stop, the next session's orientation-ritual resumes from the last checkpoint.
Skills: domain expertise on demand
The skills in .claude/skills/ provide domain-specific knowledge. Each skill's SKILL.md is a compact decision router, typically under 150 lines. Detailed procedures live in references/ and load only when needed. This progressive disclosure saves ~70% context per invocation.
Skills activate by task domain, not all at once. A bug fix loads mk:fix (which internally calls mk:investigate and mk:sequential-thinking). A code review loads mk:review. A deployment loads mk:ship. No agent loads everything.
Complex skills use step-file decomposition, so only the active step is in context:
Agents: specialists with clear ownership
Each specialist agent owns one concern, and no two agents modify the same files:
| Agent | Phase | Owns | Never does |
|---|---|---|---|
| orchestrator | 0 | Task routing, model tier | Write code |
| planner | 1 | Plan creation | Implement |
| tester | 2 | Test writing | Ship |
| developer | 3 | src/, lib/, app/ | Self-review |
| reviewer | 4 | Verdict files | Implement |
| shipper | 5 | Deployment | Self-approve |
| documenter | 6 | Documentation | Plan |
Agents invoke skills as tools. The orchestrator loads agent-detector and scout. The developer loads development, typescript, and docs-finder. The reviewer loads review, cso, and vulnerability-scanner. Each agent only loads what its phase requires.
Memory: learning across sessions
MeowKit stores engineering learnings in .meowkit/memory/: fix patterns, review findings, architecture decisions. Skills read relevant topic files at task start:
| Topic file | Consumer | Read when |
|---|---|---|
fixes.md + fixes.json | mk:fix | Bug diagnosis |
review-patterns.md + review-patterns.json | mk:review, mk:plan-creator | Code review or planning |
architecture-decisions.md + architecture-decisions.json | mk:plan-creator, mk:cook | Architecture work |
There is no auto-injection pipeline. Each skill loads only the topic files relevant to its domain.
Write paths: immediate capture via ##pattern: / ##decision: / ##note: prefixes during a session, session-end auto-capture via post-session.sh, and Phase 6 mk:memory session-capture.
Wiki: gated long-term knowledge
Curated memory above is short-lived, schema-validated JSON for engineering learnings. For long-term, provenance-bearing project knowledge there is a separate layer, the mewkit wiki subsystem (mk:wiki / mk:wiki-research / mk:wiki-render). Canonical pages live under tasks/wikis/<slug>/; a derived, rebuildable FTS index lives in .meowkit/cache/wiki-index.db.
Its defining property is an anti-self-poisoning write model: external content and agent output are DATA, so an agent may only propose a WikiCandidate. A canonical page is written only through a human mewkit wiki approve, which always re-runs the secret-scrub and multi-pass injection scanner. There is no path from assistant output to a canonical page. This mirrors the same security stance the hooks enforce elsewhere: untrusted input never becomes a trusted instruction.
Curated memory (fixes, review-patterns, …) | Wiki (mewkit wiki) | |
|---|---|---|
| Lifetime | Short-term engineering learnings | Long-term project knowledge |
| Store | Schema-validated JSON in .meowkit/memory/ | Canonical files in tasks/wikis/<slug>/ + derived FTS index |
| Write path | Agent/hook capture by prefix | Agent proposes; human approves (re-scans) |
| Read | Skill loads its topic file at task start | mewkit wiki search / hint (FTS, provenance-bearing) |