|
| 1 | +--- |
| 2 | +title: 'Agentic Coding: AI Support for Angular' |
| 3 | +author: Angular-Buch Team |
| 4 | +mail: team@angular-buch.com |
| 5 | +bio: '<a href="https://angular-buch.com"><img src="https://angular-buch.com/assets/img/book-cover-v1m.png" alt="Angular-Buch Cover" style="float: right; margin-top: -60px; margin-right: 30px; max-width: 250px;"></a>This article is an excerpt from the new <b>Angular book</b> (in German language) by Ferdinand Malcher, Danny Koppenhagen and Johannes Hoppe. After four successful editions, we have rewritten the book from scratch – with modern syntax, compact and covering many new topics. The new book will be released in May 2026. More info at <a href="https://angular-buch.com" style="text-decoration: underline;"><b>angular-buch.com</b></a>' |
| 6 | +bioHeading: About the Angular book |
| 7 | +author2: Angular.Schule Team |
| 8 | +mail2: team@angular.schule |
| 9 | +bio2: '<a href="https://angular.schule"><img src="/img/logo-angular-schule-gradient-550.png" alt="Angular.Schule Logo" style="float: right; margin-left: 30px; margin-top: -10px; margin-right: 30px; max-width: 250px;"></a>Want to try AI-powered Angular development hands-on? Join Ferdinand Malcher and Johannes Hoppe in our workshops, where you learn Angular the practical way – including modern AI tools for more efficient development. More at <a href="https://angular.schule" style="text-decoration: underline;"><b>angular.schule</b></a>' |
| 10 | +bio2Heading: About our Angular workshops |
| 11 | +published: 2026-02-11 |
| 12 | +keywords: |
| 13 | + - Angular |
| 14 | + - AI |
| 15 | + - Artificial Intelligence |
| 16 | + - AI Agent |
| 17 | + - AI-Agent |
| 18 | + - MCP |
| 19 | + - Model Context Protocol |
| 20 | + - MCP Server |
| 21 | + - Vibe Coding |
| 22 | + - Agentic Coding |
| 23 | + - LLM |
| 24 | +language: en |
| 25 | +header: header.jpg |
| 26 | +--- |
| 27 | + |
| 28 | +Software projects are becoming more complex, and requirements are increasing. |
| 29 | +AI (Artificial Intelligence) tools can support us in development and provide relief: They help with generating code, explain complex relationships and suggest improvements. |
| 30 | +**In this article, we show you how to generate the best possible code using Angular's AI tools.** |
| 31 | + |
| 32 | +## Contents |
| 33 | + |
| 34 | +[[toc]] |
| 35 | + |
| 36 | +## What are AI Agents? |
| 37 | + |
| 38 | +**Agentic Coding** is the next step after ChatGPT: Forget copy-paste from the browser. AI agents work directly in your project – they read code, write files, run tests and autonomously plan next steps. You set the direction, the agent executes. |
| 39 | + |
| 40 | +AI found its way into everyday life through browser-based chats like ChatGPT, Gemini or Perplexity. But anyone developing software with them quickly hits limitations: The chat doesn't know the project, and code must be manually copied back and forth. AI agents solve this problem. They can essentially do anything we could do on a computer. The agents typically run in a sandbox and ask for confirmation before critical actions. |
| 41 | + |
| 42 | + |
| 43 | + |
| 44 | +Angular provides special support for working with such agents, so that we get optimal results and the generated code follows current best practices. |
| 45 | +Before we go into detail, however, we should discuss why this support is even necessary. |
| 46 | + |
| 47 | +## Challenge: Outdated Knowledge |
| 48 | + |
| 49 | +The technical foundation of all AI agents is an LLM (Large Language Model). |
| 50 | +It is based on training data that was created at a specific point in time. |
| 51 | +Since such training is extremely resource-intensive, it is not performed continuously. |
| 52 | +So there is practically a cutoff date, and even the best models can only "know" what existed up to that date. |
| 53 | + |
| 54 | +This becomes problematic with fast-moving technologies like Angular: New features are added and best practices change. |
| 55 | +Recent innovations like Signal Forms, the Resource API or Angular Aria may not be present in the training data. |
| 56 | +Older concepts like the module system (`NgModule`) or the structural directives (`NgIf` and `NgFor`) are, however, well known to the model. |
| 57 | +Considering also that older concepts have accumulated more documentation, tutorials and code examples over the years, it is statistically more likely that the model will suggest these. |
| 58 | +For maintaining existing legacy projects, this is an advantage. |
| 59 | +But if you aim for a modern application with current best practices, the model is more likely to provide older solutions. |
| 60 | +In the worst case, the model mixes old and new concepts or **hallucinates**, i.e. it generates plausible-sounding but factually incorrect statements. |
| 61 | +The result is inconsistent or non-functional code. |
| 62 | + |
| 63 | +The solution lies in providing the AI agent with the necessary context. |
| 64 | +Angular offers two tools for this: |
| 65 | + |
| 66 | +- **Configuration files** for instructions and examples |
| 67 | +- **MCP server** for Angular-specific information (and tools) |
| 68 | + |
| 69 | +## AI Configuration Files |
| 70 | + |
| 71 | +At the start of their work, AI agents need as much good information as possible. |
| 72 | +This is also referred to as context. |
| 73 | +The vendor has already provided basic rules and instructions, the so-called **System Prompt**. |
| 74 | +But this is usually not enough: The agent has no knowledge yet about the specific project for which it should perform work. |
| 75 | + |
| 76 | +This is where project-specific configuration files come into play. |
| 77 | +Most AI agents look for such files with a specific name: Claude Code expects `.claude/CLAUDE.md`, Cursor uses `.cursorrules`, GitHub Copilot uses `.github/copilot-instructions.md` and so on. |
| 78 | +Each vendor has their own standard, but the generic filename `AGENTS.md` could establish itself as a cross-vendor standard. |
| 79 | +These files contain a collection of rules and best practices for the respective project. |
| 80 | +This is called a **Custom Prompt**: a file with project-specific instructions that controls the behavior of the AI agent and supplements the System Prompt. |
| 81 | +You could also enter these inputs manually before each conversation, but that would be tedious and easy to forget. |
| 82 | + |
| 83 | +Since no unified standard for the filename has been established yet, the Angular CLI supports various variants. |
| 84 | +It asks which agent is being used when creating an application and generates the appropriate files. |
| 85 | +We can also specify the configuration directly with the `--ai-config` option: |
| 86 | + |
| 87 | +```bash |
| 88 | +ng new my-app --ai-config=agents |
| 89 | +``` |
| 90 | + |
| 91 | +If we initially decided against an explicit configuration or want to add another one, we can generate such a configuration afterwards: |
| 92 | + |
| 93 | +```bash |
| 94 | +ng g ai-config |
| 95 | +``` |
| 96 | + |
| 97 | +The guidelines include best practices for TypeScript and Angular, specifications for components, state management, templates and services, as well as accessibility requirements. |
| 98 | + |
| 99 | +The agent now has instructions. |
| 100 | +But whether it can implement them correctly depends on its knowledge level. |
| 101 | +The Custom Prompt states, for example, that the new syntax for control flow should be used. |
| 102 | +But how should the model know how this works if it didn't exist at the time of training? |
| 103 | + |
| 104 | +Here we can partially help: The file generated by Angular is a good starting point, but we can extend it. |
| 105 | +Useful are concrete examples for new syntax, project-specific conventions or hints about errors the agent has repeatedly made. |
| 106 | +For the Custom Prompt: keep it short and focused. |
| 107 | +Too many instructions dilute the effect. |
| 108 | +The AI agent can actually help formulate good instructions itself. |
| 109 | +The MCP server, which we will introduce later, can also provide missing information. |
| 110 | + |
| 111 | +However, there is a limitation: Every LLM can only process a limited amount of text at once. |
| 112 | +This is called a context window. |
| 113 | +The Custom Prompt sits in this window, and during longer sessions the instructions can be forgotten. |
| 114 | + |
| 115 | +## Challenge: The Context Window |
| 116 | + |
| 117 | + |
| 118 | + |
| 119 | +When the context window is exceeded, the AI agent "forgets" earlier parts of the conversation. |
| 120 | +This forgetting is technically necessary for the conversation to continue. |
| 121 | +The most common approach is to summarize the previous conversation as best as possible (**Context Summarization**). |
| 122 | +This works wonderfully sometimes and unfortunately not at all other times. |
| 123 | +If the summary has removed important aspects, this leads to inconsistent responses or outdated code suggestions. |
| 124 | + |
| 125 | +Related to this is the **Lost-in-the-Middle** effect: Information in the middle of a very long context is given less weight by the model than information at the beginning or end. |
| 126 | +This can cause initial instructions from Custom Prompts to be neglected as the conversation progresses, and the model falls back only to the original System Prompt. |
| 127 | +The longer the session lasts, the more likely such effects become. |
| 128 | +Modern AI agents use additional strategies beyond summarization, e.g. targeted tool calls or sub-agents with their own context window. |
| 129 | +A particularly elegant solution is offered by the Angular CLI's MCP server. |
| 130 | + |
| 131 | +## Angular's MCP Server |
| 132 | + |
| 133 | +[MCP (Model Context Protocol)](https://modelcontextprotocol.io/) is an open standard that enables connections between AI applications and external systems. |
| 134 | +MCP servers can provide resources (data sources), tools (callable functions) and prompts (predefined instructions). |
| 135 | +The Angular team is very active in this new field and provides an integrated MCP server through the Angular CLI. |
| 136 | + |
| 137 | +Why does this help? |
| 138 | +MCP tools are called fresh on demand. |
| 139 | +The information then lands in the context. If it is lost through summarization, it can be retrieved again at any time. |
| 140 | +Additionally, the Angular team maintains the responses and updates them regularly, so the problem of outdated knowledge is also addressed. |
| 141 | +Angular's MCP server provides various tools. |
| 142 | + |
| 143 | +### Tools Overview |
| 144 | + |
| 145 | +**Standard Tools:** |
| 146 | + |
| 147 | +- `get_best_practices`: provides coding guidelines for modern Angular development. |
| 148 | +- `search_documentation`: searches the official Angular documentation version-specifically based on keywords. |
| 149 | +- `find_examples`: provides code examples for modern Angular features from a curated database. |
| 150 | +- `ai_tutor`: starts an interactive Angular course that guides you step by step through the framework. |
| 151 | +- `list_projects`: identifies applications and libraries in the workspace. |
| 152 | +- `onpush_zoneless_migration`: analyzes code and provides instructions for migrating to OnPush change detection. |
| 153 | + |
| 154 | +**Experimental Tools:** |
| 155 | + |
| 156 | +- `modernize`: supports migrations to modern patterns, e.g. Signal Inputs (`@Input` → `input()`), modern Outputs (`@Output` → `output()`), the `inject()` function, Signal Queries (`ViewChild`/`ContentChild` → Signals), Built-in Control Flow (`*ngIf`/`*ngFor` → `@if`/`@for`) and Self-Closing Tags. |
| 157 | +- `build`: performs a one-time build with `ng build`. |
| 158 | +- `devserver.start`, `devserver.stop`, `devserver.wait_for_build`: manage the Development Server. |
| 159 | +- `e2e`: runs End-to-End tests. |
| 160 | +- `test`: runs Unit tests. |
| 161 | + |
| 162 | +Since the Angular team has a strong focus on AI, more tools will likely be added regularly. |
| 163 | + |
| 164 | +### Setting up the MCP Server |
| 165 | + |
| 166 | +For the AI agent to use the MCP server, we need to configure it once. |
| 167 | +The command `ng mcp` displays a generic configuration example for this: |
| 168 | + |
| 169 | +``` |
| 170 | +$ ng mcp |
| 171 | +
|
| 172 | +To start using the Angular CLI MCP Server, add this |
| 173 | +configuration to your host: |
| 174 | +
|
| 175 | +{ |
| 176 | + "mcpServers": { |
| 177 | + "angular-cli": { |
| 178 | + "command": "npx", |
| 179 | + "args": ["-y", "@angular/cli", "mcp"] |
| 180 | + } |
| 181 | + } |
| 182 | +} |
| 183 | +
|
| 184 | +Exact configuration may differ depending on the host. |
| 185 | +
|
| 186 | +For more information and documentation, visit: |
| 187 | +https://angular.dev/ai/mcp |
| 188 | +``` |
| 189 | + |
| 190 | +The `-y` flag in the `npx` command installs the Angular CLI without prompting if it is not present. |
| 191 | +The `ng mcp` command only outputs setup guidance in the terminal. |
| 192 | +The exact configuration differs depending on the agent. Typical configuration files are `mcp.json` or `settings.json`. |
| 193 | +The [Angular documentation](https://angular.dev/ai) contains instructions for various agents. |
| 194 | + |
| 195 | +### Enabling Experimental Tools |
| 196 | + |
| 197 | +The experimental tools are disabled by default. |
| 198 | +To use them, they must be explicitly enabled with the `--experimental-tool` flag (short: `-E`). |
| 199 | +The standard tools remain available – the experimental tools are added, not replaced. |
| 200 | + |
| 201 | +Enable individual tools: |
| 202 | + |
| 203 | +```json |
| 204 | +{ |
| 205 | + "mcpServers": { |
| 206 | + "angular-cli": { |
| 207 | + "command": "npx", |
| 208 | + "args": ["-y", "@angular/cli", "mcp", "-E", "modernize", "-E", "test"] |
| 209 | + } |
| 210 | + } |
| 211 | +} |
| 212 | +``` |
| 213 | + |
| 214 | +Enable all experimental tools at once: |
| 215 | + |
| 216 | +```json |
| 217 | +{ |
| 218 | + "mcpServers": { |
| 219 | + "angular-cli": { |
| 220 | + "command": "npx", |
| 221 | + "args": ["-y", "@angular/cli", "mcp", "-E", "all"] |
| 222 | + } |
| 223 | + } |
| 224 | +} |
| 225 | +``` |
| 226 | + |
| 227 | +There is also the `devserver` group, which only enables the devserver tools (`devserver.start`, `devserver.stop`, `devserver.wait_for_build`). |
| 228 | + |
| 229 | +Additionally, two more options are available: |
| 230 | + |
| 231 | +- `--read-only`: enables only read-only tools that don't modify files. |
| 232 | +- `--local-only`: enables only tools that don't require internet access. |
| 233 | + |
| 234 | +Once the MCP server is configured, the AI agent decides autonomously when to call which tool. |
| 235 | +The MCP server does not run permanently, but is only started on demand and then stopped again. |
| 236 | +Most tools are read-only: They provide information like documentation, examples or best practices without modifying files. |
| 237 | +Some tools like `modernize` can, however, also call Angular CLI generators and thus modify code in the project. |
| 238 | +If you want to use a specific tool, explicitly ask the agent for it, e.g. with *"Use the `search_documentation` tool to search for Signal Forms"*. |
| 239 | + |
| 240 | +If you're curious, you can explore the Angular CLI's MCP server yourself. |
| 241 | +With the [MCP Inspector](https://modelcontextprotocol.io/docs/tools/inspector) tool, you can view and test all available tools in the web browser: |
| 242 | + |
| 243 | +```bash |
| 244 | +npx @modelcontextprotocol/inspector "npx" --args "-y @angular/cli mcp" |
| 245 | +``` |
| 246 | + |
| 247 | + |
| 248 | + |
| 249 | +## Practical Recommendations |
| 250 | + |
| 251 | +Working with AI agents has a learning curve. |
| 252 | +Initially it requires effort to formulate good prompts, provide the right context and maintain the setup. |
| 253 | +But those who give this phase time can achieve significant relief in their daily work. |
| 254 | +The following tips for daily work help to shorten this learning curve: |
| 255 | + |
| 256 | +- **Provide context:** Give the agent the context it needs for the current task, and be careful not to flood the context excessively with irrelevant information. |
| 257 | +Reference existing files, interfaces or conventions in your project. |
| 258 | +Use the MCP server to query Angular-specific best practices. |
| 259 | +- **Work iteratively:** Don't expect the first result to be perfect. |
| 260 | +Break complex tasks into small steps and refine the result gradually. |
| 261 | +Ask the agent to review the created software itself and find errors. |
| 262 | +Have it check whether the code conforms to the Angular style guide. |
| 263 | +- **Prefer simplicity:** AI agents produce better results with clear, simple structures – just like humans do. |
| 264 | +Instead of designing complex architectures, use proven abstractions like the [Resource API](https://angular.dev/guide/signals/resource). |
| 265 | +Simple code is easier to generate, review and maintain. |
| 266 | +- **Let it generate tests:** Have unit and integration tests generated, possibly also E2E tests. |
| 267 | +Creating `TestBed` configurations and mocks is a strength of AI agents. |
| 268 | +You get quick feedback on whether something works as intended, and can work together with the agent on a good solution. |
| 269 | +- **Keep code reviews:** Generated code should go through the same review process as manually written code. |
| 270 | +Pay special attention to modern Angular patterns like Signals and the new Control Flow. |
| 271 | +- **Have errors explained:** When an error occurs, let the agent analyze the error message and make solution suggestions. |
| 272 | +You save yourself the research and get context-specific help. |
| 273 | +- **Review critically:** AI models tend, in our experience, to take shortcuts. |
| 274 | +Typical examples are the `any` type as a lazy solution instead of correct typing, or weak assertions like `toBeTruthy()` instead of `toEqual({ name: 'Test' })` or `toBeGreaterThan(0)` instead of `toBe(42)`. |
| 275 | +Pay special attention to ensure the AI doesn't simply adjust the test when tests fail, instead of solving the actual problem. |
| 276 | +Therefore, always review generated code critically and demand strict typing. |
| 277 | +- **Use recipes:** Countless implementation patterns from the training data are stored in the LLM. |
| 278 | +Describe what you need and have solution suggestions generated. |
| 279 | +Always ask for possible alternatives too, and have pros and cons listed. |
| 280 | +- **Delegate migrations:** For Angular upgrades or migration to new patterns like Standalone Components, Signals or Control Flow, the agent can take over a lot of work. |
| 281 | +The MCP server provides dedicated tools for this. |
| 282 | +- **Pair Programming:** Use the agent as a "sparring partner" for architectural decisions. |
| 283 | +Have different solution paths shown to you. |
| 284 | +The agent has no ego and explains patiently. |
| 285 | +- **Use CLIs instead of Web:** AI agents are increasingly receiving access blocks because they crawl websites intensively. |
| 286 | +Therefore use designated interfaces: for GitHub the GitHub CLI (`gh`), for Azure DevOps the Azure CLI (`az devops`) or provided MCP servers. |
| 287 | +Command-line tools offer a more direct interface than web interfaces and consume less API quota, which saves costs. |
| 288 | +- **Additional MCP servers:** Connect additional MCP servers to your agent. |
| 289 | +Many tools from everyday development offer suitable integrations. |
| 290 | +By connecting to your design software, ticket systems and other platforms, the agent can directly access documentation, designs and tickets and incorporate this information into its work. |
| 291 | + |
| 292 | +## Conclusion |
| 293 | + |
| 294 | +AI agents are powerful tools that support us in developing with Angular. |
| 295 | +With configuration files and the Angular CLI's MCP server, you bridge the gap between outdated training data and current best practices. |
| 296 | +But AI does not replace expertise. |
| 297 | +Those who don't understand Angular's concepts cannot judge whether the generated code is correct. |
| 298 | +Therefore: Use AI as an accelerator, but invest in your own understanding – for example in [our Angular workshops](https://angular.schule). |
| 299 | + |
| 300 | +<br> |
| 301 | +<hr> |
| 302 | + |
| 303 | +<small>**Header image:** generated with Nano Banana Pro (Gemini 3)</small> |
0 commit comments