Cursor app hooks bugs of additional_context

Where does the bug appear (feature/product)?

Cursor IDE

Describe the Bug

sessions history:

# Hook script injection information

## User

你是否看到hook脚本注入信息,直接回答我,不要去调用任何tool

## Assistant

我这边**看不到**单独标成「hook 脚本注入」的字段或段落

当前上下文只有:用户信息、工作区/用户规则、技能列表、MCP 说明、以及你的这条消息

若 hook 把内容写进规则或系统提示,我会当成普通规则读,**无法区分**是不是 hook 注入的

## User

你上下文中没有看到 ## 会话约束 么?

## Assistant

**没有**

我这次收到的上下文里**没有** `## 会话约束` 这一段

若你的 hook 会注入它,要么没进 Agent 上下文,要么只在别的通道(例如 UI/终端)里出现

hooks log

input:
{
  "conversation_id": "7136cdd7-209d-4c73-91ee-3a60b144292a",
  "generation_id": "",
  "model": "composer-2.5",
  "model_id": "composer-2.5",
  "model_params": [
    {
      "id": "fast",
      "value": "false"
    }
  ],
  "is_background_agent": false,
  "composer_mode": "agent",
  "session_id": "7136cdd7-209d-4c73-91ee-3a60b144292a",
  "hook_event_name": "sessionStart",
  "cursor_version": "3.8.23",
  "workspace_roots": [
    "/Users/eos/dev/bin"
  ],
  "user_email": "[email protected]",
  "transcript_path": null
}

output:
{
  "additional_context": "## 会话约束(全局 hook 注入)\n\n你必须**严格按照**遵守用户的 ~/.cursor/rules,\n- chinese-language\n- eos-code-taste\n- think-before-coding\n"
}

Steps to Reproduce

my hooks code

import fs from "node:fs"
import path from "node:path"

const input = JSON.parse(fs.readFileSync(0, "utf8") || "{}")

const roots = input.workspace_roots
const root =
  (Array.isArray(roots) && typeof roots[0] === "string" && roots[0]) ||
  input.workspaceRoot ||
  input.workspace_root ||
  input.projectRoot ||
  input.project_root ||
  input.cwd ||
  process.env.CURSOR_WORKSPACE_ROOT ||
  process.cwd()

const BASE_CONTEXT = [
  "## 会话约束(全局 hook 注入)",
  "",
  "你必须**严格按照**遵守用户的 ~/.cursor/rules,",
  "- chinese-language",
  "- eos-code-taste",
  "- think-before-coding",
  "",
].join("\n")

const VITEPLUS_COMMANDS = [
  "优先使用 viteplus 命令:",
  "- 启动开发服务器:vp dev",
  "- 生产构建:vp build",
  "- 构建并监听:vp build --watch",
  "- 格式化 + lint + 类型检查:vp check",
  "- 检查并自动修复:vp check --fix",
  "- 仅格式化:vp fmt",
  "- 检查格式而不修改:vp fmt --check",
  "- 仅 lint:vp lint",
  "- lint 并自动修复:vp lint --fix",
  "- 运行测试:vp test",
  "- 监听模式测试:vp test watch",
  "- 运行 package.json 脚本:vp run <script>",
  "",
].join("\n")

function scanWorkspaceRoot(projectRoot) {
  let isViteplus = false
  let hasCheckScript = false

  try {
    const entries = new Set(fs.readdirSync(projectRoot))
    isViteplus =
      entries.has("viteplus.config.ts") || entries.has("viteplus.config.js")
    if (entries.has("tools")) {
      hasCheckScript = fs.existsSync(
        path.join(projectRoot, "tools", "check.sh"),
      )
    }
  } catch {
    // 工作区不可读时仅注入全局约束
  }

  return { isViteplus, hasCheckScript }
}

const { isViteplus, hasCheckScript } = scanWorkspaceRoot(root)

let additional_context = BASE_CONTEXT

if (isViteplus) {
  additional_context += [
    "",
    `当前项目识别为 viteplus 项目:${root}`,
    "",
    VITEPLUS_COMMANDS,
  ].join("\n")
}

const checkRel = "tools/check.sh"
if (hasCheckScript) {
  additional_context += [
    "",
    `当前工作区提供统一检查脚本 \`${checkRel}\`。`,
    `修改代码后的验证**优先**在工作区根目录执行:\`bash ${checkRel}\`。`,
    `如果 \`${checkRel}\` 不完善你需补全功能,而不是调用其他工具`,
    "完成实质性代码改动后,在交付前应跑通一次上述检查",
  ].join("\n")
}

process.stdout.write(JSON.stringify({ additional_context }))

Operating System

MacOS

Version Information

Version: 3.8.23 (Universal)
VS Code Extension API: 1.105.1
Commit: 7cf19b7482706625cdb70db3211b7dd035b7aa30
Date: 2026-06-23T14:57:42.334Z
Layout: glass
Build Type: Stable
Release Track: Default
Electron: 40.10.3
Chromium: 144.0.7559.236
Node.js: 24.15.0
V8: 14.4.258.32-electron.0
xterm.js: 6.1.0-beta.256
OS: Darwin x64 22.6.0

Does this stop you from using Cursor

No - Cursor works, but with this issue

Hey @eos

Thanks for the report. This is a known issue that has beeen reported previously.

I’ve attached your report to your existing bug report, which helps us prioritize!