Просмотр исходного кода

feat(flags): allow disabling .claude prompt and skills loading (#7205)

freespace8 1 месяц назад
Родитель
Сommit
542c9d5346

+ 5 - 0
packages/opencode/src/flag/flag.ts

@@ -13,6 +13,11 @@ export namespace Flag {
   export const OPENCODE_ENABLE_EXPERIMENTAL_MODELS = truthy("OPENCODE_ENABLE_EXPERIMENTAL_MODELS")
   export const OPENCODE_DISABLE_AUTOCOMPACT = truthy("OPENCODE_DISABLE_AUTOCOMPACT")
   export const OPENCODE_DISABLE_MODELS_FETCH = truthy("OPENCODE_DISABLE_MODELS_FETCH")
+  export const OPENCODE_DISABLE_CLAUDE_CODE = truthy("OPENCODE_DISABLE_CLAUDE_CODE")
+  export const OPENCODE_DISABLE_CLAUDE_CODE_PROMPT =
+    OPENCODE_DISABLE_CLAUDE_CODE || truthy("OPENCODE_DISABLE_CLAUDE_CODE_PROMPT")
+  export const OPENCODE_DISABLE_CLAUDE_CODE_SKILLS =
+    OPENCODE_DISABLE_CLAUDE_CODE || truthy("OPENCODE_DISABLE_CLAUDE_CODE_SKILLS")
   export const OPENCODE_FAKE_VCS = process.env["OPENCODE_FAKE_VCS"]
   export const OPENCODE_CLIENT = process.env["OPENCODE_CLIENT"] ?? "cli"
 

+ 4 - 4
packages/opencode/src/session/system.ts

@@ -62,10 +62,10 @@ export namespace SystemPrompt {
     "CLAUDE.md",
     "CONTEXT.md", // deprecated
   ]
-  const GLOBAL_RULE_FILES = [
-    path.join(Global.Path.config, "AGENTS.md"),
-    path.join(os.homedir(), ".claude", "CLAUDE.md"),
-  ]
+  const GLOBAL_RULE_FILES = [path.join(Global.Path.config, "AGENTS.md")]
+  if (!Flag.OPENCODE_DISABLE_CLAUDE_CODE_PROMPT) {
+    GLOBAL_RULE_FILES.push(path.join(os.homedir(), ".claude", "CLAUDE.md"))
+  }
 
   if (Flag.OPENCODE_CONFIG_DIR) {
     GLOBAL_RULE_FILES.push(path.join(Flag.OPENCODE_CONFIG_DIR, "AGENTS.md"))

+ 19 - 16
packages/opencode/src/skill/skill.ts

@@ -7,6 +7,7 @@ import { Log } from "../util/log"
 import { Global } from "@/global"
 import { Filesystem } from "@/util/filesystem"
 import { exists } from "fs/promises"
+import { Flag } from "@/flag/flag"
 
 export namespace Skill {
   const log = Log.create({ service: "skill" })
@@ -80,22 +81,24 @@ export namespace Skill {
       claudeDirs.push(globalClaude)
     }
 
-    for (const dir of claudeDirs) {
-      const matches = await Array.fromAsync(
-        CLAUDE_SKILL_GLOB.scan({
-          cwd: dir,
-          absolute: true,
-          onlyFiles: true,
-          followSymlinks: true,
-          dot: true,
-        }),
-      ).catch((error) => {
-        log.error("failed .claude directory scan for skills", { dir, error })
-        return []
-      })
-
-      for (const match of matches) {
-        await addSkill(match)
+    if (!Flag.OPENCODE_DISABLE_CLAUDE_CODE_SKILLS) {
+      for (const dir of claudeDirs) {
+        const matches = await Array.fromAsync(
+          CLAUDE_SKILL_GLOB.scan({
+            cwd: dir,
+            absolute: true,
+            onlyFiles: true,
+            followSymlinks: true,
+            dot: true,
+          }),
+        ).catch((error) => {
+          log.error("failed .claude directory scan for skills", { dir, error })
+          return []
+        })
+
+        for (const match of matches) {
+          await addSkill(match)
+        }
       }
     }
 

+ 3 - 0
packages/web/src/content/docs/cli.mdx

@@ -566,6 +566,9 @@ OpenCode can be configured using environment variables.
 | `OPENCODE_DISABLE_LSP_DOWNLOAD`       | boolean | Disable automatic LSP server downloads   |
 | `OPENCODE_ENABLE_EXPERIMENTAL_MODELS` | boolean | Enable experimental models               |
 | `OPENCODE_DISABLE_AUTOCOMPACT`        | boolean | Disable automatic context compaction     |
+| `OPENCODE_DISABLE_CLAUDE_CODE`        | boolean | Disable reading from `.claude` (prompt + skills) |
+| `OPENCODE_DISABLE_CLAUDE_CODE_PROMPT` | boolean | Disable reading `~/.claude/CLAUDE.md`     |
+| `OPENCODE_DISABLE_CLAUDE_CODE_SKILLS` | boolean | Disable loading `.claude/skills`          |
 | `OPENCODE_CLIENT`                     | string  | Client identifier (defaults to `cli`)    |
 | `OPENCODE_ENABLE_EXA`                 | boolean | Enable Exa web search tools              |