Direct answer
TypeScript project references model which composite projects depend on which other composite projects, and they connect a source project to the declaration output its consumers read. A reference is a boundary statement: the consumer compiles against the referenced project’s .d.ts output, not against its source. Changing build order, moving a file between projects, or editing an emitted declaration are three different kinds of change, and treating them as one is how build graphs rot. The concrete win is a build order you can predict from the reference graph instead of from memory. The concrete loss is that a declaration being emitted is not proof the emitted API is correct or that a bundler will agree with it.
Map the references, the composite settings, the declaration paths, and the build order before moving source between projects. An edit made against one tsconfig line, judged without the graph, is the change that breaks a downstream project two weeks later.
Read the graph from the repository itself
A reference graph you keep in your head goes stale the first time someone adds a project. Reading it from the repository is cheaper, and it is the first step of any boundary review.
git grep -n "references" -- "*/tsconfig.json"
# every edge declaration in the repository
git grep -n "composite" -- "*/tsconfig.json"
# every project that claims to be referencableTwo greps produce a complete edge list and a complete list of referencable projects. Comparing them is the check that catches the common mistake: a reference pointing at a directory whose tsconfig never declared composite. That mismatch produces a build failure that reads like a missing module, and the cause is a graph error rather than a path error.
The edge list also exposes asymmetry. A project that is referenced by three consumers and references none is a leaf with wide responsibility. A project that references four others and is referenced by none is a top-level assembly. Neither shape is wrong, but each carries a different review burden when a type moves.
| Graph shape | Review burden | Typical risk |
|---|---|---|
| Leaf, widely referenced | High, many consumers read its declarations | A type move breaks several builds |
| Mid, references and referenced | Medium, both directions to check | A cycle appears after an edge is added |
| Top-level assembly, references many | Low for consumers, high for build time | Build order widens for everyone |
Read the table as a triage aid. Changes in leaves deserve the most care because the blast radius is widest, and the graph is the only way to know which projects are leaves without asking someone.
Why a guessed build order costs a team
Project references fail quietly at first. A build passes, then a downstream project sees a type that no longer exists, and the fix looks like a declaration tweak. Three costs follow from reasoning about one project at a time.
Review time goes into arguing about a build command that was never the cause. Runtime risk goes up when an emitted declaration drifts from the source it describes, because consumers compile against the declaration and run against the source. Rollback risk goes up when nobody can say which project owns a type, so reverting one boundary reverts three.
Reading the graph first is cheaper than repairing it later. A reference answers who consumes whom, and composite answers who is allowed to be consumed. Neither requires a build to interpret. The TypeScript project references handbook is the official reference for the model, and this post stays on the graph rather than on general TypeScript setup.
Why Project References Exist
A single tsconfig for a large repository produces one giant program. Compilation gets slower, incremental rebuilds get coarser, and ownership gets blurry because every file is in the same graph. Project references split the program into smaller composite projects with explicit edges between them.
Three problems the model addresses are worth naming before touching a tsconfig.
| Problem | What references change | What stays unchanged |
|---|---|---|
| One monolithic program | Program splits into composite projects with declared edges | Module resolution rules inside a project |
| Coarse incremental rebuilds | Downstream builds read declaration output | Whether a bundler honors the split |
| Unclear ownership | Each project owns its own source and output | Runtime behavior of the compiled code |
The split is a build and ownership tool. The split is not a bundler replacement, and it does not decide what ships to a browser or a Node process. The handbook documents references as dependencies between composite projects. What the model does not promise is that every bundler workflow becomes unnecessary, and this post does not claim that.
Read tsconfig References
A reference lives in the references array of a consumer’s tsconfig, and each entry points at a directory whose tsconfig declares composite: true. The whole edge is that one array entry. Reading a repository’s graph means collecting these arrays and drawing the arrows.
{
"compilerOptions": {
"composite": true,
"declaration": true,
"outDir": "./dist"
},
"references": [
{ "path": "../shared" },
{ "path": "../core" }
]
}The consumer declares which projects it reads from. The referenced project declares that it is consumable through composite. Both halves have to be present for the edge to mean anything, and the tsc --build command uses the graph to decide order.
A reading table helps when a repository has more than a few projects.
| tsconfig location | references entries |
Reads declaration output from |
|---|---|---|
packages/app |
../core, ../shared |
core and shared declaration files |
packages/core |
../shared |
shared declaration files |
packages/shared |
none | nothing, it is a leaf |
The leaf is the useful anchor. Projects with no references are the ones whose declaration output is most likely to be consumed widely, which makes them the highest-risk place to move a type without a graph check.
Understand Composite Projects
composite: true marks a project as referencable and carries requirements. Declaration emit is part of that contract, because a consumer reads the referenced project’s declarations rather than recompiling its source. The TSConfig reference for composite and the one for declaration are the official references for both settings.
| Setting | What it does | Why references need it |
|---|---|---|
composite: true |
Marks the project referencable and enables incremental build information | A consumer needs a stable, declared boundary |
declaration: true |
Emits .d.ts files alongside JavaScript output |
Consumers compile against declarations, not source |
declarationMap |
Emits .d.ts.map for editor navigation |
Optional, improves navigation into referenced source |
outDir |
Names where output and declarations land | Consumers and build tools need a predictable path |
The composite contract is what makes the edge cheap. A downstream project does not recompile the referenced project to type-check; it reads the emitted declarations. The trap lives here too: the declaration is a projection of the source, and a stale or hand-edited declaration is a lie the compiler will happily believe.
Map Declaration Ownership
Every composite project owns its source and its emitted declarations. Consumers own nothing about the declarations they read. That ownership rule is the review unit for any change that moves code between projects.
| Artifact | Owner | Consumer may |
|---|---|---|
Source .ts files |
The project that declares them | Import through the boundary the project exposes |
Emitted .d.ts files |
The project that emits them | Read them at compile time |
| Emitted JavaScript | The project that emits it | Bundle or run it according to the build pipeline |
| Declaration maps | The project that emits them | Use them for navigation |
Official, F045: The TypeScript handbook describes project references as modeling dependencies between composite projects and connecting source projects to the declaration output consumed by referenced projects. The URL was fetched during research, but content extraction returned page assets rather than handbook text, so the exact passage behind this paragraph should be rechecked against the current handbook before relying on a fine detail.
Derived, F046: Mapping references, composite settings, declaration paths, and build order before moving source between projects is an editorial review method built on the official model. The TSConfig pages were not fetched in this pass, so the method is a recommendation, not a TypeScript requirement.
Never edit an emitted .d.ts as the fix for a type problem. The declaration is a build output. The fix belongs in the source that produces it, and an emitted-file edit is overwritten on the next build. This is the same discipline the OpenAPI generator customization guide applies to generated clients: change the input, not the output.
Trace Build Order
tsc --build walks the reference graph and builds referenced projects before the projects that reference them. That is the mechanism. A cycle is a hard failure because the order cannot be computed, and a missing edge is a silent ordering assumption that may or may not work depending on what else forced a build.
npx tsc --build
# builds in dependency order according to the references
npx tsc --build --dry
# reports what would build without writing outputThe graph, not memory, decides the order. A build-order result that is not derived from the declared references is a guess, and the guardrail for this topic is explicit: do not invent a build-order result without the project graph. The table below is the shape of a useful trace.
| Project | References | Build position | Reason |
|---|---|---|---|
shared |
none | first | leaf, nothing to build before it |
core |
shared |
after shared |
consumes shared declarations |
app |
core, shared |
last | consumes both |
A reference added for convenience, without a real compile-time dependency, widens the build for every consumer of the graph. The Cargo workspace inheritance guide makes the same point for Rust: centralizing metadata is useful only when the relationships stay visible, and an edge that exists for tidiness is still an edge the build has to honor.
Review Source Mappings
Moving a file between projects is the change that looks local and lands widely. The file’s new project owns its declarations, and every consumer that used to read the old project’s declaration now needs an edge to the new one, or the type disappears from its view.
git grep -n "from '\.\./shared/" packages/core/src
# find imports that cross the boundary you are about to moveThe review question is who reads the moved type. A type exported from a leaf project and consumed by three projects is a public boundary. Moving it into one consumer removes it from the other two, and the compiler error will show up in their builds, not in the project you edited.
| Move | Boundary effect | Review action |
|---|---|---|
| File within one project | None if internal | Confirm it was not part of the public surface |
| File from leaf to consumer | Leaf declaration loses the type | Add an edge or keep the type in the leaf |
| Type re-exported from a new project | New project owns the declaration | Confirm consumers reference the new project |
| Declaration path changed | Consumers may need output path updates | Rebuild and check the emitted declaration path |
A source mapping change is a boundary decision, and the Go workspace boundaries guide applies the same rule to Go: decide what belongs inside a boundary before moving code across it, because local convenience and published contract are different things.
Change One Boundary at a Time
The reference graph is reviewable when each change touches one edge or one project’s settings. Bundling a boundary move with a declaration setting change and a build-order fix produces a diff nobody can attribute.
npx tsc --build --dry
# before the change
# make one boundary edit here
npx tsc --build --dry
# after the changeThe pass condition is concrete. The dry build succeeds, the build order matches the intended graph, and every downstream project that reads the changed boundary still type-checks. The Claude Code best practices favor this kind of before-and-after check, and the common workflows cover iterating an edit against a command.
| Change type | Pass condition | If it fails |
|---|---|---|
| Add a reference | Dry build succeeds and order matches intent | Check for a cycle |
| Remove a reference | No consumer misses the removed declarations | Re-add or move the type back |
| Change declaration settings | Emitted declarations land where consumers expect | Update consumer paths |
| Move source between projects | Every affected consumer type-checks | Rebuild the ownership map first |
One boundary per change is also the cheapest way to use an agent. The Claude Code parallel agents guide covers isolating concurrent work, and boundary changes are the kind of edit where two agents in one graph fight over build order.
Declaration files as a published surface
A declaration file is the TypeScript equivalent of a published API surface. Consumers never see the source of a referenced project at compile time; they see the .d.ts. That makes the declaration the thing to review when a boundary changes, and it makes declaration drift the failure mode worth watching.
Drift has two common causes. The first is a stale build, where a source change landed and the declaration was never regenerated, so consumers compile against an API the source no longer has. The second is a hand edit, where someone fixed a type error by changing the emitted file directly. Both produce a declaration that lies, and the compiler will happily propagate the lie to every consumer.
The check is cheap. Rebuild the referenced project and confirm the emitted declaration matches the source. A diff in the declaration after a clean rebuild means the checked-in output was stale or edited.
npx tsc --build --force packages/shared
# rebuild the referenced project from source
git diff -- packages/shared/dist
# any diff here means the committed declarations were stale or hand-editedRead a diff in the emitted output as a finding, not as a fix. The finding is that the declaration and the source disagreed, and the fix belongs in whichever one was wrong. This is the same reasoning the generated-client guides in this batch apply: an emitted artifact that disagrees with its input is a defect in the pipeline, not a file to patch. Treating declarations as a published surface is also what makes the ownership table earlier in this post more than a diagram. Each row is a surface someone depends on, and the rebuild check is how you confirm the surface is honest before a consumer builds against it.
Project reference review table
A review artifact worth keeping is a one-page map of the graph with the composite and declaration settings beside each project. The map turns a future boundary question into a lookup.
| Project | composite |
declaration |
Declaration output | Consumers |
|---|---|---|---|---|
shared |
true | true | dist/*.d.ts |
core, app |
core |
true | true | dist/*.d.ts |
app |
app |
false | false | none | none |
Use the table as contract inventory. Each row is a promise the project makes to its consumers. The rows where composite is false are the rows that cannot be referenced, which is worth confirming before someone adds an edge to them and gets a confusing failure.
The same ownership discipline shows up in other ecosystems in this batch. C# Source Generators covers reviewing generated contracts rather than treating compiler output as proof, and Conan CMakeDeps covers keeping consumer-facing targets stable while the producing side changes.
The concrete win, loss, and implication
The concrete win is a build order you can read from the graph. When tsc --build succeeds, the order it used is written down in the references arrays, and the question “why does this project build first” becomes a lookup rather than a memory test.
The concrete loss is that a declaration is a projection, not a guarantee. Declaration emit produces a .d.ts that describes the source at the moment it was compiled. Declaration emit does not certify runtime behavior, does not guarantee that a bundler will resolve the same way, and a stale declaration can describe an API the source no longer has.
The practical implication is that references are an ownership graph, not a build configuration detail. Teams that review boundary changes against the graph spend less time repairing downstream projects. Teams that judge a boundary change from one tsconfig line keep rediscovering the ownership rule the hard way.
Working with Claude Code on a boundary change
Give the agent three inputs: the boundary you want to change, the commands it may run, and the definition of done. Read-only investigation first. Ask for the reference graph, the composite and declaration settings of each affected project, and the build order a dry run would use. Edits come after the graph is read.
npx tsc --build --dry
# ask for this before any tsconfig edit
git grep -n "references" -- "*/tsconfig.json"
# ask for the raw edge list nextReview the agent’s ownership claim against the graph. The agent can read the references accurately and still propose moving a type into the consumer that asked for it, because that is the shortest path to a green build locally. Deciding who owns a type is an architecture decision, and the reviewer owns it. The Claude Code verification guide covers the questions to ask before accepting the change.
A boundary change that touches many tsconfigs at once deserves a pause. The Claude Code monorepo search guide covers keeping investigation cheap in a large repository, and a wide boundary edit is the pattern the Claude Code overengineering guide warns about.
Checklist before you change a boundary
| Check | Pass condition | If it fails |
|---|---|---|
| Reference graph mapped | Every edge is listed with direction | Collect references arrays first |
| Composite settings confirmed | Referenced projects declare composite: true |
Read the TSConfig composite reference |
| Declaration paths recorded | Output locations written down per project | Read the declaration reference |
| Build order traced | Order derived from the graph, not memory | Run tsc --build --dry |
| Consumers identified | Every consumer of the boundary is named | Search imports across projects |
| One boundary per change | The diff touches one edge or one setting | Split the change |
| Emitted files untouched | No .d.ts edited by hand |
Fix the source instead |
| Dry build passes | Before-and-after dry runs succeed | Do not merge on a green local build alone |
Data gap and future update
The project references handbook URL was fetched, but content extraction returned page assets rather than handbook text, so F045 carries an explicit passage-recheck caveat. The TSConfig pages for composite and declaration were not fetched in this pass, so F046 is derived from the official model rather than quoted from those pages.
No build-time measurement, incremental-rebuild number, or bundler-compatibility result is reported here, because none was measured. A future update quantifying how a reference split affects incremental rebuild time for a specific repository would need a fixed toolchain and a measured pass. No such data was collected.
Bundler behavior with referenced projects is also out of scope. Whether a specific bundler resolves declarations and emitted JavaScript the way tsc --build does is a property of that bundler, and this post does not generalize from the compiler model to any bundler’s implementation.
Related reading on build and dependency boundaries
Build graphs and boundaries appear across this batch. Go Module Compatibility covers keeping exported API changes inside an import compatibility contract, the same ownership discipline applied to Go modules. Cargo Feature Unification covers feature activation across a selected package set, and Cargo Build Scripts covers generated-artifact contracts, which is where a boundary change can alter what a build emits.
Version and variant selection in the JVM world appear in Gradle Constraints vs Dependencies, Gradle Capability Conflicts, and Gradle Variant Attributes. Maven Optional Dependencies covers keeping transitive expectations explicit.
Generated-code boundaries are covered in OpenAPI Generator Customization, GraphQL Code Generator Client Presets, Protocol Buffer Reserved Fields, and sqlc Query Annotations. Framework maintenance appears in Django Deprecation Runway, Rails Upgrade Sequence, and Angular Update Guide.
More from this batch
- pnpm Peer Diagnostics: Read Resolution Reports Before Claude Code Pins
- OpenAPI Generator Customization: Keep Templates and Config in Sync
- GraphQL Code Generator Client Presets: Review Generated Boundaries
- Protocol Buffer Reserved Fields: A Claude Code Wire Compatibility Guide
- sqlc Query Annotations: Align SQL and Generated Types With Claude Code
- Django Deprecation Runway: Plan Framework Maintenance With Claude Code
- Rails Upgrade Sequence: Order Major Changes With Claude Code
- Angular Update Guide: Build a Migration Plan With Claude Code
- Cargo Workspace Inheritance: Centralize Metadata Without Hiding Crates
- CMake Presets: Give Claude Code Reproducible Configure Inputs
One AI API Key option for OpenAI-format agents
Claude Code uses an Anthropic-format route, so the One AI free model IDs are not a Claude Code model source. The packet records Claude IDs as unavailable on 2026-11-27.
OpenAI-format agents have a separate route: One AI API Key offers https://api.oneaiapikey.com/v1, one key, and 46 live free IDs. Free IDs are a different client and request format, not a workaround for Claude Code authentication. Check the free model list before choosing an agent route, or read the quickstart for the request shape.
FAQ
Do project references replace a bundler?
No. References are a compiler-level boundary model. They decide build order and which declarations a consumer reads. What ships to a browser or a Node process is decided by the bundler and the build pipeline, and this post does not claim references replace every bundler workflow.
Can I fix a type error by editing the emitted declaration?
No. The .d.ts is a build output produced from source. Editing it is overwritten on the next build, and a hand-edited declaration can describe an API the source no longer has. Fix the source that produces the declaration.
How do I know the build order without running a build?
Read the references arrays and draw the graph. tsc --build --dry reports what would build without writing output, and that report is derived from the declared edges. A build order that is not derived from the graph is a guess.
Does declaration emit prove the emitted API is correct?
No. Declaration emit produces a projection of the source at compile time. Whether that API is correct for consumers is a separate question that needs review and, where it matters, a test against the consumer’s usage. This post treats emitted output and verified behavior as different claims.
What proves a boundary change is complete?
Three conditions. A dry build succeeds before and after, the build order matches the intended graph, and every downstream project that reads the changed boundary still type-checks. A build of just the edited project is not enough, because a boundary change can break a consumer two projects away.
More Claude Code troubleshooting
- Python Dependency Groups vs Extras: A Claude Code Migration Map
- Python Protocols vs ABCs: Preserve Interface Contracts With Claude Code
- Python TypedDict Boundaries: Stop Model Drift With Claude Code
- Python Stub Drift: Audit Third-Party Types With Claude Code
- Go Module Graph Pruning: Explain Indirect Dependencies With Claude Code
- Cargo Profile Boundaries: Keep Debug and Release Behavior Aligned
- NuGet Central Package Management: Plan a Cross-Project Migration
- .NET Multi-Targeting: Separate Framework Dependencies for Claude Code
- CMake find_package vs FetchContent: Choose a Dependency Boundary
Sources
- Official: TypeScript Handbook: Project References, describing references as dependencies between composite projects and declaration output used by consumers (F045). Passage recheck noted.
- Official: TypeScript TSConfig: composite, reference for the composite setting that marks a project referencable (F046 context).
- Official: TypeScript TSConfig: declaration, reference for declaration emit that produces the
.d.tsconsumers read. - Official: TypeScript Handbook: Modules Reference, reference for module resolution inside a project.
- Official: Claude Code Docs: Best Practices, supporting the before-and-after check loop used as verification.
- Official: Claude Code Docs: Common Workflows, reference for iterating an edit against a command.