Skip to content

Commit 9e4a856

Browse files
committed
docs(hooks): add docs about custom hooks
1 parent d2dcc60 commit 9e4a856

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,12 @@ require('opencode').setup({
252252
enabled = false, -- Enable debug messages in the output window
253253
},
254254
prompt_guard = nil, -- Optional function that returns boolean to control when prompts can be sent (see Prompt Guard section)
255+
256+
-- User Hooks for custom behavior at certain events
257+
hooks = {
258+
on_file_edited = nil, -- Called after a file is edited by opencode.
259+
on_session_loaded = nil, -- Called after a session is loaded.
260+
},
255261
})
256262
```
257263

@@ -585,6 +591,28 @@ The plugin defines several highlight groups that can be customized to match your
585591

586592
The `prompt_guard` configuration option allows you to control when prompts can be sent to Opencode. This is useful for preventing accidental or unauthorized AI interactions in certain contexts.
587593

594+
## 🪝Custom user hooks
595+
596+
You can define custom functions to be called at specific events in Opencode:
597+
598+
- `on_file_edited`: Called after a file is edited by Opencode.
599+
- `on_session_loaded`: Called after a session is loaded.
600+
601+
```lua
602+
require('opencode').setup({
603+
hooks = {
604+
on_file_edited = function(file_path, edit_type)
605+
-- Custom logic after a file is edited
606+
print("File edited: " .. file_path .. " Type: " .. edit_type)
607+
end,
608+
on_session_loaded = function(session_name)
609+
-- Custom logic after a session is loaded
610+
print("Session loaded: " .. session_name)
611+
end,
612+
},
613+
})
614+
```
615+
588616
### Configuration
589617

590618
Set `prompt_guard` to a function that returns a boolean:

0 commit comments

Comments
 (0)