Claude Code's Hooks feature is really compelling. Hooks are a configurable automation feature that allows you to execute custom shell commands or scripts in response to various events within the Claude Code environment, such as tool usage, prompt submissions, notifications, and agent lifecycle changes. Defined in JSON settings files, hooks can target specific tools or events using matchers and can validate, block, or enhance actions by processing event data passed as JSON. They provide flexible control over your coding workflow, enabling tasks like input validation, security enforcement, and workflow customization, but require careful handling due to their ability to run arbitrary commands on your system.
With that said, bringing hooks into opencode would enable the same kind of agentic workflows. To configure hooks in Claude Code, you define them in JSON settings files such as ~/.claude/settings.json for user-wide settings or .claude/settings.json for project-specific settings. Each hook is associated with a specific event (like PreToolUse, PostToolUse, or UserPromptSubmit) and can optionally include a matcher—a string or regex pattern—to target particular tools. Within each event and matcher, you list one or more commands to run, specifying the command type (currently only "command" is supported), the shell command to execute, and an optional timeout in seconds. When the event occurs, Claude Code runs the matching commands, passing event data as JSON via stdin, and the command’s output or exit code determines whether the action proceeds, is blocked, or is modified.
Claude Code's Hooks feature is really compelling. Hooks are a configurable automation feature that allows you to execute custom shell commands or scripts in response to various events within the Claude Code environment, such as tool usage, prompt submissions, notifications, and agent lifecycle changes. Defined in JSON settings files, hooks can target specific tools or events using matchers and can validate, block, or enhance actions by processing event data passed as JSON. They provide flexible control over your coding workflow, enabling tasks like input validation, security enforcement, and workflow customization, but require careful handling due to their ability to run arbitrary commands on your system.
With that said, bringing hooks into opencode would enable the same kind of agentic workflows. To configure hooks in Claude Code, you define them in JSON settings files such as
~/.claude/settings.jsonfor user-wide settings or .claude/settings.jsonfor project-specific settings. Each hook is associated with a specific event (like PreToolUse, PostToolUse, or UserPromptSubmit) and can optionally include a matcher—a string or regex pattern—to target particular tools. Within each event and matcher, you list one or more commands to run, specifying the command type (currently only "command"is supported), the shell command to execute, and an optional timeout in seconds. When the event occurs, Claude Code runs the matching commands, passing event data as JSON via stdin, and the command’s output or exit code determines whether the action proceeds, is blocked, or is modified.