Skip to content

Conversation

@johnlindquist
Copy link
Owner

@johnlindquist johnlindquist commented Jul 8, 2025

Summary

  • Replaced all any types with proper TypeScript types based on Claude Code schema
  • Fixed Node.js import protocol warning by using node:path instead of path
  • Fixed type inconsistency in session.ts by importing and using HookPayload type from ./lib
  • All linting issues resolved with Biome

Changes

  • templates/hooks/index.ts: Cast payload.tool_input to proper type interface instead of any
  • templates/hooks/lib.ts:
    • Changed tool_input and tool_response from Record<string, any> to Record<string, unknown>
    • Updated saveSessionData to accept HookPayload type instead of any
    • Fixed sessionData array typing with proper interface
    • Changed log function parameters from any[] to unknown[]
    • Fixed hook_type casting to use proper union type
  • templates/hooks/session.ts:
    • Fixed Node.js import protocol for path module
    • Updated saveSessionData parameter from Record<string, unknown> to HookPayload type
    • Added import for HookPayload type from ./lib
    • Updated internal sessionData array type to use HookPayload

Test plan

  • Run bun run lint - All checks pass
  • Verify no more TypeScript any warnings in IDE
  • Tests fail due to pre-existing issue with TypeScript file extension handling (unrelated to these changes)

Note: The test failures are pre-existing and occur on the main branch as well. They're related to the test setup not being able to handle TypeScript files when running CLI commands, not to the type fixes in this PR.

🤖 Generated with Claude Code

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->

Summary by CodeRabbit

  • Refactor

    • Improved type safety and clarity for various parameters and function signatures to enhance reliability and maintainability.
    • Updated function signatures for session data handling to use more precise type annotations.
  • Chores

    • Updated import statements for consistency with modern module resolution standards.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

Summary by CodeRabbit

  • Refactor

    • Improved type safety and clarity for various parameters and function signatures to enhance reliability and maintainability.
    • Updated function signatures for session data handling to use more precise type annotations.
  • Chores

    • Updated import statements for consistency with modern module resolution standards.

- Replace `any` with specific types based on Claude Code schema
- Use `unknown` for generic record values following TypeScript best practices
- Fix Node.js import protocol warning by using 'node:path'
- All linting issues resolved, no more Biome warnings

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

Co-Authored-By: Claude <[email protected]>
@coderabbitai
Copy link

coderabbitai bot commented Jul 8, 2025

Walkthrough

The changes focus on improving type safety and clarity in TypeScript code. Type assertions and type annotations are refined across several files, particularly for payloads and function parameters, without altering any logic or control flow. Some import statements are also updated for consistency.

Changes

File(s) Change Summary
templates/hooks/index.ts Refined type assertion for extracting file_path from payload.tool_input for better type safety.
templates/hooks/lib.ts Updated type annotations for payloads, function parameters, rest arguments, and hook type casting.
templates/hooks/session.ts Changed import style for path and refined type annotations for function parameters and variables.

Suggested labels

released

Poem

A hop and a skip, the types are now tight,
No more loose any, just clarity in sight!
With payloads well-typed and imports so neat,
This bunny’s code garden feels tidy and sweet.
🐇✨


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 90c8780 and 58008c8.

📒 Files selected for processing (1)
  • templates/hooks/session.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • templates/hooks/session.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: test (windows-latest, 18)
  • GitHub Check: test (ubuntu-latest, 18)
  • GitHub Check: test (windows-latest, 20)
✨ Finishing Touches
  • 📝 Generate Docstrings

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 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.

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

🧹 Nitpick comments (1)
templates/hooks/index.ts (1)

22-22: Type assertion improvement looks good, but consider runtime validation.

The change from any to {file_path: string} improves type safety. However, since this is a runtime type assertion, consider adding a runtime check to ensure file_path exists before destructuring.

- const {file_path} = payload.tool_input as {file_path: string}
+ const toolInput = payload.tool_input as {file_path?: string}
+ if (!toolInput.file_path) return {}
+ const {file_path} = toolInput
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 42dfda5 and 90c8780.

📒 Files selected for processing (3)
  • templates/hooks/index.ts (1 hunks)
  • templates/hooks/lib.ts (4 hunks)
  • templates/hooks/session.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`templates/**/*`: Hook templates must be stored in the 'templates/' directory and are copied to the user's '.claude/' directory during initialization.

templates/**/*: Hook templates must be stored in the 'templates/' directory and are copied to the user's '.claude/' directory during initialization.

📄 Source: CodeRabbit Inference Engine (CLAUDE.md)

List of files the instruction was applied to:

  • templates/hooks/index.ts
  • templates/hooks/session.ts
  • templates/hooks/lib.ts
🧠 Learnings (3)
📓 Common learnings
Learnt from: CR
PR: johnlindquist/claude-hooks#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-07T16:54:50.705Z
Learning: Applies to tsconfig.json : TypeScript strict mode must be enabled.
templates/hooks/index.ts (1)
Learnt from: CR
PR: johnlindquist/claude-hooks#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-07T16:54:50.705Z
Learning: Applies to .claude/{settings.json,hooks/index.ts,hooks/lib.ts,hooks/session.ts} : The CLI generates a '.claude/' directory containing 'settings.json', 'hooks/index.ts', 'hooks/lib.ts', and 'hooks/session.ts' when initialized.
templates/hooks/session.ts (1)
Learnt from: CR
PR: johnlindquist/claude-hooks#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-07T16:54:50.705Z
Learning: Applies to .claude/{settings.json,hooks/index.ts,hooks/lib.ts,hooks/session.ts} : The CLI generates a '.claude/' directory containing 'settings.json', 'hooks/index.ts', 'hooks/lib.ts', and 'hooks/session.ts' when initialized.
🧬 Code Graph Analysis (2)
templates/hooks/session.ts (1)
templates/hooks/lib.ts (1)
  • saveSessionData (113-136)
templates/hooks/lib.ts (1)
templates/hooks/session.ts (1)
  • saveSessionData (7-33)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
  • GitHub Check: test (windows-latest, 20)
  • GitHub Check: test (macos-latest, 20)
  • GitHub Check: test (windows-latest, 18)
  • GitHub Check: test (ubuntu-latest, 20)
  • GitHub Check: test (ubuntu-latest, 18)
🔇 Additional comments (8)
templates/hooks/session.ts (2)

3-3: Good improvement to use Node.js protocol import.

Using node:path is the recommended approach for Node.js built-in modules as it makes the import explicit and avoids potential conflicts with npm packages.


15-15: Improved type annotation for session data array.

The explicit type annotation improves type safety and clarity. The type aligns well with the function's logic.

templates/hooks/lib.ts (6)

11-11: Excellent type safety improvement.

Changing from Record<string, any> to Record<string, unknown> is a significant improvement. unknown is type-safe and requires explicit type checks before use, unlike any which disables type checking.


18-19: Consistent type safety improvements for tool data.

Both tool_input and tool_response benefit from the change to Record<string, unknown>, maintaining consistency across the payload interfaces.


113-113: More precise parameter typing for saveSessionData.

Changing from any to HookPayload provides proper type safety and ensures the payload has the required structure including session_id. This is more accurate than the generic approach.


118-118: Explicit array typing improves code clarity.

The explicit type annotation makes the expected structure clear and provides better IntelliSense support.


139-139: Type-safe logging function parameter.

Changing from any[] to unknown[] maintains type safety while still allowing any values to be logged. This is the appropriate choice for a logging utility.


153-153: Precise union type assertion.

Using HookPayload['hook_type'] instead of any provides compile-time validation that the hook_type is one of the valid values from the union type. This catches potential runtime errors at compile time.

…on.ts

- Import HookPayload type from './lib'
- Update saveSessionData function signature to use HookPayload
- Update sessionData array type to use HookPayload
- This unifies the payload type across both lib.ts and session.ts files
@johnlindquist johnlindquist enabled auto-merge (squash) July 8, 2025 21:18
@johnlindquist johnlindquist merged commit c70447b into main Jul 8, 2025
10 checks passed
@github-actions
Copy link
Contributor

github-actions bot commented Jul 8, 2025

🎉 This PR is included in version 1.2.1 🎉

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