Back to DevLog

Building a Complete Hook System: PostToolUse Monitoring and SessionStart Context Loading

3 min read

Just shipped MemStack Pro v3.3.2 with two major new hooks that complete my event coverage architecture. This was one of those satisfying sessions where you audit everything, find the gaps, and systematically fill them in.

The Hook System Audit

I started by reading through all 6 existing hook scripts and mapping out the complete architecture. What I found was pretty good coverage across 5 events, but two obvious gaps:

  • No PostToolUse observation capture after tool calls
  • No SessionStart context injection for session continuity

I also documented some rookie mistakes I'd made along the way: exit code semantics, inconsistent python vs python3 usage, and those fun MSYS path gotchas that only show up on Windows.

PostToolUse Observation Hook

The new post-tool-monitor.sh captures everything after Write/Edit/MultiEdit/Bash calls:

  • Tool name and parsed JSON input summary
  • Timestamp and working directory
  • Appends to daily files in .claude/observations/YYYY-MM-DD.md

I used Python for JSON parsing with a grep fallback, and followed the defensive pattern I learned from pre-compact.sh: set -uo pipefail but no -e flag, with guaranteed exit 0. One failed command shouldn't block the entire hook system.

SessionStart Context Loader

The session-context-load.sh hook solves the context continuity problem:

  • Reads last 3 diary entries from .claude/diary/ or memory/sessions/
  • Pulls last 3 observation files
  • Writes condensed summary to .claude/session-context.md (max 200 lines)
  • Idempotent and atomic via tmp file + mv

Now every new session gets automatic context about what I've been working on recently.

Architecture Decision: Option B

I went with Option B for the hook architecture - each hook gets its own independent entry in settings.json with its own timeout budget. PostToolUse monitor gets 10 seconds, SessionStart context loader gets 15 seconds. It's safer than trying to share entries.

Total system now: 7 hooks across 5 events. Pretty comprehensive coverage.

Documentation and Upsells

Updated all the docs in the Pro repo with the full hook system table and bumped version badges to 3.3.2. Then I went through the free repo and added strategic upsells:

  • SessionStart upsells in 4 skills (echo, state, work, project)
  • PostToolUse upsells in 7 skills (grimoire, verify, shard, forge, sight, scan, quill)
  • Skipped 3 skills where the hook benefit wasn't genuinely relevant

I try to keep the upsells authentic - only mention Pro features where they actually add value to that specific skill.

Marketing Site Audit

Did a full audit of the marketing site and found the hooks section is way outdated - still only mentions 2 of the 7 hooks we now have. The Pricing and Comparison pages are missing Pro hook differentiators entirely.

Skill count is current at 80+, and I intentionally don't put version numbers on the marketing site (less maintenance overhead), but the hook system deserves better representation.

What's Next

Left the marketing site updates for next session. I've got exact file paths and line numbers for the three must-fix files: FrameworkArtifact.jsx, Pricing.tsx, and Comparison.tsx. The site currently just mentions hooks generically as "pre-push, session start/end" with no Pro differentiation, which doesn't do justice to the full system.

This felt like a really solid session - methodical audit, clean implementation, good documentation, and strategic positioning. The hook system architecture is now complete and should handle most automation needs going forward.

Share this post