Skip to content

feat: Add automatic event bus synchronization on every prompt - #99

Merged
evansenter merged 2 commits into
mainfrom
issue-75
Jan 1, 2026
Merged

feat: Add automatic event bus synchronization on every prompt#99
evansenter merged 2 commits into
mainfrom
issue-75

Conversation

@evansenter

Copy link
Copy Markdown
Owner

Summary

  • Add prompt-events.sh hook that fetches new events from the event bus on every UserPromptSubmit
  • Update session-start.sh to catch up on recent events at session startup
  • Configure UserPromptSubmit hook in settings.json
  • Document new automatic synchronization behavior in CLAUDE.md

Uses event-bus-cli with --track-state for incremental polling via ~/.local/state/claude/last_event_id. Events are filtered to exclude session_registered/session_unregistered noise.

Test plan

  • Verify prompt-events.sh fetches new events correctly
  • Verify incremental polling (no duplicate events)
  • Verify silent output when no new events
  • Verify session-start.sh shows recent events on startup
  • Verify graceful degradation when event-bus-cli not installed

Closes #75

🤖 Generated with Claude Code

@claude

claude Bot commented Dec 31, 2025

Copy link
Copy Markdown

Prompt: evansenter/dotfiles/.../claude-review.md

Code Review

Summary

This PR adds automatic event bus synchronization by fetching events on every user prompt via a new prompt-events.sh hook and on session startup. It uses event-bus-cli with --track-state for incremental polling.

Issues Found

Critical

None.

Important

None.

Suggestions

  • home/.claude/hooks/prompt-events.sh:39 - The --timeout 200 flag (presumably 200ms) is used but the issue discussion mentioned ~250-300ms typical latency. Consider whether this timeout is sufficient or if it should match the session-start timeout. A timeout shorter than typical response time could cause silent failures.

  • home/.claude/hooks/session-start.sh:57-62 - The session-start uses --limit 10 while prompt-events uses --limit 20. Consider aligning these or documenting why they differ. The issue proposed --limit 10 for both.

  • home/.claude/CLAUDE.md:152 - The performance note mentions "~250-300ms latency" but doesn't mention that the hooks use a 200ms timeout, which may cause event fetching to timeout before completing. This could lead to confusion if users notice events are sometimes not fetched.

  • home/.claude/hooks/prompt-events.sh:34-38 - The command array builds options in a specific order but --session-id is added at the end conditionally. While this works, consider adding a comment explaining that --session-id is optional and refreshes the heartbeat, since this purpose isn't immediately obvious from the code.

Verdict

REQUEST_CHANGES - A few minor suggestions around timeout configuration and limit consistency. The core implementation looks solid with proper graceful degradation and state management.


Automated review by Claude Code

@claude

claude Bot commented Dec 31, 2025

Copy link
Copy Markdown

Prompt: evansenter/dotfiles/.../claude-review.md

Code Review

Summary

This PR adds automatic event bus synchronization by creating a new prompt-events.sh hook that runs on every UserPromptSubmit, and enhances session-start.sh to fetch recent events at session startup. Both use event-bus-cli with --track-state for incremental polling via state file.

Issue #75 Requirements Verification

All requirements from the linked issue are addressed:

  • ✅ Create home/.claude/hooks/prompt-events.sh
  • ✅ Update session-start.sh to include event catch-up
  • ✅ Update settings.json with UserPromptSubmit hook
  • ✅ Hooks directory is symlinked as a whole by bootstrap.sh (via symlink_claude_dir "hooks")
  • ✅ Documentation added to CLAUDE.md Event Bus section

Code Quality Notes

Good practices observed:

  • Proper stdin consumption in both hooks to avoid broken pipe errors
  • Graceful degradation when event-bus-cli or jq not installed
  • Clear comments explaining design choices (e.g., limit 20 vs 10)
  • Consistent error handling with || true for optional operations
  • XDG-compliant state directory usage

Design choices reviewed:

  • The --timeout 200 parameter is the HTTP request timeout, separate from the ~250-300ms total latency (which includes Python CLI startup). This is appropriate.
  • Using --limit 20 for prompt-events vs --limit 10 for session-start is documented and makes sense: active sessions benefit from more context.

Verdict

APPROVE - Clean implementation that addresses all issue requirements. Code follows shell best practices with proper error handling and graceful degradation.


Automated review by Claude Code

@evansenter

Copy link
Copy Markdown
Owner Author

Feedback Addressed

Implemented

  • [Suggestion] Added comment in prompt-events.sh explaining why limit (20) differs from session-start (10) - active sessions benefit from more event context

Skipped

  • [Suggestion] 200ms timeout vs 250-300ms latency - The 200ms is HTTP timeout; 250-300ms includes Python startup. Timeout prevents hanging.
  • [Suggestion] Add timeout detail to CLAUDE.md - Implementation detail, docs already note hooks can be disabled
  • [Suggestion] Add comment for --session-id - Already documented on line 27 ("enables heartbeat refresh")

@claude

claude Bot commented Jan 1, 2026

Copy link
Copy Markdown

Prompt: evansenter/dotfiles/.../claude-review.md

Code Review

Summary

This PR adds automatic event bus synchronization on every prompt via a new prompt-events.sh hook and enhances session-start.sh to fetch recent events at startup. Both use event-bus-cli with --track-state for incremental polling.

Issue #75 Verification

All requirements from the linked issue are addressed:

  • prompt-events.sh hook created with graceful degradation
  • session-start.sh enhanced with event catch-up
  • settings.json updated with UserPromptSubmit hook
  • ✅ Hooks directory already symlinked by bootstrap.sh
  • ✅ Documentation added to CLAUDE.md

Previous Feedback Status

All suggestions from previous reviews have been addressed in the "Feedback Addressed" comment:

  • Limit comment added to prompt-events.sh:34
  • Timeout clarification (200ms HTTP vs 250-300ms total) explained
  • Session-id comment already present at line 27

Verdict

APPROVE - Clean implementation with proper error handling, graceful degradation, and XDG-compliant state management. All issue requirements met and previous feedback addressed.


Automated review by Claude Code

evansenter and others added 2 commits January 1, 2026 17:28
Add UserPromptSubmit hook (prompt-events.sh) that fetches new events
from the event bus before processing each user prompt. Also update
session-start.sh to catch up on recent events at session startup.

Uses event-bus-cli with --track-state for incremental polling via
~/.local/state/claude/last_event_id. Events are filtered to exclude
session_registered/session_unregistered noise.

Closes #75

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Addresses claude-review suggestion: document why prompt-events uses
--limit 20 while session-start uses --limit 10 (active sessions
benefit from more event context).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@claude

claude Bot commented Jan 1, 2026

Copy link
Copy Markdown

Prompt: evansenter/dotfiles/.../claude-review.md

Code Review

Summary

This PR adds automatic event bus synchronization by creating a prompt-events.sh hook that fetches new events on every UserPromptSubmit, and enhances session-start.sh to catch up on recent events at startup. Both hooks use event-bus-cli with --track-state for incremental polling via a shared state file.

Issue #75 Verification

All requirements from the linked issue are fully addressed:

  • prompt-events.sh hook created with proper stdin handling and graceful degradation
  • session-start.sh enhanced with event catch-up functionality
  • settings.json updated with UserPromptSubmit hook configuration
  • ✅ Hooks directory already symlinked by bootstrap.sh (via symlink_claude_dir "hooks")
  • ✅ Documentation added to CLAUDE.md with performance notes

Code Quality Assessment

Well-implemented patterns:

  • Proper stdin consumption (INPUT=$(cat) / cat >/dev/null) to prevent broken pipe errors
  • Graceful degradation when event-bus-cli or jq are not installed
  • XDG-compliant state directory ($XDG_STATE_HOME with fallback)
  • Clear comments documenting design decisions (limit 20 vs 10 rationale on line 34)
  • Consistent error suppression with || true for optional operations
  • Event filtering excludes noisy session_registered/session_unregistered events

Previous Feedback Status:
All suggestions from earlier reviews have been addressed per the "Feedback Addressed" comment:

  • Limit difference comment added
  • Timeout clarification (200ms HTTP timeout vs 250-300ms total latency) acknowledged
  • Session-id heartbeat purpose documented on line 27

Verdict

APPROVE - Clean implementation with proper error handling, graceful degradation, and XDG-compliant state management. All issue #75 requirements met and previous feedback addressed.


Automated review by Claude Code

@evansenter
evansenter merged commit 4a89af0 into main Jan 1, 2026
4 checks passed
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.

Add get_events on every prompt and session start for maximum synchronization

1 participant