Hooks System
20+ built-in hooks that automate and enhance your workflow
What are Hooks?
Hooks are event-driven functions that run at specific points in the OpenCode workflow. They allow you to customize and extend functionality without modifying core code. Oh My OpenCode includes 20+ built-in hooks that are enabled by default.
Task Management Hooks
todo-continuation-enforcer
Ensures tasks are completed. Monitors todo items and prompts for continuation if tasks are left incomplete.
When it runs: During task execution and completion checks
empty-task-response-detector
Detects when responses are empty or incomplete, helping ensure tasks are properly handled.
When it runs: After receiving agent responses
Context Management Hooks
context-window-monitor
Monitors and manages context window usage. Tracks token usage and warns when approaching limits.
When it runs: Continuously during session
compaction-context-injector
Manages context compaction to stay within token limits. Intelligently compacts old context while preserving important information.
When it runs: When context window approaches limits
preemptive-compaction
Preemptive context compaction that runs before hitting limits. Configurable threshold (default 0.85).
When it runs: When context usage reaches threshold
Configuration: experimental.preemptive_compaction_threshold
anthropic-context-window-limit-recovery
Handles Anthropic-specific context window limits and recovery. Automatically manages context when hitting Anthropic API limits.
When it runs: When using Anthropic models and hitting limits
Session Management Hooks
session-recovery
Automatically recovers from errors, thinking block violations, and interruptions. Never lose your progress.
When it runs: After errors or interruptions
session-notification
Notifies about session events like starts, errors, and completions.
When it runs: On session events
auto_resume
Experimental Automatically resumes session after successful recovery. Extracts the last user message and continues.
When it runs: After successful recovery
Configuration: experimental.auto_resume
Code Quality Hooks
comment-checker
Validates code comments. Ensures code is properly documented and comments are meaningful.
When it runs: During code generation and review
thinking-block-validator
Validates thinking blocks to ensure they follow proper format and structure.
When it runs: When processing thinking blocks
Output Management Hooks
grep-output-truncator
Truncates large grep outputs to prevent context window overflow. Intelligently truncates while preserving important matches.
When it runs: After grep operations with large outputs
tool-output-truncator
Manages tool output sizes. Truncates outputs from whitelisted tools (Grep, Glob, LSP, AST-grep) to stay within limits.
When it runs: After tool operations with large outputs
Configuration: Can be configured to truncate ALL tool outputs via experimental.truncate_all_tool_outputs
aggressive_truncation
Experimental More aggressive tool output truncation when token limit is exceeded. Falls back to summarize/revert if insufficient.
When it runs: When token limit is exceeded
Configuration: experimental.aggressive_truncation
Workflow Hooks
directory-agents-injector
Injects directory-specific agents based on directory structure. Automatically enables relevant agents for different parts of your codebase.
When it runs: When entering directories with agent configurations
directory-readme-injector
Adds README context automatically. Injects README files from directories to provide better context.
When it runs: When entering directories with README files
rules-injector
Injects custom rules into the agent context. Allows project-specific rules and guidelines.
When it runs: At session start and when rules change
think-mode
Enables thinking mode for agents. Allows agents to use thinking blocks for complex reasoning.
When it runs: When thinking mode is requested
claude-code-hooks
Claude-specific hooks for enhanced Claude Code integration.
When it runs: When using Claude models
ralph-loop
Ralph agent loop management. Handles Ralph agent specific workflows.
When it runs: When using Ralph agent
Configuration & Utility Hooks
auto-update-checker
Checks for updates automatically. Notifies you when new versions are available.
When it runs: At startup and periodically
Note: The startup-toast hook is a sub-feature of this hook.
startup-toast
Shows startup notifications. Displays welcome messages and important information at startup.
When it runs: At startup
Note: This is a sub-feature of auto-update-checker. Disable separately to keep update checking but remove toast.
keyword-detector
Detects keywords in conversations. Can trigger specific behaviors based on detected keywords.
When it runs: During conversation processing
agent-usage-reminder
Reminds about agent usage. Provides helpful reminders about available agents and their capabilities.
When it runs: Periodically during sessions
non-interactive-env
Handles non-interactive environments. Adapts behavior for CI/CD and automated environments.
When it runs: When in non-interactive mode
interactive-bash-session
Manages interactive bash sessions. Handles interactive terminal sessions properly.
When it runs: During interactive terminal operations
empty-message-sanitizer
Cleans empty messages. Removes or handles empty messages in conversations.
When it runs: When processing messages
Disabling Hooks
Disable specific hooks via disabled_hooks in your configuration:
{
"disabled_hooks": ["comment-checker", "agent-usage-reminder"]
}
Configuration Locations
~/.config/opencode/oh-my-opencode.json- User-wide.opencode/oh-my-opencode.json- Project-specific
startup-toast hook is a sub-feature of auto-update-checker. To disable only the startup toast notification while keeping update checking enabled, add "startup-toast" to disabled_hooks. To disable all update checking features (including the toast), add "auto-update-checker" to disabled_hooks.
Hook Execution Order
Hooks are executed in a specific order to ensure proper functionality:
- Session initialization hooks (startup-toast, auto-update-checker)
- Context management hooks (context-window-monitor, preemptive-compaction)
- Workflow hooks (directory-agents-injector, directory-readme-injector, rules-injector)
- Task management hooks (todo-continuation-enforcer, empty-task-response-detector)
- Code quality hooks (comment-checker, thinking-block-validator)
- Output management hooks (grep-output-truncator, tool-output-truncator)
- Session management hooks (session-recovery, session-notification)