hooks: Instructions file for Codex

AGENTS.md

hooks AGENTS.md is an instructions file for Codex, OpenCode from alibaba/hooks. It costs 1,010 tokens per session, scanned A, original, MIT.

Repository instructions for Alibaba's Hooks, a TypeScript library of reusable React Hooks. They require reading the instructions and related code first, following existing patterns, and keeping public code accurately typed and compatible.

In plain words
What is it for?
Use them for any task in the repository, especially when adding or changing Hooks, interfaces, generics, component properties, type guards, documentation, or compatibility support.
Why use it?
They reduce accidental breaking changes, unclear types, unnecessary dependencies, and mismatches with the project's established code style.

Instructions file for CodexOpenCode ✓ vendor

Written for Codex and OpenCode: the file is AGENTS.md.

This is alibaba/hooks's own configuration. It tells Codex and OpenCode how to work on hooks itself, so it is not a mod to install elsewhere. Copy it as a starting point and replace the rules that are about this project. Everything hooks configures →

About the project

alibaba/hooks is a TypeScript library of React Hooks, including basic utilities and Hooks shaped by common application development needs. React developers use it in applications that may also require server-side rendering and predictable static types. The catalogue entries provide rules and instructions for using the library.

alibaba/hooks · 14,975 stars · on GitHub · ahooks.js.org

Reuse

Borrowing it

Nothing to install: this file belongs to alibaba/hooks. Take a copy, put it at the same path in your own repository, and replace the rules that are about this project with yours.

Copy the file
curl -O https://raw.githubusercontent.com/alibaba/hooks/master/AGENTS.md
Clone the repo
git clone --depth 1 https://github.com/alibaba/hooks

Made for: Codex, OpenCode.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for hooks AGENTS.md

README.md
[![agentmods](https://agentmods.dev/badge/instructions/alibaba/hooks/agents-md/github.svg)](https://agentmods.dev/instructions/alibaba/hooks/agents-md)
Your own site
<a href="https://agentmods.dev/instructions/alibaba/hooks/agents-md"><img src="https://agentmods.dev/badge/instructions/alibaba/hooks/agents-md/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for hooks AGENTS.md

Your own site · 80×15
<a href="https://agentmods.dev/instructions/alibaba/hooks/agents-md"><img src="https://agentmods.dev/badge/instructions/alibaba/hooks/agents-md.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 1,010 This file is loaded in full into every session.
When invoked 1,010 The same file — it is already loaded in full.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.01010 $0.01010
Opus 5.5 $0.00404 $0.00404
Sonnet 5.5 $0.00202 $0.00202
Haiku 4.5 $0.00101 $0.00101

Measured 2mo ago against content hash a3e572f22728, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

hooks AGENTS.md scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2mo ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

AGENTS.md · 107 lines

What it actually says

项目背景

这是由蚂蚁团队开发的一个高质量、可靠的 React Hooks 库。

  • 易学易用
  • 支持 SSR
  • 对输入输出函数做了特殊处理,避免闭包问题
  • 包含大量提炼自业务的高级 Hooks
  • 包含丰富的基础 Hooks
  • 使用 TypeScript 构建,提供完整的类型定义文件

开始任何任务前

  1. 完整阅读本文件。
  2. 明确任务范围,并先阅读相关现有实现,优先复用仓库中的既有模式。
  3. 保持与现有代码风格、架构和命名一致,不要为了“更优写法”偏离团队约定。

编码规范

  • 使用 TypeScript 和 React 书写
  • 避免引入新依赖,严控打包体积
  • 兼容现代浏览器
  • 支持服务端渲染
  • 保持向下兼容,避免 breaking change
  • 合理使用 React.memo、useMemo 和 useCallback 优化性能

TypeScript 规范

基本原则

  • 所有组件和函数必须提供准确的类型定义
  • 尽量避免使用 any 类型,尽可能精确地定义类型
  • 使用接口而非类型别名定义对象结构
  • 导出所有公共接口类型,方便用户使用
  • 严格遵循 TypeScript 类型设计原则,确保类型安全
  • 确保编译无任何类型错误或警告

hook 类型定义

  • 复杂的数据结构应拆分为多个接口定义
  • 所有函数类型应明确定义参数和返回值

泛型使用

  • 适当使用泛型增强类型灵活性
  • 为泛型参数提供合理的默认类型和约束
  • 避免过度使用泛型导致类型复杂化
  • 在泛型参数上应用限制条件(constraints)确保类型安全
  • 为复杂泛型提供类型别名以提高可读性

类型合并与扩展

  • 使用交叉类型(&)合并多个类型
  • 使用 Partial、Pick<T, K>、Omit<T, K> 等工具类型修改现有类型
  • 扩展原生 DOM 元素属性时,继承相应的内置类型
  • 使用 type 定义联合类型和交叉类型
  • 优先使用自带的工具类型,避免重复定义

枚举和常量

  • 使用字面量联合类型定义有限的选项集合
  • 为复杂的枚举值提供类型守卫函数
  • 避免使用 enum,优先使用联合类型和 as const
  • 对于关键常量,使用 as const 断言确保类型严格
  • 为联合类型中的每个值提供适当的注释

类型推断与断言

  • 尽可能依赖 TypeScript 的类型推断
  • 只在必要时使用类型断言(as)
  • 使用类型守卫函数进行运行时类型检查
  • 尽量避免使用非空断言操作符(!)
  • 使用 instanceof 和 typeof 进行类型守卫
  • 为自定义类型创建类型谓词(type predicates)函数

JSDoc 注释

  • 为复杂的类型、函数、hook 添加 JSDoc 注释
  • 使用 @deprecated 标记已废弃的 API
  • 在注释中提供使用示例
  • 说明参数和返回值的含义与约束
  • 在 interface 和重要类型定义上添加文档注释

类型兼容性

  • 确保类型定义兼容不同版本的 React
  • 避免使用实验性或不稳定的 TypeScript 特性
  • 为第三方库未提供的类型编写声明文件
  • 使用条件类型处理复杂的类型逻辑
  • 验证类型在不同 TypeScript 版本下的兼容性

严格使用 TypeScript 类型

  • 导出组件类型和接口
  • 避免使用 any,优先使用 unknown
  • 组件 Props 使用 interface 定义
  • 使用明确的命名约定
  • 合理使用泛型提高复用性
  • 导出类型时使用 export type
  • 组件属性使用 JSDoc 注释说明用途

测试规范

  • 使用 vitest 和 @testing-library/react 编写单元测试
  • 测试覆盖率要求 100%
  • 测试文件放在 tests 目录,命名格式为:index.spec.ts 或 xxx.spec.ts
Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2mo ago First seen · 107 lines · 1,010 tokens per session scan A a3e572f22728

Subscribe to this mod's changes

hooks AGENTS.md is an instructions file published in the GitHub repository alibaba/hooks (14,975 stars, last pushed 10d ago), licensed MIT. It adds 1,010 tokens to every session, about $0.0040 per session on Opus 5.5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-01.

Related

hooks AGENTS.md compared with instructions from other repositories

hooks AGENTS.md next to 6 instructions from other repositories
ModTypeStarsLast pushLicenceScanTokensWorks with
hooks AGENTS.mdalibaba/hooksInstructions file15k10d agoMITA1,010Codex, OpenCode
vscode buildNext.instructions.mdmicrosoft/vscodeInstructions file195ktodayMITA9,719GitHub Copilot
next.js AGENTS.mdvercel/next.jsInstructions file143ktodayMITA7,461Codex, OpenCode
langchain AGENTS.mdlangchain-ai/langchainInstructions file149ktodayMITA4,680Codex, OpenCode
vscode oss-third-party-notices.instructions.mdmicrosoft/vscodeInstructions file195ktodayMITA5,516GitHub Copilot
vscode copilot-instructions.mdmicrosoft/vscodeInstructions file195ktodayMITA3,093GitHub Copilot
deepseek-harness AGENTS.mddeepseek-ai/deepseek-harnessInstructions file274k2d agoMITA4,313Codex, OpenCode