Skip to content

feat: Stop-hook haiku AI context summarization (v1.5.0)#39

Merged
brianruggieri merged 10 commits into
mainfrom
feat/stop-hook-haiku
Mar 20, 2026
Merged

feat: Stop-hook haiku AI context summarization (v1.5.0)#39
brianruggieri merged 10 commits into
mainfrom
feat/stop-hook-haiku

Conversation

@brianruggieri

@brianruggieri brianruggieri commented Mar 20, 2026

Copy link
Copy Markdown
Owner

Summary

Major usability upgrade to AI context summarization — switches from the inline marker strategy (0.5% delivery rate) to Stop-hook-based haiku summarization (~100% delivery rate).

  • Stop-hook haiku: The Stop hook receives last_assistant_message — Claude's actual response — truncates to first 500 + last 500 chars, and sends it to claude-haiku for a 3-5 word title summary. Summarizes what Claude did, not just what was asked.
  • Two-phase context: First-5-words appears immediately on prompt submission; refined haiku summary overwrites after the turn completes.
  • Race guard: Haiku subprocess snapshots context before launching; only writes summary if no newer prompt has arrived (prevents stale overwrites on rapid turns).
  • Git commit message capture: Commit subject line automatically written to context file on 💾 Committed — free, human-written task summary.
  • Context sanitization: Shell prompt prefixes ((venv) user@host %) stripped from first-5-words when users paste terminal output.
  • Inline strategy removed: --ai-context-strategy flag, --append-system-prompt injection, CCP_TASK_SUMMARY markers, and sentinel files all cleaned out. --ai-context is now a simple boolean toggle.
  • Priority sync fix: _status_priority() in hook_runner.sh now includes Rebasing and Cherry-picking at priority 75, matching monitor.sh.

Net result: -261 lines, simpler codebase, dramatically better title context quality.

Test plan

  • 220 tests passing (removed 21 inline tests, added 16 new)
  • New tests cover: stop-hook haiku (fires, skips when disabled/empty/missing, truncation, CLAUDECODE env clearing), commit message capture, context sanitization
  • Haiku tests use polling with bounded timeout instead of fixed sleep delays
  • ShellCheck clean across all shell files
  • Bash 3.2+ compatible (verified substring ops ${msg:0:500} and ${msg: -500})
  • Manual verification: run ccp --ai-context "test task" and confirm title updates with haiku summary after Claude responds
  • Verify commit message appears in title after a git commit

Review fixes addressed

  • Race condition (Copilot): Haiku subprocess now snapshots context file before launch; only writes if context hasn't changed
  • Flaky sleep in tests (Copilot): Replaced sleep 2 with polling loops (0.25s intervals, 5s timeout) for positive cases; sleep 1 for negative cases
  • Printf format string (Copilot): Sanitization tests now use printf '%s' instead of raw format strings

Summarize Claude's last_assistant_message via claude-haiku on the Stop
hook. Detached subprocess writes to context file; first-5-words remains
as the immediate placeholder. Delivers ~100% AI summaries (up from 0.5%
with inline strategy).
Strip (venv), user@host, and shell prompt characters ($ % # >) from
first-5-words context. Simplify user-prompt handler by removing the
haiku subprocess and inline strategy check (now handled by Stop hook).
Write the commit subject line to the context file when a git commit
is detected in post-tool. Remove the inline AI context marker scanning
block and all associated tests — inline strategy is now dead code.
Remove --ai-context-strategy flag, inline --append-system-prompt injection,
display filtering, strategy validation, and debug event field. AI context
is now a simple boolean: --ai-context enables Stop-hook haiku.
Remove inline_captured.* from stale file cleanup and inline_marker_miss
event handler from Pulse Monitor.
Rewrite AI context docs, remove inline-context-spec, update README with
new features (commit message capture, context sanitization), simplify
CLI flag documentation.
Copilot AI review requested due to automatic review settings March 20, 2026 13:46
zsh prompts include a directory name between user@host and the prompt
character: (venv) user@host dir % command. The previous sed chain
stripped (venv) and user@host but left dir % because % wasn't at
position 0. Add a sed to strip an optional word before the prompt char.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR upgrades ccp’s AI context summarization by removing the unreliable inline-marker strategy and switching to Stop-hook-based haiku summarization derived from Claude’s actual response text (last_assistant_message), with additional context improvements (commit subject capture + prompt sanitization).

Changes:

  • Replace inline AI context strategy with Stop-hook haiku summarization (two-phase: immediate first-5-words placeholder, then refined haiku after turn completes).
  • Add automatic context enrichment: git commit subject capture and prompt prefix sanitization for pasted terminal content.
  • Remove inline-strategy CLI/docs/tests and simplify debug monitoring around summary delivery.

Reviewed changes

Copilot reviewed 9 out of 11 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
lib/hook_runner.sh Adds prompt sanitization, implements Stop-hook haiku summarization using last_assistant_message, and captures git commit subjects into context.
bin/ccp Removes --ai-context-strategy support and simplifies AI context startup messaging.
tests/test-suite.sh Adds coverage for sanitization, stop-hook haiku behavior, truncation, CLAUDECODE clearing, and commit subject capture; removes inline-strategy tests.
README.md Updates feature description and usage examples to reflect Stop-hook haiku summarization and removal of inline strategy.
docs/ai-context.md Documents two-phase context and new Stop-hook summarization inputs/privacy implications.
docs/dynamic-titles.md Updates hook behavior documentation (Stop now triggers summarization; commit writes context).
docs/usage.md Removes --ai-context-strategy flag documentation.
docs/inline-context-spec.md Deletes the inline strategy spec doc.
lib/session.sh Stops pruning inline sentinel files (inline strategy removed).
bin/ccp-watch Simplifies summary delivery tracking (no pending/inline-miss tracking).
CHANGELOG.md Adds v1.5.0 entry describing Stop-hook haiku, commit capture, sanitization, and inline removal.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/hook_runner.sh
Comment thread tests/test-suite.sh Outdated
Comment thread tests/test-suite.sh
- hook_runner.sh: add race guard to haiku subprocess — only writes
  context if no newer prompt has arrived since the subprocess launched
- hook_runner.sh: sync _status_priority() with monitor.sh — add
  missing Rebasing and Cherry-picking to priority 75
- tests: replace flaky sleep 2 with polling loops in haiku tests
- tests: use printf '%s' for sanitization test payloads to avoid
  format string fragility with % characters
- README: add missing -p/--print to no-value flags list
- CHANGELOG: add v1.5.0 comparison link
- docs/dynamic-titles.md: fix SubagentStop status text to match code
@brianruggieri
brianruggieri merged commit 208171d into main Mar 20, 2026
4 checks passed
@brianruggieri
brianruggieri deleted the feat/stop-hook-haiku branch March 20, 2026 14:16
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.

2 participants