Opencode TypeScript
Code like the opencode core team. This skill contains real code extracted from the repo — complete implementations, not abstract rules. Follow the workflow below based on your task.
Implement (new code)
Follow these phases in order:
1. Orient — where does this go?
Load architecture.md. Find:
- Which module owns this behavior
- What the dependency direction allows
- What file naming convention to follow
- Whether this is a new module or an addition to an existing one
2. Gather — what already exists?
Load helpers-deep-dive.md. Before writing ANY utility:
- Check if it already exists in
util/, effect/, bus/, sync/
- Check the usage matrix to see how other modules use it
- If it exists, use it. If it doesn't, inline first — extract only when awkwardness repeats.
For quick lookups: primitives.md (shorter, import paths + signatures only)
3. Build — write the code
Load the reference that matches what you're building:
| Building... |
Load this |
| Service module (namespace + Effect service + schemas + events) |
service-module.md |
| Tool or modifying tool behavior |
tool-module.md |
| Database tables, schemas, events, error types |
schemas-and-state.md |
| Server routes, config, plugins, project lifecycle |
server-and-routes.md |
| Tests |
test-writing.md |
4. CHECK GATE — code MUST pass all of these before proceeding
Load style-dna.md. If ANY of the following fail, fix the code before proceeding to Review:
DO NOT proceed if any check fails. Go back to phase 3 and fix.
5. REVIEW GATE — REJECT the diff if any of these apply
Load review-voice.md. The diff MUST NOT contain any of the following. If it does, fix before submitting:
Refactor (changing existing code)
1. Orient — what touches what?
Load architecture.md. Map the blast radius before changing anything.
2. Study — which pattern applies here?
Load refactoring-patterns.md. Start with the Decision Matrix at the top — match the code smell you see to the correct pattern. Then read the specific pattern section for real before/after diffs:
- Simplification patterns (removing unnecessary abstraction)
- Consolidation patterns (Bun → Node migration)
- Extraction patterns (pulling reusable utilities)
- Migration patterns (moving to Effect services)
- Deletion patterns (removing dead code)
- Stabilization patterns (fixing ordering/race conditions)
- Variant elimination (removing special cases)
3. Gather — can an existing utility replace this code?
Load helpers-deep-dive.md. The best refactor often replaces 20 lines with one utility call.
4. Check + Review
Same as implement phases 4-5: style-dna.md then review-voice.md.
Key decisions (always apply)
- Effect is mandatory — all services use
Context.Service / Layer / makeRuntime. No plain async classes.
- One module, one self-barrel — write flat top-level exports (schemas,
Interface, Service, layer, defaultLayer), then close the file with export * as X from ".". Consumers still write import { X } from "@/x" → X.Service; the barrel is the namespace. opencode dropped in-file export namespace X {}.
- Effect Schema everywhere —
Schema.Struct + Schema.Schema.Type<typeof X> for DTOs, events, and tool params; .annotate({ identifier }) on boundary schemas, .annotate({ description }) on fields. Schema.TaggedErrorClass for Effect errors. Newtype<Self>()("Name", Schema.String.check(...)) (from @opencode-ai/core/schema) for branded IDs. Zod is no longer the boundary tool.
- Event-sourced writes — mutations go through
SyncEvent.run → projectors → SQLite. Direct DB writes only for non-event-sourced features.
- No mocks in tests — use
tmpdir + Instance.provide + real services. Mocks only for external SDKs.
- Single-word variables —
state, pending, info, row, cfg, tx. Multi-word only when genuinely ambiguous.
Reference index
| File |
Size |
What it contains |
| style-dna.md |
18K |
Mandatory style rules, naming, control flow, 14 review traps |
| primitives.md |
22K |
Quick-lookup: every utility with import path + signature |
| helpers-deep-dive.md |
~40K |
Full deep-dive: every utility, every usage site, when NOT to use |
| architecture.md |
~30K |
Module map, dependency graph, data flow, file conventions |
| service-module.md |
27K |
Complete Question + Permission implementations |
| tool-module.md |
28K |
Full tool implementations, registry, prompt loop |
| test-writing.md |
42K |
5 complete test files with all fixture patterns |
| schemas-and-state.md |
36K |
SQL tables, Effect Schema (Struct/annotate/Newtype), SyncEvent flow, errors |
| server-and-routes.md |
32K |
Routes, config, plugins, project lifecycle |
| review-voice.md |
~25K |
Real PR review comments from Dax + Aiden |
| refactoring-patterns.md |
~25K |
Real before/after diffs from cleanup commits |
1---2name: opencode-ts3description: Write and refactor TypeScript code in repos that use Effect-TS services, Effect Schema, event-sourced persistence, and barrel-module architecture. Use this skill when implementing features, fixing bugs, writing tests, or refactoring in opencode or any TypeScript codebase built on the same stack (Effect DI via Context.Service, Drizzle ORM, Hono routes, Bun runtime). Triggers on tasks involving Effect services, Context.Service / Layer modules, Effect Schema definitions, SyncEvent patterns, tool implementations, test writing, or code review in Effect-based TypeScript projects.4---5
6# Opencode TypeScript
7
8Code like the opencode core team. This skill contains real code extracted from the repo — complete implementations, not abstract rules. Follow the workflow below based on your task.
9
10---
11
12## Implement (new code)
13
14Follow these phases in order:
15
16### 1. Orient — where does this go?
17
18Load [architecture.md](references/architecture.md). Find:
19- Which module owns this behavior
20- What the dependency direction allows
21- What file naming convention to follow
22- Whether this is a new module or an addition to an existing one
23
24### 2. Gather — what already exists?
25
26Load [helpers-deep-dive.md](references/helpers-deep-dive.md). Before writing ANY utility:
27- Check if it already exists in `util/`, `effect/`, `bus/`, `sync/`
28- Check the usage matrix to see how other modules use it
29- If it exists, use it. If it doesn't, inline first — extract only when awkwardness repeats.
30
31For quick lookups: [primitives.md](references/primitives.md) (shorter, import paths + signatures only)
32
33### 3. Build — write the code
34
35Load the reference that matches what you're building:
36
37| Building... | Load this |
38|---|---|
39| Service module (namespace + Effect service + schemas + events) | [service-module.md](references/service-module.md) |
40| Tool or modifying tool behavior | [tool-module.md](references/tool-module.md) |
41| Database tables, schemas, events, error types | [schemas-and-state.md](references/schemas-and-state.md) |
42| Server routes, config, plugins, project lifecycle | [server-and-routes.md](references/server-and-routes.md) |
43| Tests | [test-writing.md](references/test-writing.md) |
44
45### 4. CHECK GATE — code MUST pass all of these before proceeding
46
47Load [style-dna.md](references/style-dna.md). **If ANY of the following fail, fix the code before proceeding to Review:**
48
49- [ ] Single-word variable names where clear
50- [ ] No `try`/`catch`, no `else`, no `any`, no unnecessary destructuring
51- [ ] `const` + ternary over `let` + mutation
52- [ ] snake_case Drizzle fields, `.annotate({ identifier })` on boundary schemas, `.annotate({ description })` on fields
53- [ ] Effect Schema (`Schema.Struct`/`Schema.Schema.Type`) for DTOs, events, tool params — not Zod
54- [ ] Effect is used for services, not plain async classes
55- [ ] Module ends with `export * as X from "."` — no in-file `export namespace X {}`
56- [ ] No patterns from Section 7 ("Things That Compile But Get Rejected") present in the diff
57
58**DO NOT proceed if any check fails.** Go back to phase 3 and fix.
59
60### 5. REVIEW GATE — REJECT the diff if any of these apply
61
62Load [review-voice.md](references/review-voice.md). **The diff MUST NOT contain any of the following. If it does, fix before submitting:**
63
64- [ ] Changes to files outside the scope of the task
65- [ ] `as any` or `as unknown as` casts
66- [ ] Custom utilities that duplicate community primitives or `@/util/*` helpers
67- [ ] Provider-specific code that should live in models.dev
68- [ ] Code removal without a clear reason documented in the commit
69- [ ] Unexplained variable renames or structural changes
70- [ ] Abstraction the core team would ask to remove (check refactoring-patterns.md)
71
72---
73
74## Refactor (changing existing code)
75
76### 1. Orient — what touches what?
77
78Load [architecture.md](references/architecture.md). Map the blast radius before changing anything.
79
80### 2. Study — which pattern applies here?
81
82Load [refactoring-patterns.md](references/refactoring-patterns.md). **Start with the Decision Matrix at the top** — match the code smell you see to the correct pattern. Then read the specific pattern section for real before/after diffs:
83- Simplification patterns (removing unnecessary abstraction)
84- Consolidation patterns (Bun → Node migration)
85- Extraction patterns (pulling reusable utilities)
86- Migration patterns (moving to Effect services)
87- Deletion patterns (removing dead code)
88- Stabilization patterns (fixing ordering/race conditions)
89- Variant elimination (removing special cases)
90
91### 3. Gather — can an existing utility replace this code?
92
93Load [helpers-deep-dive.md](references/helpers-deep-dive.md). The best refactor often replaces 20 lines with one utility call.
94
95### 4. Check + Review
96
97Same as implement phases 4-5: [style-dna.md](references/style-dna.md) then [review-voice.md](references/review-voice.md).
98
99---
100
101## Key decisions (always apply)
102
103- **Effect is mandatory** — all services use `Context.Service` / `Layer` / `makeRuntime`. No plain async classes.
104- **One module, one self-barrel** — write flat top-level exports (schemas, `Interface`, `Service`, `layer`, `defaultLayer`), then close the file with `export * as X from "."`. Consumers still write `import { X } from "@/x"` → `X.Service`; the barrel *is* the namespace. opencode dropped in-file `export namespace X {}`.
105- **Effect Schema everywhere** — `Schema.Struct` + `Schema.Schema.Type<typeof X>` for DTOs, events, and tool params; `.annotate({ identifier })` on boundary schemas, `.annotate({ description })` on fields. `Schema.TaggedErrorClass` for Effect errors. `Newtype<Self>()("Name", Schema.String.check(...))` (from `@opencode-ai/core/schema`) for branded IDs. Zod is no longer the boundary tool.
106- **Event-sourced writes** — mutations go through `SyncEvent.run` → projectors → SQLite. Direct DB writes only for non-event-sourced features.
107- **No mocks in tests** — use `tmpdir` + `Instance.provide` + real services. Mocks only for external SDKs.
108- **Single-word variables** — `state`, `pending`, `info`, `row`, `cfg`, `tx`. Multi-word only when genuinely ambiguous.
109
110---
111
112## Reference index
113
114| File | Size | What it contains |
115|------|------|-----------------|
116| [style-dna.md](references/style-dna.md) | 18K | Mandatory style rules, naming, control flow, 14 review traps |
117| [primitives.md](references/primitives.md) | 22K | Quick-lookup: every utility with import path + signature |
118| [helpers-deep-dive.md](references/helpers-deep-dive.md) | ~40K | Full deep-dive: every utility, every usage site, when NOT to use |
119| [architecture.md](references/architecture.md) | ~30K | Module map, dependency graph, data flow, file conventions |
120| [service-module.md](references/service-module.md) | 27K | Complete Question + Permission implementations |
121| [tool-module.md](references/tool-module.md) | 28K | Full tool implementations, registry, prompt loop |
122| [test-writing.md](references/test-writing.md) | 42K | 5 complete test files with all fixture patterns |
123| [schemas-and-state.md](references/schemas-and-state.md) | 36K | SQL tables, Effect Schema (Struct/annotate/Newtype), SyncEvent flow, errors |
124| [server-and-routes.md](references/server-and-routes.md) | 32K | Routes, config, plugins, project lifecycle |
125| [review-voice.md](references/review-voice.md) | ~25K | Real PR review comments from Dax + Aiden |
126| [refactoring-patterns.md](references/refactoring-patterns.md) | ~25K | Real before/after diffs from cleanup commits |