
Angular Compiler CLI Reference
FreeUnderstand the architecture of Angular's compiler.
Free · Opens the source repo
What Angular Compiler CLI Reference does
The Angular Compiler CLI (ngtsc) is a specialized tool designed to enhance the TypeScript compilation process for Angular applications. It serves as a wrapper around the standard TypeScript compiler, adding Angular-specific capabilities such as compiling decorators into static properties and performing template type checking. This skill provides a comprehensive overview of the mental model and architecture behind the packages/compiler-cli, making it essential for developers working with Angular's compilation process.
The core architecture of ngtsc is built around a lazy, incremental, and partial compilation pipeline. It utilizes a wrapper pattern through the NgtscProgram, which acts as a drop-in replacement for the standard TypeScript program. This allows for efficient management of Angular-specific compilation tasks, such as analyzing decorated classes and linking dependencies. The system categorizes classes with Angular decorators as "Traits," managing their state through a defined state machine. This approach ensures that analysis and resolution are performed only when necessary, optimizing performance during the compilation process.
Key subsystems within ngtsc include the core orchestration logic, trait compilation, decorator handlers, template type checking, and metadata management. Each subsystem plays a crucial role in ensuring that Angular applications are compiled accurately and efficiently. For instance, the TraitCompiler iterates over source files to identify decorated classes, while the TemplateTypeChecker generates type check blocks that validate template logic. Understanding these components is vital for any developer looking to leverage the full capabilities of Angular's compiler.
This skill is particularly useful for developers who need to work closely with Angular's compilation process, whether for building new features, debugging existing code, or optimizing performance. By familiarizing themselves with the architecture and mental model of ngtsc, developers can enhance their productivity and effectiveness when working with Angular applications.
When to use it
Use this skill when you are planning to work with the Angular Compiler CLI or need to understand its architecture for development purposes.
When not to use it
This skill is not suitable for those who are not working with Angular or do not require in-depth knowledge of the compiler's architecture.
What you can build with it
Building Angular Applications
When developing new features in Angular, understanding the compiler's architecture helps in optimizing code and ensuring proper functionality.
Debugging Compiler Issues
If you encounter issues related to Angular's compilation process, this skill provides the necessary insights to identify and resolve problems effectively.
Learning Angular Internals
For developers interested in the inner workings of Angular, this skill offers a detailed look at how the compiler operates and manages Angular-specific tasks.
How to install Angular Compiler CLI Reference
View source1. Install with the skills CLI
npx skills add angular/angular/reference-compiler-cli --agent claude-code2. Or install it manually
Download the skill folder and drop it into ~/.claude/skills/ for all projects, or .claude/skills/ to scope it to one repo. Restart Claude Code so it picks up the new skill.
Anthropic's agentic coding CLI, and the reference implementation of Agent Skills. Drop a skill folder into ~/.claude/skills and Claude Code loads it automatically whenever a task matches the skill's description. Claude Code docs
Inside SKILL.md
Written by angularAngular Compiler CLI (ngtsc) Architecture
Overview
The packages/compiler-cli package contains the Angular Compiler (Ivy), often referred to as ngtsc. It is a wrapper around the TypeScript compiler (tsc) that extends it with Angular-specific capabilities.
The core goal of ngtsc is to compile Angular decorators (like @Component, @Directive, @Pipe) into static properties on the class (Ivy instructions, e.g., static ɵcmp = ...). It also performs template type checking and ahead-of-time (AOT) compilation.
Mental Model
The compiler is designed as a lazy, incremental, and partial compilation pipeline.
- Wrapper Pattern:
NgtscProgramwraps the standardts.Program. It intercepts calls to act as a drop-in replacement for standard tooling. - Traits System: Every class with an Angular decorator is considered a "Trait". The compiler manages the state of these traits through a state machine:
- Pending: Detected but not processed.
- Analyzed: Metadata extracted, template parsed (but dependencies not yet linked).
- Resolved: Dependencies (directives/pipes in template) resolved, import cycles handled.
- Skipped: Not an Angular class.
- Lazy Analysis: Analysis only happens when necessary (e.g., when diagnostics are requested or emit is prepared).
- Output AST: The compiler generates an intermediate "Output AST" (
o.Expression) for the generated code, which is then translated into TypeScript AST nodes during the emit phase.
Key Subsystems
1. Core Orchestration (ngtsc/core)
NgtscProgram: The public API implementingapi.Program. It manages thets.Programand theNgCompiler.NgCompiler: The brain of the compiler. It orchestrates the compilation phases (Analysis, Resolution, Type Checking, Emit). It holds theTraitCompiler.
2. Trait Compilation (ngtsc/transform)
TraitCompiler: Manages the lifecycle of "Traits". It iterates over source files, identifies decorated classes, and delegates to the appropriateDecoratorHandler.Trait: A state container for a class, holding its handler, analysis results, and resolution results.
3. Decorator Handlers (ngtsc/annotations)
DecoratorHandler: An interface for handling specific decorators.ComponentDecoratorHandler: The most complex handler. It:- Extracts metadata (selector, inputs, outputs).
- Parses the template.
- Resolves used directives and pipes (
R3TargetBinder). - Generates the
ɵcmpinstruction.
DirectiveDecoratorHandler,PipeDecoratorHandler,NgModuleDecoratorHandler: Handle their respective decorators.
4. Template Type Checking (ngtsc/typecheck)
TemplateTypeChecker: Generates "Type Check Blocks" (TCBs). A TCB is a block of TypeScript code that represents the template's logic in a waytsccan understand and check for errors.TypeCheckBlock: The actual generated code that validates bindings, events, and structural directives.
5. Metadata & Scope (ngtsc/metadata, ngtsc/scope)
MetadataReader: Reads Angular metadata from source files (usingLocalMetadataRegistry) and.d.tsfiles (usingDtsMetadataReader).ScopeRegistry: Determines the "compilation scope" of a component (which directives/pipes are available to it), handlingNgModuletransitive exports and Standalone Component imports.
6. Emit & Transformation (ngtsc/transform)
ivyTransformFactory: A TypeScript transformer factory.IvyCompilationVisitor: Visits classes, triggers compilation viaTraitCompiler, and collects the Output AST.IvyTransformationVisitor: Translates the Output AST into TypeScript AST, injects thestatic ɵ...fields, and removes the original decorators.
Compilation Phases
- Construction:
NgtscProgramcreatesNgCompiler, which sets up all registries and theTraitCompiler. - Analysis (
analyzeSync):- The
TraitCompilerscans files. DecoratorHandlers extract metadata and parse templates.- No cross-file resolution happens here (allowing for parallelism and caching).
- The
- Resolution (
resolve):TraitCompilerresolves traits.- Components link their templates to specific Directives and Pipes (found via
ScopeRegistry). - Import cycles are detected and handled (e.g., via "remote scoping").
- Type Checking:
TemplateTypeCheckercreates TCBs for all components.- TypeScript diagnostics are retrieved for these TCBs.
- Emit (
prepareEmit):ivyTransformFactoryis created.- TS
emitis called. - The transformers run, injecting the compiled Ivy instructions into the JS/DTS output.
Important File Locations
packages/compiler-cli/src/ngtsc/program.ts: Entry point (NgtscProgram).packages/compiler-cli/src/ngtsc/core/src/compiler.ts: Core logic (NgCompiler).packages/compiler-cli/src/ngtsc/transform/src/trait.ts: Trait state machine.packages/compiler-cli/src/ngtsc/annotations/component/src/handler.ts: Component compilation logic.packages/compiler-cli/src/ngtsc/typecheck/src/template_type_checker.ts: Type checking logic.packages/compiler-cli/src/ngtsc/transform/src/transform.ts: AST transformation logic.
Frequently asked questions about Angular Compiler CLI Reference
Similar skills
Markdown to HTML Conversion
Efficiently convert Markdown documents to HTML.
Code Tour
Create structured walkthroughs for codebases.
Acquire Codebase Knowledge
Streamline onboarding with comprehensive codebase documentation.
Documentation & Modernization
Streamline codebase documentation and modernization planning.
Azure Resource Visualizer
Generate architecture diagrams for Azure resources.
CLAUDE.md Improver
Optimize your CLAUDE.md files for better project context.
