effect-scope

Manage resource lifecycles in Effect v4 using Scope, finalizers, and scoped acquisition APIs.

1|Updated Aug 24, 2026
One-click install
npx skills add https://github.com/lambdasolver2/opencode-effect-harness --skill effect-scope-lambdasolver2
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: effect-scope
Source: https://github.com/lambdasolver2/opencode-effect-harness/tree/main/packages/module-typescript/assets/skills/effect-scope
Command: npx skills add https://github.com/lambdasolver2/opencode-effect-harness --skill effect-scope-lambdasolver2

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Effect v4 code that acquires resources like connections, file handles, or event listeners needs guaranteed cleanup, but the v4 Scope API differs substantially from v3 and most training data, causing leaks, premature releases, and compile errors from renamed APIs. ## Core Features & Use Cases - Scoped acquisition: Guides correct use of Effect.acquireRelease, acquireDisposable, acquireUseRelease, and addFinalizer so cleanup always runs on success, failure, or interruption. - Scope elimination and ownership: Explains Effect.scoped, scopedWith, Scope.provide/use, manual Scope.make/close/fork, and how Layer.effect owns scopes in v4. - Advanced lifetime patterns: Covers ScopedRef for rotating resources, forkScoped/forkIn for fibers bound to scopes, child scopes for per-job lifetimes, and LIFO finalizer ordering semantics. - Use Case: When a database connection leaks in a long-running Effect service, apply this Skill to wrap acquisition in Effect.scoped at the right boundary or move it into a Layer.effect constructor with proper teardown. ## Quick Start Use the effect-scope skill to fix this Effect v4 code so the database connection is released when the request finishes.

Frequently Asked Questions about effect-scope

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I acquire and release resources in Effect v4?

Use Effect.acquireRelease with an acquire effect and a release function that receives the Exit. The release finalizer registers on the current Scope and runs when that scope closes, whether by success, failure, or interruption. Eliminate the Scope requirement with Effect.scoped at the narrowest correct boundary.

What replaced Layer.scoped and Scope.extend in Effect v4?

Layer.effect and Layer.effectDiscard now eliminate Scope from the construction effect directly, so Layer.scoped no longer exists. Scope.extend was renamed to Scope.provide, which injects a scope without closing it; Scope.use injects and closes.

Does Effect.acquireRelease allow interruption during acquisition?

Acquisition is uninterruptible by default in v4. Pass { interruptible: true } as the third argument to allow interruption; there is no separate acquireReleaseInterruptible function anymore.

Why do my Effect finalizers run in unexpected order?

Scope finalizers run in reverse registration order (LIFO), sequentially by default. Opt into parallel finalization per scope with Scope.make('parallel'); all finalizers always run even if one fails, with failures combined into a single Cause.

When should I use ScopedRef instead of a regular Ref in Effect?

Use ScopedRef when the held value owns resources that must be released on replacement, such as rotating connections or refreshed credentials. ScopedRef.set closes the old value's scope before acquiring the new one, and the outer scope closes the current value on shutdown.

Why does my resource leak in a long-running Effect application?

Leaks happen when Scope is eliminated at the app root instead of near the use site, so resources live until shutdown. Wrap per-request or per-job work in Effect.scoped, or fork a child scope per item so finalizers run when each unit of work exits.