Skip to content

Hooks

Hooks are shell commands triggered by lifecycle events. Me Write Code uses the Claude Code hook schema, with Me Write Code config stored under ~/.mewrite/agent/.

Events

EventWhen firesSync?
SessionStartMe Write Code session bootssync, advisory
SessionEndMe Write Code exitssync, advisory
UserPromptSubmitUser sends a turnsync, advisory (stdout → context)
StopModel returns final responsesync, advisory
SubagentStopA subagent returns to parentsync, advisory
PreToolUseBefore any tool callsync, advisory/input-mutating, 30s timeout
PostToolUseAfter any tool callasync by default
PreCompactBefore context compactionsync, advisory
PostCompactAfter context compactionsync, advisory
NotificationStatus / progress eventsasync, fire-and-forget
FileChangedWatched file editsasync
CwdChangedcd inside the sessionsync, advisory

settings.json schema

json
{
    "hooks": {
        "PreToolUse": [
            {
                "matcher": "Edit|Write",
                "hooks": [
                    {
                        "command": "biome check --staged",
                        "timeout": 30
                    }
                ]
            }
        ],
        "PostToolUse": [
            {
                "matcher": "Edit|Write",
                "hooks": [
                    {
                        "command": "path=$(jq -r '.tool_input.path // .tool_input.file_path // empty'); [ -z \"$path\" ] || biome format --write \"$path\""
                    }
                ]
            }
        ],
        "Stop": [
            {
                "matcher": "*",
                "hooks": [
                    { "command": "npm test --silent" }
                ]
            }
        ]
    }
}

Matchers

MatcherPurpose
Edit|WriteRegex against tool name for PreToolUse / PostToolUse
startup, resume, clear, compactSession-start sources
manual, autoCompaction trigger type
* or omittedMatch everything for that event

Hook output

PreToolUse hooks are currently advisory. They can add context and may return hookSpecificOutput.updatedInput to adjust tool input, but they do not block tool execution yet. Use approval mode and tool allowlists for hard gates.

PostToolUse and other events: stdout from the hook is appended to the model's context as a system reminder. Exit code is logged but not used to gate.

stdout-as-assistant-context (the killer feature)

Anything a hook prints to stdout is fed back to the model as a system reminder. Use this to:

  • Inject the latest CI status before the model decides how to fix.
  • Re-fetch the user's recent commits so the model knows the diff is fresh.
  • Run a linter and let the output guide the model's next edit.

Example: a PostToolUse hook that reports failing tests:

json
{
    "hooks": {
        "PostToolUse": [
            {
                "matcher": "Edit|Write",
                "hooks": [
                    { "command": "npm test --silent --json | jq '.numFailedTests' || true" }
                ]
            }
        ]
    }
}

If the count is non-zero, the model sees 123 in its context and proactively fixes failures.

Bundled hook recipes

HookEventPurpose
auto-formatPostToolUse Edit/WriteRun Biome / prettier on changed files
auto-testStopRun the test suite, report failures
commit-gatePreToolUse Bash matching git commitReport non-conventional commit messages
secret-scanPreToolUse WriteReport writes that contain secrets (gitleaks / trufflehog)

These recipes are not enabled by default. View them with /hooks recipes and install or copy the ones you want.

Slash commands

text
/hooks list
/hooks test PreToolUse --tool Edit --path src/foo.ts

/hooks opens the same view inside the TUI.

Importing Claude Code hooks

bash
cp ~/.claude/settings.json ~/.mewrite/agent/settings.json
# adjust permission mode if needed; the rest works as-is

Anti-patterns

  • Long blocking PreToolUse hooks — 30s timeout is hard. Move heavy work to PostToolUse.
  • Mutating files in PostToolUse without re-reading — the model's context still shows the pre-mutation file. Pair with a read directive in the next turn.
  • Hooks where skills would fit — hooks enforce invariants; skills express knowledge. Pick correctly.

MIT Licensed.