Skip to content

Conversation

@johnlindquist
Copy link
Owner

@johnlindquist johnlindquist commented Aug 1, 2025

Summary

This PR adds a default sessionStart handler to the hooks template, completing the SessionStart feature implementation.

Changes

  • Added SessionStartHandler to the imports in templates/hooks/index.ts
  • Implemented a default sessionStart handler with:
    • Session data saving using saveSessionData
    • Logging of session start with source and session ID
    • Example code for loading user preferences
    • Source-specific behavior examples (VS Code vs web)
    • Helpful comments for customization
  • Added sessionStart to the runHook configuration

Implementation Details

The handler follows the same pattern as other handlers in the template:

  • Saves session data for debugging/tracking
  • Provides clear examples of common use cases
  • Returns empty object for default behavior
  • Includes helpful comments for users

This complements the SessionStart hook implementation in PR #50 by providing users with a ready-to-use handler template.

Testing

  • ✅ Linting passes
  • ✅ Follows existing handler patterns
  • ✅ TypeScript types are properly imported

Related

Summary by CodeRabbit

  • New Features

    • Introduced support for a new "SessionStart" event, enabling handling of actions when a new session begins.
    • Added a handler for the "SessionStart" event, allowing custom logic to be executed at session start.
    • Enhanced event payloads and responses to include session-specific information and decisions.
  • Other Improvements

    • Added an optional title field to notifications.

@coderabbitai
Copy link

coderabbitai bot commented Aug 1, 2025

Walkthrough

This change introduces a new "SessionStart" hook event into the codebase. It adds corresponding payload and response interfaces, handler type definitions, and updates hook dispatch logic to support the new event. A template handler for "SessionStart" is provided, and related type unions, interfaces, and switch statements are updated accordingly.

Changes

Cohort / File(s) Change Summary
SessionStart Hook Type Support
templates/hooks/lib.ts, add-session-start.sed
Adds SessionStartPayload and SessionStartResponse interfaces, extends HookPayload union, adds SessionStartHandler type, updates HookHandlers interface, and modifies the hook dispatch switch to handle the new "SessionStart" event. Also adds an optional title field to NotificationPayload.
SessionStart Handler Implementation
templates/hooks/index.ts
Implements and exports a sessionStart handler. The handler logs session information, demonstrates where to load preferences or initialize resources, and returns an empty object to continue processing. Integrates the new handler into the hooks system.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant HookSystem
    participant SessionStartHandler

    Client->>HookSystem: Trigger "SessionStart" event with payload
    HookSystem->>SessionStartHandler: Invoke handler with payload
    SessionStartHandler-->>HookSystem: Return SessionStartResponse
    HookSystem->>Client: Log/return response
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15 minutes

Possibly related PRs

  • feat: add SessionStart hook handler #50: The main PR and the retrieved PR both add the same SessionStart hook event support by defining identical payload and response interfaces, extending the HookHandlers interface with a sessionStart handler, and updating the runHook function to handle the SessionStart case, indicating they are directly related changes.

Suggested labels

released

Poem

A session begins, the hook takes flight,
With payloads and handlers, all set just right.
New types and responses, the code hops along,
Logging each start with a rabbit’s song.
From “vscode” or “web,” let the sessions commence—
This bunny’s code change makes perfect sense! 🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/add-session-start-handler-template

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@johnlindquist johnlindquist enabled auto-merge (squash) August 1, 2025 14:35
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d1d6343 and 91319dc.

📒 Files selected for processing (3)
  • add-session-start.sed (1 hunks)
  • templates/hooks/index.ts (2 hunks)
  • templates/hooks/lib.ts (6 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
templates/**/*

📄 CodeRabbit Inference Engine (CLAUDE.md)

Hook templates must be stored in the templates/ directory and copied to the user's .claude/ directory when initialized.

Files:

  • templates/hooks/index.ts
  • templates/hooks/lib.ts
🧠 Learnings (4)
📓 Common learnings
Learnt from: CR
PR: johnlindquist/claude-hooks#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-28T15:51:09.840Z
Learning: Applies to .claude/{settings.json,hooks/index.ts,hooks/lib.ts,hooks/session.ts} : The generated hook system must create `.claude/settings.json`, `.claude/hooks/index.ts`, `.claude/hooks/lib.ts`, and `.claude/hooks/session.ts`.
📚 Learning: applies to .claude/{settings.json,hooks/index.ts,hooks/lib.ts,hooks/session.ts} : the generated hook...
Learnt from: CR
PR: johnlindquist/claude-hooks#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-28T15:51:09.840Z
Learning: Applies to .claude/{settings.json,hooks/index.ts,hooks/lib.ts,hooks/session.ts} : The generated hook system must create `.claude/settings.json`, `.claude/hooks/index.ts`, `.claude/hooks/lib.ts`, and `.claude/hooks/session.ts`.

Applied to files:

  • templates/hooks/index.ts
  • add-session-start.sed
📚 Learning: applies to templates/**/* : hook templates must be stored in the `templates/` directory and copied t...
Learnt from: CR
PR: johnlindquist/claude-hooks#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-28T15:51:09.840Z
Learning: Applies to templates/**/* : Hook templates must be stored in the `templates/` directory and copied to the user's `.claude/` directory when initialized.

Applied to files:

  • templates/hooks/index.ts
📚 Learning: hooks are executed using the bun runtime (required dependency)....
Learnt from: CR
PR: johnlindquist/claude-hooks#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-28T15:51:09.840Z
Learning: Hooks are executed using the Bun runtime (required dependency).

Applied to files:

  • templates/hooks/index.ts
🧬 Code Graph Analysis (2)
templates/hooks/lib.ts (1)
scripts/session-type-reference.ts (1)
  • BasePayload (15-18)
add-session-start.sed (1)
scripts/session-type-reference.ts (1)
  • BasePayload (15-18)
🔇 Additional comments (14)
add-session-start.sed (6)

3-13: LGTM - Consistent payload interface pattern.

The SessionStartPayload interface follows the established pattern with standard fields plus a logical source field for tracking session origin.


15-17: LGTM - Proper union type extension.

The union type addition follows the discriminated union pattern correctly.


19-32: LGTM - Well-structured response interface.

The SessionStartResponse interface follows established patterns with appropriate decision options and hook-specific output structure.


34-36: LGTM - Consistent handler type definition.

The handler type follows the established pattern with proper payload and response types.


38-40: LGTM - Proper interface extension.

The HookHandlers interface extension maintains the optional pattern and uses the correct handler type.


42-54: LGTM - Consistent runtime dispatch logic.

The switch case follows the established pattern with proper async handling and fallback behavior.

templates/hooks/index.ts (3)

8-8: LGTM - Clean import addition.

The SessionStartHandler import is properly added and maintains alphabetical ordering.


16-41: Excellent handler implementation with helpful examples.

The sessionStart handler follows established patterns while providing comprehensive examples for common use cases. The source-specific behavior examples and well-commented code will help developers customize the template effectively.


174-174: LGTM - Logical placement in handler configuration.

The sessionStart handler is appropriately placed at the beginning of the handler list, reflecting its role in session initialization.

templates/hooks/lib.ts (5)

289-289: LGTM - Useful optional field addition.

The optional title field enhances notification capabilities without breaking existing code.


320-325: LGTM - Consistent interface structure.

The SessionStartPayload interface properly extends the base payload pattern with a logical source field for session origin tracking.


334-334: LGTM - Proper discriminated union extension.

The union type addition correctly follows the established discriminated union pattern.


379-387: LGTM - Well-structured response interface.

The SessionStartResponse interface follows established patterns with appropriate decision options and consistent hook-specific output structure.


410-410: LGTM - Consistent handler type definition.

The SessionStartHandler type maintains the established pattern with proper payload and response types.

@johnlindquist johnlindquist merged commit af5b18d into main Aug 1, 2025
10 checks passed
@github-actions
Copy link
Contributor

github-actions bot commented Aug 1, 2025

🎉 This PR is included in version 2.4.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants