npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

opencode-claude-hooks

v0.1.0

Published

OpenCode plugin for Claude Code hooks compatibility

Readme

OpenCode Claude Hooks

npm version npm downloads License: MIT TypeScript Made with Bun

Claude Code hooks compatibility for OpenCode

This OpenCode plugin enables you to use your existing Claude Code hook configurations with OpenCode, providing ~80% compatibility for drop-in migration.

Features

  • Drop-in compatibility - Use your existing .claude/settings.json files
  • All major hooks supported - SessionStart, SessionEnd, PreToolUse, PostToolUse, etc.
  • Command and prompt-based hooks - Run shell scripts or use LLM-based decisions
  • Multiple config locations - Project and global configurations
  • Tool pattern matching - Target specific tools with regex patterns

Installation

npm install opencode-claude-hooks
# or
bun add opencode-claude-hooks

Add to your OpenCode configuration (~/.config/opencode/opencode.json):

{
  "$schema": "https://opencode.ai/config.json",
  "plugin": [
    "opencode-claude-hooks"
  ]
}

Configuration

The plugin loads hook configurations from these locations (in priority order):

Claude Code locations (for compatibility):

  1. .claude/settings.local.json (project, not committed)
  2. .claude/settings.json (project)
  3. ~/.claude/settings.json (user global)

OpenCode locations: 4. .opencode/hooks.json (project) 5. ~/.config/opencode/hooks.json (user global)

All configurations are merged, with earlier files taking precedence.

Hook Configuration Format

{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Bash",
        "hooks": [
          {
            "type": "command",
            "command": "bash ./scripts/validate-command.sh",
            "timeout": 5000
          }
        ]
      }
    ],
    "SessionStart": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "echo 'Session started!'"
          }
        ]
      }
    ]
  }
}

Supported Hooks

| Claude Code Hook | OpenCode Event | Compatibility | |-----------------|----------------|---------------| | SessionStart | session.created | ✅ Full | | SessionEnd | session.deleted | ✅ Full | | PreToolUse | tool.execute.before | ✅ Full | | PostToolUse | tool.execute.after | ✅ Full | | PostToolUseFailure | tool.execute.after (error) | ✅ Full | | PermissionRequest | permission.asked | ⚠️ Partial | | SubagentStart | tool.execute.before (Task) | ⚠️ Partial | | SubagentStop | tool.execute.after (Task) | ⚠️ Partial | | PreCompact | experimental.session.compacting | ⚠️ Partial | | UserPromptSubmit | message.updated (user) | ⚠️ Partial | | Stop | session.idle | ⚠️ Partial | | Notification | tui.toast.show | ⚠️ Partial | | Setup | N/A | ❌ Not supported |

Hook Types

Command Hooks

Execute shell commands with stdin/stdout:

{
  "type": "command",
  "command": "bash ./my-hook.sh",
  "timeout": 5000
}

Input via stdin:

{
  "session_id": "abc123",
  "transcript_path": "/path/to/transcript.jsonl",
  "cwd": "/project/directory",
  "permission_mode": "default",
  "hook_event_name": "PreToolUse",
  "tool_name": "Bash",
  "tool_input": { "command": "ls" }
}

Exit codes:

  • 0 - Success, continue
  • 2 - Block/deny the action
  • Other - Non-blocking error

JSON output (optional):

{
  "hookSpecificOutput": {
    "hookEventName": "PreToolUse",
    "permissionDecision": "deny",
    "permissionDecisionReason": "Dangerous command detected"
  }
}

Prompt-Based Hooks

Use LLM to make decisions:

{
  "type": "prompt",
  "prompt": "Check if this bash command is safe to execute"
}

Tool Pattern Matching

Use the matcher field to target specific tools:

  • "*" or "" - Matches all tools
  • "Bash" - Exact match
  • "Edit|Write" - Regex pattern (matches Edit OR Write)
  • "Read.*" - Regex with wildcards

Examples

See the examples/ directory for complete hook examples:

  • session-start.sh - Log session starts with timestamp
  • block-dangerous-bash.sh - Block dangerous bash commands
  • pre-tool-use-logger.sh - Log all tool executions
  • notify-on-write.sh - macOS notification when files are written

Environment Variables

Hooks receive these environment variables:

  • CLAUDE_PROJECT_DIR - Project root directory
  • OPENCODE_COMPAT - Set to "true" (indicates OpenCode environment)

Limitations

  1. Setup hook - No equivalent in OpenCode
  2. MCP tools - May not trigger plugin hooks
  3. Timing differences - Stop and PreCompact semantics differ slightly
  4. Permission model - OpenCode's permission system works differently

Development

# Install dependencies
bun install

# Build
bun run build

# Type check
bun run typecheck

# Test hooks locally
bun run examples/test-runner.ts

License

MIT

Contributing

Contributions welcome! Please open an issue or PR.

Related