From c9acadad4ad6768d41762abc941c514da3427fa9 Mon Sep 17 00:00:00 2001 From: Test Date: Fri, 3 Jul 2026 17:44:47 +0800 Subject: [PATCH] fix(prompt): remove stale always-on hooks system prompt hooks.txt taught the retired settings.json 6-layer protocol (hooks now live in dedicated hooks.json chains; .claude/ is never read) and stale event counts (22 vs actual 27). Discovery is preserved via the built-in configure-hooks skill injected through sys.skills(agent). Also fix README hooks section: 27 events and dead hooks-reference.md link now points at the skill doc. --- README.md | 6 +-- packages/opencode/src/session/prompt.ts | 4 +- .../opencode/src/session/prompt/hooks.txt | 37 ------------------- packages/opencode/src/session/system.ts | 6 --- 4 files changed, 4 insertions(+), 49 deletions(-) delete mode 100644 packages/opencode/src/session/prompt/hooks.txt diff --git a/README.md b/README.md index 0ffbd0b272..d90776d313 100644 --- a/README.md +++ b/README.md @@ -55,11 +55,11 @@ Built on top of the MIT-licensed [opencode](https://github.com/anomalyco/opencod ### 📌 Stable on `main` -#### Hooks API (22 events × 5 execution types) +#### Hooks API (27 events × 5 execution types) -Full Claude Code hooks protocol compatibility: `command`, `mcp`, `http`, `prompt`, `agent` hook types with 17 hook events including `PreToolUse`, `PostToolUse`, `SessionStart`, `PermissionRequest`, `WorktreeCreate`, and more. +Full Claude Code hooks protocol compatibility: `command`, `mcp`, `http`, `prompt`, `agent` hook types with 27 hook events including `PreToolUse`, `PostToolUse`, `SessionStart`, `PermissionRequest`, `WorktreeCreate`, and more. -See [hooks reference](./packages/opencode/src/session/prompt/hooks-reference.md). +See [hooks reference](./packages/core/src/plugin/skill/configure-hooks.md). #### Goal Auto-Loop diff --git a/packages/opencode/src/session/prompt.ts b/packages/opencode/src/session/prompt.ts index 7aa7cfe6c3..c749012492 100644 --- a/packages/opencode/src/session/prompt.ts +++ b/packages/opencode/src/session/prompt.ts @@ -1456,12 +1456,11 @@ export const layer = Layer.effect( yield* plugin.trigger("experimental.chat.messages.transform", {}, { messages: msgs }) - const [skills, env, instructions, mcpInstructions, hooksDocs, goalDocs, modelMsgs] = yield* Effect.all([ + const [skills, env, instructions, mcpInstructions, goalDocs, modelMsgs] = yield* Effect.all([ sys.skills(agent), sys.environment(model), instruction.system().pipe(Effect.orDie), sys.mcp(agent, session.permission), - sys.hooks(), sys.goal(sessionID), MessageV2.toModelMessagesEffect(msgs, model), ]) @@ -1470,7 +1469,6 @@ export const layer = Layer.effect( ...instructions, ...(mcpInstructions ? [mcpInstructions] : []), ...(skills ? [skills] : []), - ...hooksDocs, ...goalDocs, ] const format = lastUser.format ?? { type: "text" as const } diff --git a/packages/opencode/src/session/prompt/hooks.txt b/packages/opencode/src/session/prompt/hooks.txt deleted file mode 100644 index d312338e4c..0000000000 --- a/packages/opencode/src/session/prompt/hooks.txt +++ /dev/null @@ -1,37 +0,0 @@ -# Claude Code Hooks API - -OpenCode is **fully compatible with the Claude Code hooks protocol**. The hooks system is built-in and active. When installing plugins or configuring automations, **always use the standard Claude Code hooks mechanism** — do NOT skip hooks or assume they are unavailable. - -## Quick Reference - -**Settings paths** (6-layer chain, merged in order): -1. `~/.claude/settings.json` (global) -2. `~/.config/opencode/settings.json` (OpenCode global) -3. `/.claude/settings.json` -4. `/.opencode/settings.json` -5. `/.claude/settings.local.json` -6. `/.opencode/settings.local.json` - -**Hook types**: `command` | `mcp` | `http` | `prompt` | `agent` - -**22 actively triggered events**: PreToolUse, PostToolUse, PostToolUseFailure, FileChanged, UserPromptSubmit, Stop, StopFailure, InstructionsLoaded, SessionStart, SessionEnd, PermissionRequest, PermissionDenied, SubagentStart, SubagentStop, TaskCreated, TaskCompleted, TeammateIdle, PreCompact, PostCompact, WorktreeCreate, WorktreeRemove, ConfigChange - -**Config format**: -```json -{ - "hooks": { - "PreToolUse": [{ "matcher": "*", "hooks": [{ "type": "command", "command": "your-script.sh" }] }] - } -} -``` - -**Exit codes**: 0=allow (parse stdout JSON), 2=block (stderr=reason), other=log+continue - -**Env vars**: `CLAUDE_PROJECT_DIR`, `CLAUDE_PLUGIN_ROOT`, `CLAUDE_PLUGIN_DATA` - -## Detailed Reference - -For the complete protocol specification (stdin/stdout envelope, all event payloads, template variables, hookSpecificOutput fields), read: -``` -~/.config/opencode/docs/hooks-reference.md -``` diff --git a/packages/opencode/src/session/system.ts b/packages/opencode/src/session/system.ts index 0fa5a5a190..b1ae4b44eb 100644 --- a/packages/opencode/src/session/system.ts +++ b/packages/opencode/src/session/system.ts @@ -12,7 +12,6 @@ import PROMPT_KIMI from "./prompt/kimi.txt" import PROMPT_CODEX from "./prompt/codex.txt" import PROMPT_TRINITY from "./prompt/trinity.txt" -import PROMPT_HOOKS from "./prompt/hooks.txt" import PROMPT_GOAL from "./prompt/goal.txt" import type { Provider } from "@/provider/provider" import type { Agent } from "@/agent/agent" @@ -48,7 +47,6 @@ export interface Interface { readonly environment: (model: Provider.Model) => Effect.Effect readonly skills: (agent: Agent.Info) => Effect.Effect readonly mcp: (agent: Agent.Info, permission?: PermissionV1.Ruleset) => Effect.Effect - readonly hooks: () => Effect.Effect readonly goal: (sessionID: SessionID) => Effect.Effect } @@ -139,10 +137,6 @@ export const layer = Layer.effect( ].join("\n") }), - hooks: Effect.fn("SystemPrompt.hooks")(function* () { - return [PROMPT_HOOKS] - }), - goal: Effect.fn("SystemPrompt.goal")(function* (sessionID: SessionID) { // No Goal service wired into this entry point → degrade to a terse note. if (!goalSvc) return ["No autonomous goal is active for this session."]