Hooks #861

Closed
opened 2026-02-16 17:28:35 -05:00 by yindo · 3 comments
Owner

Originally created by @samholmes on GitHub (Jul 22, 2025).

Originally assigned to: @thdxr on GitHub.

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.

Originally created by @samholmes on GitHub (Jul 22, 2025). Originally assigned to: @thdxr on GitHub. 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.
yindo closed this issue 2026-02-16 17:28:35 -05:00
Author
Owner

@cbgbt commented on GitHub (Jul 24, 2025):

The ability to use hooks to deny tool executions in Claude Code is extremely useful. I wish for that feature in opencode.

@cbgbt commented on GitHub (Jul 24, 2025): The ability to use hooks to deny tool executions in Claude Code is extremely useful. I wish for that feature in opencode.
Author
Owner

@tamirzb commented on GitHub (Jul 25, 2025):

For the record an issue about this was already opened three weeks ago (#573)

@tamirzb commented on GitHub (Jul 25, 2025): For the record an issue about this was already opened three weeks ago (#573)
Author
Owner

@jayair commented on GitHub (Jul 25, 2025):

Closing in favour of that

@jayair commented on GitHub (Jul 25, 2025): Closing in favour of that
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#861