Add Agent Hooks (Open Code)
Step 0: Language selection
Before proceeding with any other steps in this skill, ask the user which language to continue in using AskUserQuestion. Keep this initial prompt in English because the preferred language is not yet known.
- Question:
Which language should I continue in? - Options:
English,日本語 (Japanese)
Use the selected language for all subsequent user-facing messages and for every further AskUserQuestion prompt in this skill. Do not translate code, file paths, shell commands, or file contents.
Enable PostToolUse and SessionStart hooks for Open Code containers that send real-time notifications to the chat channel.
What it does
- PostToolUse — Sends a message like
🔧 `Bash: ls -la /workspace/group`to the chat channel after each tool execution - SessionStart — Sends
💭 Thinking...when a new session begins
Steps
1. Check prerequisites
test -f deploy/{ASSISTANT_NAME}/host/entry.ts && echo "ENTRY_EXISTS" || echo "ENTRY_MISSING"
test -f deploy/templates/container/open-code/entry.template.ts && echo "TEMPLATE_EXISTS" || echo "TEMPLATE_MISSING"
If deploy/{ASSISTANT_NAME}/host/entry.ts is missing, run /setup first.
2. Create agent-hooks plugin for Open Code
Check if plugin already exists:
test -d container/open-code/plugins/agent-hooks && echo "EXISTS" || echo "MISSING"
If missing, copy from Claude Code's plugin (they share the same IPC-based logic):
mkdir -p container/open-code/plugins/agent-hooks
cp container/claude-code/plugins/agent-hooks/index.mjs container/open-code/plugins/agent-hooks/index.mjs
3. Enable hooks in deploy/{ASSISTANT_NAME}/host/entry.ts (host side)
Read deploy/{ASSISTANT_NAME}/host/entry.ts and check if registerHooksPlugin is already called.
If not present, add after the MCP plugin registrations:
// Register agent hooks (PostToolUse / SessionStart notifications to chat)
orchestrator.registerHooksPlugin({
postToolUse: true,
sessionStart: true,
});
4. Enable hooks in deploy/templates/container/open-code/entry.template.ts (container side)
Read deploy/templates/container/open-code/entry.template.ts and check if the agent-hooks plugin is loaded.
If not present, ensure the plugin import block exists:
try {
const pluginPath = "/app/agent-plugins/agent-hooks/index.mjs";
const agentHooks = await import(/* webpackIgnore: true */ pluginPath);
plugins.push({
name: "agent-hooks",
createHooks: (
chatJid: string,
groupFolder: string,
hooksConfig: { postToolUse?: boolean; sessionStart?: boolean; skipTools?: string[] } | undefined,
log: (msg: string) => void,
) => ({
...(hooksConfig?.postToolUse !== false ? {
PostToolUse: [{ hooks: [agentHooks.createPostToolUseHook(chatJid, groupFolder, hooksConfig?.skipTools, log)] }],
} : {}),
...(hooksConfig?.sessionStart !== false ? {
SessionStart: [{ hooks: [agentHooks.createSessionStartHook(chatJid, groupFolder, log)] }],
} : {}),
}),
});
} catch {
// Plugin not available, skip
}
5. Sync local entry.ts
cp deploy/templates/container/open-code/entry.template.ts deploy/{ASSISTANT_NAME}/container/open-code/entry.ts
Or run /deploy and select Open Code.
6. Rebuild and restart
./container/open-code/build.sh
launchctl kickstart -k gui/$(id -u)/com.nagi.{ASSISTANT_NAME}
sleep 2
launchctl list | grep com.nagi.{ASSISTANT_NAME}
7. Test
Tell user to send a message in Slack/Discord that triggers tool use.
Expected: tool execution notifications appear in the chat channel.