Skip to content

feat(claude): add SessionStart routing hook - #30

Merged
3metaJun merged 6 commits into
mainfrom
feat/claude-session-hook
Oct 6, 2026
Merged

3metaJun merged 6 commits into
mainfrom
feat/claude-session-hook

Conversation

@3metaJun

@3metaJun 3metaJun commented Oct 5, 2026

Copy link
Copy Markdown
Owner

Problem

mstack's Claude Code plugin ships skills and agents but nothing tells a fresh session to route multi-file changes or bugs with an unknown cause through /meta-mode. pstack-claude closes that gap with a SessionStart hook, but with Bash and PowerShell copies and a Cursor-style sheet. mstack needs a portable version that follows its own config layout.

Solution

  • hooks/hooks.json registers a SessionStart hook (matcher startup|resume|clear|compact) running node "${CLAUDE_PLUGIN_ROOT}/scripts/session-hook.mjs". Claude Code loads hooks/hooks.json by default, so plugin.json does not reference it. validatePluginHooks rejects a duplicate manifest reference.
  • scripts/session-hook.mjs is one Node script for Windows, macOS, and Linux. It prints hookSpecificOutput.additionalContext JSON from hooks/session-start-context.md (routing to mstack:meta-mode, reversible work proceeds, irreversible asks, user CLAUDE.md wins). It always exits 0 and prints nothing on any failure.
  • Off switch: "sessionHook": false in ~/.config/mstack/models.json. Only boolean false disables it. A missing, unreadable, or malformed config leaves the hook on. A UTF-8 or UTF-16 LE byte-order mark and CRLF are accepted. validateModelConfig rejects a non-boolean value (small additive edit to model-config-lib.mjs).
  • Validation: validate.mjs now checks the hook file, its script reference, the context file, and agents/*.md (frontmatter name equals file name, manifest agent paths exist). check-package requires the new files in the npm tarball. package.json files gains hooks.
  • Docs: new guide page 12 (layers: agent coordination, principles, playbooks, user-invocable skills; the hook; autonomy stance; how to turn it off), plus README and docs/harness-adapters.md.
  • The hook ships with the plugin only. The installer would have to merge into the user's settings.json, which mstack leaves to the user, so installer-only setups get no hook and the two routes cannot double-load it.
  • No meta-agent-<effort> variants. Nothing in the skills dispatches by effort, agents/ is shared with Codex TOML conversion (which rejects an effort field) and OpenCode, and a Claude-only generated copy would be dead code. The guide explains claude --effort and user-owned agent files instead.

Verification

  • npm test: 258 tests pass, including 8 new ones in scripts/session-hook.test.mjs (output shape through the real script, off switch with BOM, UTF-16, CRLF, missing, directory-in-place-of-file, malformed, non-boolean values, context skill names exist, manifest and hook reference checks).
  • npm run check-package passes.
  • claude plugin validate . --strict passes (Claude Code 2.1.289).
  • Loaded the repo with claude --plugin-dir . in stream-json mode: the SessionStart:startup hook ran, exit 0, and returned the expected additionalContext.

Model: Claude Sonnet 5.5 | Harness: Claude Code

🤖 Generated with Claude Code

3metaJun and others added 6 commits October 6, 2026 02:36
The Claude Code plugin now registers a SessionStart hook that adds a short note routing multi-file changes and unknown-cause bugs to mstack:meta-mode. One Node script serves every platform, fails open, and is disabled by sessionHook: false in ~/.config/mstack/models.json. Validation covers the hook file, its script reference, and the agent list. Adds guide page 12.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ontext

Reject hook script and manifest agent paths that leave the plugin root, and report a
non-file or unreadable hooks/session-start-context.md instead of throwing. Update the
installer artifacts note that no longer matches the plugin hook.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
readModelConfig now reads the BOM and UTF-16 LE files the hook already accepts, and the
guide no longer promises confirmation for reversible externally visible actions.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@3metaJun
3metaJun merged commit 8d396cc into main Oct 6, 2026
9 checks passed
@3metaJun
3metaJun deleted the feat/claude-session-hook branch October 6, 2026 04:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant