# Context and requirements

> For agents: start with the [agent guide](https://ratstack.sh/llms.txt). Every page is Markdown by default; add `Accept: text/html` for HTML.

New on /news: [Effect Office Hours 52 with Resonate HQ](/news).

**Goal:** read an [Effect](/lore/effect-basics) type and say which services the work still needs.

An Effect type has three parts: what the work returns, how it can fail, and which services it needs.
The third part is the requirements.
A context is the set of services that running work receives.

## Worked example: inspecting a file

rat-stack's file inspection reads a file through a `FileInspector` [service](/lore/services-capture-dependencies).
The [actor](/lore/lifecycles-are-machines) that does the read asks for that service by name:

packages/core/src/inspect-machine.ts at a3f5a14861ce89913e82bea0f7ba02c83e8d4725; lines 27-31; highlighted 29. Title: The read asks for FileInspector.

```typescript
const readStats = createEffectLogic({
  effect: ({ input }) =>
    FileInspector.use((inspector) => inspector.inspect(input.path)),
  schemas: { input: Schema.Struct({ path: Schema.String }) },
});
```

`FileInspector.use` returns an Effect whose requirements include `FileInspector`.
Nothing runs yet.
The type now records a debt: some caller must supply a `FileInspector`.

The CLI pays that debt once, at startup:

apps/cli/src/cli.ts at a3f5a14861ce89913e82bea0f7ba02c83e8d4725; lines 22-24; highlighted 24. Title: The composition root supplies it.

```typescript
  Effect.provide(
    Layer.mergeAll(
      Layer.provideMerge(FileInspector.layer, NodeServices.layer),
```

`Effect.provide` removes `FileInspector` from the requirements.
`FileInspector.layer` itself needs a file system, and `NodeServices.layer` supplies it.

The tests pay the same debt with their own Layer:

packages/core/test/inspect-machine.test.ts at a3f5a14861ce89913e82bea0f7ba02c83e8d4725; lines 14-14; highlighted none. Title: A test supplies the same requirement.

```typescript
const TestLayer = Layer.provideMerge(FileInspector.layer, NodeServices.layer);
```

The diagram above shows the same move on a small `Greeter` service: `provide` turns `Greeter` into `never`.

## Why the type carries it

The compiler rejects execution while a required service remains unsupplied. [Dependency injection](/lore/dependency-injection-is-the-reason-to-choose-effect) shows that rule.
A forgotten service fails the typecheck before the program runs.

Sam Goodwin describes this requirements channel as a way to model permissions before execution, which he calls a static effect.
He connects that idea to [Alchemy](/skills/learn-alchemy) inferring which identity and access management (IAM) policy a program needs. [Happy Path 116, 11:54](https://youtu.be/YEn4A7XxgF4?t=714)

Michael Arnaldi describes an Effect by its output, predictable failures, and requirements. [Happy Path 81, 49:15](https://youtu.be/gc5P36t6kD0?t=2955)

## Next

Read [how a service captures its dependencies](/lore/services-capture-dependencies) to see what `FileInspector` keeps inside itself.
Then read [why dependency injection matters](/lore/dependency-injection-is-the-reason-to-choose-effect).

See [Effect basics](/lore/effect-basics) for the whole type, and [infrastructure as effects](/lore/infrastructure-as-effects) for Sam's infrastructure reading.

## Sources

1. [#116 Infrastructure as Effects with Sam Goodwin - YouTube](https://youtu.be/YEn4A7XxgF4?t=714)
   Sam Goodwin. Requirements-channel discussion; used for static infrastructure permissions. Accessed 2026-10-01.

2. [#81 TypeScript & Effects with Michael Arnaldi - YouTube](https://youtu.be/gc5P36t6kD0?t=2955)
   Michael Arnaldi. Effect type explanation; used for output, failure, and service requirements. Accessed 2026-10-01.

3. [Inspection machine actor](https://github.com/joelhooks/rat-stack/blob/a3f5a14861ce89913e82bea0f7ba02c83e8d4725/packages/core/src/inspect-machine.ts)
   GitHub joelhooks/rat-stack. readStats asks for FileInspector, so its Effect carries that requirement. Accessed 2026-11-08.

4. [CLI composition root](https://github.com/joelhooks/rat-stack/blob/a3f5a14861ce89913e82bea0f7ba02c83e8d4725/apps/cli/src/cli.ts)
   GitHub joelhooks/rat-stack. The CLI provides FileInspector.layer and NodeServices.layer before it runs. Accessed 2026-11-08.

5. [Inspection machine tests](https://github.com/joelhooks/rat-stack/blob/a3f5a14861ce89913e82bea0f7ba02c83e8d4725/packages/core/test/inspect-machine.test.ts)
   GitHub joelhooks/rat-stack. The tests supply the same requirement through their own TestLayer. Accessed 2026-11-08.

## Lore on this page

- [Sam Goodwin](/lore/sam-goodwin)
- [Michael Arnaldi](/lore/michael-arnaldi)

## Linked from

- Agent guide → An Effect stack so pure (aspirational) Kit Langton will blush. → [Read page](https://ratstack.sh/llms.txt)

- Change log → What changed in the files served here, newest first. → [Read page](https://ratstack.sh/log)

- Dependency injection is the reason to choose Effect → Effect tracks service requirements in types and supplies replaceable implementations through Layers. → [Read page](https://ratstack.sh/lore/dependency-injection-is-the-reason-to-choose-effect)

- Effect basics → An Effect describes work, expected failures, and required services before a runtime executes it. → [Read page](https://ratstack.sh/lore/effect-basics)

- Full agent guide → An Effect stack so pure (aspirational) Kit Langton will blush. → [Read page](https://ratstack.sh/llms-full.txt)

- Infrastructure as effects → Sam Goodwin relates application operations to infrastructure requirements in one typed program. → [Read page](https://ratstack.sh/lore/infrastructure-as-effects)

- Learn rat-stack from your own agent → Turn on learn mode: your own agent explains rat-stack ideas during real work and keeps progress local. → [Read page](https://ratstack.sh/learn)

- Rat Stack lore | rat-stack → Short, source-grounded notes on the ideas and decisions behind rat-stack. → [Read page](https://ratstack.sh/lore)

- Source change history (log.md) → The generated change log as Markdown. → [Read page](https://ratstack.sh/log.md)

## Unlinked mentions

- [A service captures its construction dependencies](https://ratstack.sh/lore/services-capture-dependencies) → A context holds supplied service implementations.¶

- [add-a-capability](https://ratstack.sh/skills/add-a-capability) → MCP (Model Context Protocol) adds a doThing tool with the same schemas and flags.¶

- [Agent rules for rat-stack (AGENTS.md)](https://ratstack.sh/AGENTS.md) → Effect Schema, Context.Service, CLI: .agent\_sources/github.com/Effect-TS/effect/

- [Code snippets quote a pinned source](https://ratstack.sh/lore/code-snippets) → This preserves the preceding source context for multiline comments and strings.¶

- [Dependency injection is the reason to choose Effect](https://ratstack.sh/lore/dependency-injection-is-the-reason-to-choose-effect) → Shared Layer identity reuses construction within the same memoization context.¶

- [Devtools](https://ratstack.sh/systems/devtools) → MCP means Model Context Protocol, which lets an agent discover and call tools.¶

- [Effect + Alchemy peer patterns](https://ratstack.sh/resources/same-version-repos) → The guidance makes app, product-package, and vendor-neutral-library ownership explicit; it also says services capture implementation dependencies and keep request context invocation-scoped.

- [Effect 4 study: September 2026](https://ratstack.sh/resources/effect-4-reference-projects) → Two things learned on the way: the machine context must be declared via types\<Ctx>() or schemas.context, otherwise createMachine’s function-form context falls back to MachineContext and the output type collapses to any; and ErrorFrom of a machine is unknown, so join needs orDie (or an explicit catch) to keep a typed…

- [Effect basics](https://ratstack.sh/lore/effect-basics) → A context holds supplied service implementations.¶

- [Effect Meetup SF 2023: Why Effect?](https://ratstack.sh/lore/effect-meetup-sf-2023-why-effect-michael-arnaldi) → A Remix demo contrasts manually added logs, metrics, and traces and nested error handling with Effect context, Schema, spans, metrics, and retry policies.

- [gardener](https://ratstack.sh/skills/gardener) → json, and turn useful unlinked mentions into explicit source links after checking their context; leave incidental matches alone.¶

- [Handle expected failures without hiding defects](https://ratstack.sh/lore/error-model) → Its tag identifies the error type; its fields retain context.

- [Happy Path 116: Infrastructure as effects](https://ratstack.sh/lore/happy-path-116-infrastructure-as-effects-sam-goodwin) → The program carries resource requirements in its context.

- [Hosted agent interfaces](https://ratstack.sh/systems/agent-front-door) → Those values can belong to the first request’s runtime context.

- [Interest signup](https://ratstack.sh/systems/interest) → MCP means Model Context Protocol, which lets an agent discover and call tools.¶

- [Layer composition makes dependencies explicit](https://ratstack.sh/lore/layers-make-dependencies-explicit) → Sharing follows Layer identity within a build context that remembers which Layer values it has already constructed.

- [learn](https://ratstack.sh/skills/learn) → Omit context to follow the ordered learning path.

- [Learn mode presents concepts at useful depths](https://ratstack.sh/systems/learn) → Selection follows deck order when context is absent.

- [Lint and type escape ledger (debt.md)](https://ratstack.sh/debt.md) → Reason: projection boundary erases the hook requirements; the group layer’s context holds them.

- [MCP is another surface](https://ratstack.sh/lore/mcp-is-another-surface) → The Model Context Protocol lets an agent client discover and call tools.

- [Production-grade TypeScript](https://ratstack.sh/lore/production-grade-typescript) → He demonstrates Effect context, Schema, spans, metrics, and retry policies in a Remix application.

- [Purpose and boundaries of rat-stack (VISION.md)](https://ratstack.sh/VISION.md) → Context.

- [Run Effect at the integration boundary](https://ratstack.sh/lore/run-effect-at-the-boundary) → Later calls reuse the built service context.

- [Sam Goodwin](https://ratstack.sh/lore/sam-goodwin) → Its infrastructure context is the cloud environment and dependencies in which it runs.

- [Schema projections: 2026-09-18 history](https://ratstack.sh/resources/schema-projections-and-code-mode) → Tool annotations already exist as Context references: Tool.Readonly, Tool.Destructive, Tool.Idempotent, Tool.OpenWorld.

- [security-audit](https://ratstack.sh/skills/security-audit) → ts runs local programs in a child process with a VM context and a host-call bridge.

- [Structure an Effect codebase by domain](https://ratstack.sh/lore/structure-effect-by-domain) → Declare expected failures with useful context.

- [Trace operations where they mean something](https://ratstack.sh/lore/trace-meaningful-operations) → Add only context safe for that operation’s telemetry.¶

- [write-a-wiki-page](https://ratstack.sh/skills/write-a-wiki-page) → The remaining context describes the requested source.¶
