effect-scope

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

3|Updated Apr 1, 2026
One-click install
npx skills add https://github.com/mpsuesser/opencode-effect-enforcer --skill effect-scope-mpsuesser
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: effect-scope
Source: https://github.com/mpsuesser/opencode-effect-enforcer/tree/main/skills/effect-scope
Command: npx skills add https://github.com/mpsuesser/opencode-effect-enforcer --skill effect-scope-mpsuesser

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Resources like file handles, database connections, and event listeners leak or get released too early when cleanup is not tied to a well-defined lifetime. This Skill teaches how to use Effect's Scope model so every acquisition gets guaranteed cleanup on success, failure, or interruption. ## Core Features & Use Cases - Scoped acquisition: Use Effect.acquireRelease, acquireDisposable, and acquireUseRelease to register cleanup finalizers that run when a scope closes. - Lifetime control: Eliminate Scope from an effect's requirements with Effect.scoped, Scope.provide, Scope.use, or Layer.effect, and split lifetimes with Scope.fork and ScopedRef. - Use Case: When building a service layer that opens a database connection and registers an error listener, wrap both in acquireRelease inside Layer.effect so teardown releases them in LIFO order at application shutdown. ## Quick Start Ask the agent to show how to acquire a resource with Effect.acquireRelease and guarantee its cleanup using Effect.scoped in an Effect v4 TypeScript program.

Frequently Asked Questions about effect-scope

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

FAQPage Schema
How do I acquire a resource with guaranteed cleanup in Effect?

Use Effect.acquireRelease with an acquire effect and a release function; the release finalizer is registered on the current scope and runs when that scope closes. Wrap the usage in Effect.scoped to eliminate Scope from the requirements and bound the resource's lifetime to that block.

What is the difference between Effect.acquireRelease and Effect.acquireUseRelease?

acquireRelease registers cleanup on the ambient Scope, so the resource can outlive a single callback, while acquireUseRelease brackets acquire, use, and release in one effect with no Scope requirement. Choose acquireUseRelease when the resource lifetime is exactly one callback.

Does Layer.scoped still exist in Effect v4?

No, Layer.scoped and Layer.scopedDiscard were removed in v4. Layer.effect and Layer.effectDiscard already eliminate Scope from the construction effect, releasing acquired resources when the layer is torn down.

Why do my scoped resources leak in a long-running Effect app?

Leaks happen when Scope is eliminated at the application root instead of the narrowest correct boundary, so every resource lives until the root scope closes. Place Effect.scoped close to each use site, or use per-item scopes inside loops.

How do I rotate credentials or connections without leaking the old resource?

Use ScopedRef.fromAcquire to hold a resource-backed reference, then ScopedRef.set to replace it; set acquires the replacement first and releases the previous value's scope. Replacement is synchronized and uninterruptible, and a failed acquisition leaves the current value untouched.