
Effect
Skill用 Effect v4 构建生产级 TypeScript 应用的约定:用 Effect.gen 组织流程、Context.Service 与 Layer 定义服务、Schema 建模数据与错误、Config 读取配置、Schedule 做重试、Stream 处理事件、HttpClient 发请求、TestClock 写测试,并列出不该用的写法。需要项目使用 Effect v4。
name: effect
description: |
Opinionated guide for building production TypeScript applications with Effect v4. Use when implementing Effect workflows, services, layers, schemas, configuration, schedules, caches, streams, HTTP clients, or tests.
license: MIT
compatibility: Requires Effect v4. Examples are reviewed against the version documented in this repository.
Effect
Use current Effect v4 APIs and the production defaults in this skill. Established project conventions still take precedence unless the task is explicitly changing them.
Source Rule
Reviewed against Effect 4.0.0, upstream commit
6389d9ac6.
Read references/V4_APIS.md when upgrading from v3 or a v4 prerelease.
The installed version takes precedence: prerelease APIs and import paths can differ.
Check these before guessing:
- the nearest
AGENTS.mdand any project-local Effect practices doc - the project-pinned
effectpackage source and version - current upstream Effect source when the installed package does not answer the question
Branch Chooser
Read only the branch references that match the task.
- Data models, schemas, brands, variants, optional keys, or decoders: read
references/SCHEMA.md. - Services, module surfaces, layers, runtime wiring, errors,
Effect.fn, or test services: readreferences/SERVICES_LAYERS.md. - Runtime config, env variables,
ConfigProvider, orlayerConfig: readreferences/CONFIG.md. - Retry, repeat, polling, backoff, jitter, rate-limit-aware policies, or pass loops: read
references/SCHEDULING.md. - Memoization, per-key TTL caches, deduplicating concurrent lookups, or request batching: read
references/CACHING.md. - Streams, event sources, async iterables, queues/pubsubs, pagination, backpressure, or stream consumers: read
references/STREAMS.md. - Outgoing HTTP calls, Effect HttpClient, status handling, or HTTP rate limiting: read
references/HTTP_CLIENTS.md. - Effect tests, time, sleeps, concurrency synchronization, or fakes: read
references/TESTING.md.
If a task spans several branches, read all matching files before editing.
Core Defaults
- Compose workflows with
Effect.gen(function* () { ... }). - Define public service methods and non-trivial internal service methods with
Effect.fn("Domain.operation"). - Use
Effect.fnUntracedonly for internal helpers where stack-frame/span metadata is intentionally unnecessary. - Prefer
Context.Servicefor application services when the codebase has not standardized on another current service-tag style. - Build real service implementations with
Layer.effect(Service, Effect.gen(...))and returnService.of({ ... }). - Model records with
Schema.Struct(...)plus a same-nameinterface. - Model typed Effect errors with
Schema.TaggedError. - Read runtime config through
Config, not directprocess.envaccess in application logic. - Use
Schedulefor retry, repeat, polling, pacing, and backoff policies. - Use
Streamfor effectful sources that emit many values over time and need pull, backpressure, interruption, or transformation. - Prefer Effect HTTP client modules for outgoing HTTP in Effect applications when their typed errors, layers, and client transforms are useful.
- Prefer Effect-aware tests, explicit layers, and deterministic synchronization over sleeps.
- Decode unknown wire input with
Schema.decodeUnknownEffect(...); useschema.makeEffect(...)for typed constructor input with validation. Reserve throwingschema.make(...)for trusted construction, and never use casts to skip validation.
Quick Selection Guide
- Ordinary object record:
Schema.Struct(...)plus same-nameinterface. - Scalar ID/value object: constrained branded schema.
- Internal workflow decision or state:
Data.TaggedEnum<...>plusData.taggedEnum<...>()constructors and exhaustive$match. - Reusable boundary-crossing tagged variant:
Schema.TaggedStruct(...)plus same-nameinterface. - Boundary-crossing tagged union:
Schema.TaggedUnion(...)with.cases,.guards, and.match. - External/custom discriminator such as
type:Schema.Struct({ type: Schema.tag("variant"), ... })plusSchema.toTaggedUnion("type")when union helpers are needed. - Expected typed failure:
Schema.TaggedError. - Unknown boundary payload:
Schema.decodeUnknownEffect(...). - Service boundary:
Context.Service<Service, Interface>()(...)plusLayer.effect(...)plusService.of(...). - Public or non-trivial internal service method:
Effect.fn("Domain.operation"). - Runtime configuration:
Configrecipes read in layers; override withConfigProviderin tests. - Event source:
Streamconsumed withStream.runForEach(...)and forked withEffect.forkScopedin the owning layer. - Queue-backed event source:
Queuefor the producer boundary,Stream.fromQueue(...)for consumers. - Broadcast event source:
PubSub/Stream.fromPubSub(...)orSubscriptionReffor latest-value state. - Polling worker:
runPass().pipe(Effect.repeat(Schedule.spaced(...))), with typed pass failures handled before repeat. - Retry transient operation:
Effect.retry(...)/Effect.retryOrElse(...)with a boundedSchedule. - Keyed lookup cache with TTL and concurrent-lookup dedupe: prefer
Cache.make(...)/ exit-awareCache.makeWith(...)when their lifecycle and eviction model fit. - Memoize a single effect result:
Effect.cached(...)/Effect.cachedWithTTL(...). - Batch N keys into one backend call (only when a real batch endpoint exists):
Effect.request(...)+RequestResolver. - HTTP request in an Effect application: prefer Effect
HttpClientplus request/response schema decoding. - HTTP transient retry:
HttpClient.retryTransient(...). - Time-sensitive test:
TestClock, not real sleeping. - Concurrent/background test synchronization:
Deferred,Queue,Latch,Ref, or explicit test hooks.
Boundary Rules
- Keep HTTP handlers thin: decode input, read context, call services, map typed errors to transport responses.
- Keep business rules in services or domain functions, not transport handlers.
- Wrap HTTP clients, SDKs, CLIs, and external integrations in named effects at adapter boundaries.
- Decode persisted rows with Schema or SQL-specific helpers when values are not trivially trusted.
- Keep provider/network calls outside authoritative database transactions.
- Catch or retry only when the current boundary has a truthful response.
- Retry only when the operation has proven idempotency.
- Let exhausted failures remain visible unless the boundary has a real fallback.
Do Nots
- Do not use
as any, non-null assertions, or unchecked casts to silence Effect typing problems. - Do not introduce
Schema.ClassorSchema.TaggedClassas default app data-modeling patterns. - Do not hand-roll
_tagerror classes whenSchema.TaggedErrorfits. - Do not use cause-level recovery when typed-error recovery is enough.
- Do not use
Layer.mergeAll(...)orprovideMerge(...)as blind make-it-compile tools. - Do not hide required application authority, credentials, persistence, transports, or external services behind
Context.Referencedefaults. - Do not add arbitrary
Effect.sleep(...)to tests when a deterministic synchronization primitive is available. - Do not hand-roll Map/TTL/prune caches or in-flight dedupe when
effect/Cachefits.
相關資源

TypeScript LSP
Plugin为 Claude Code 接入 TypeScript/JavaScript 语言服务器,提供跳转定义、查找引用与实时类型错误检查。需先全局安装 typescript-language-server。Anthropic 官方插件。
anthropics/claude-plugins-official46.1k
Antfu Conventions
SkillAnthony Fu 对 JavaScript / TypeScript 项目的约定与工具偏好:代码组织、显式导入、Vitest 测试写法,以及 @antfu/ni、开启 antislop 的 @antfu/eslint-config、Knip、tsdown 和统一的 ci 脚本,新建项目时参照 antfu/starter-ts 模板。
antfu/skills6k
Verification Before Completion
Skill要求 agent 在声称完成、已修复或测试通过之前,先运行完整的验证命令并读完输出,用证据支撑结论,杜绝未经验证的成功声明。出自 Superpowers 工作流。
obra/superpowers314k
Karpathy-Inspired Claude Code Guidelines
Skill按 Karpathy 对大模型写代码常见毛病的观察整理的行为准则:先想清楚再动手、简单优先、只做外科手术式改动、以可验证的目标驱动。也可直接当 CLAUDE.md 使用。
multica-ai/andrej-karpathy-skills229k
MCP Builder
Skill指导 agent 构建高质量 MCP 服务器:调研协议与目标 API、设计工具、用 Python(FastMCP)或 TypeScript SDK 实现,并编写评测问题验证效果。Anthropic 官方技能。
anthropics/skills188k
Ponytail
Skill让 agent 按「能不写就不写」的阶梯解题:先问是否需要,再依次复用现有代码、标准库、平台原生能力与已装依赖,只写最少的必要代码,但保留校验、错误处理、安全与无障碍。
DietrichGebert/ponytail186k