Guide
AI Coding Workflow for TypeScript
A TypeScript AI coding workflow should start from the failing type, test or component behavior, then keep the agent inside the relevant package. A patch that compiles has passed only the first check. Review whether the diff keeps the existing types and patterns, starting with any type it made wider.

On this page
What does a reviewable agent task look like?
Give the agent one named task, only the context it needs and a check you can rerun. A task shaped this way produces a diff small enough to review and a result you can repeat.
- Move
- Start with a bounded task
- Use this when
- You have a named owner, target files and a clear done state
- Proof to save
- Issue, files, checks and owner are named
- Move
- Give the agent context
- Use this when
- The repo has patterns the agent must follow
- Proof to save
- Prompt cites files, errors and constraints
- Move
- Review the diff
- Use this when
- The task changes production code
- Proof to save
- Changed files, test output and risks are visible
| Move | Use this when | Proof to save |
|---|---|---|
| Start with a bounded task | You have a named owner, target files and a clear done state | Issue, files, checks and owner are named |
| Give the agent context | The repo has patterns the agent must follow | Prompt cites files, errors and constraints |
| Review the diff | The task changes production code | Changed files, test output and risks are visible |
Each move leaves proof that a reviewer can check later.
Each move fails in its own way. Without a boundary, the agent edits files you never meant to open, and the diff becomes hard to read. Thin context fails more quietly: the code compiles and the tests pass, but the change ignores patterns the rest of the repo follows. Without a check you can rerun, you are taking the agent's word that the work is done.
Asking for a plan before the agent writes code is the easiest step to skip. It means a short wait while nothing visible happens, and the price of skipping it shows up later, in review.
If the plan names files you didn't expect, you learn that before any code exists. If it names the right files, you have a list to check the diff against. Once four hundred lines of diff are on screen, changing the approach means throwing that work away.
Interactive widget. Tab through its controls; the result updates in the panel below as you change them.
Pick your role, stack and task type before you write a prompt.
This is covered hands-on in Cursor First Hour — 4 short Units, free to read.
How should a team run each agent task?
The habit that matters most for a team is leaving a trail the next reviewer can follow. The steps below keep the prompt and its proof attached to the change.
- 1Pick one real backlog item with a clear owner and expected result.
- 2Add only the context the agent needs: files, failing output, constraints and done state.
- 3Ask for a plan before code when the task touches more than one file.
- 4Run checks that match the risk: unit test, typecheck, visual pass or review checklist.
- 5Capture the prompt, diff, result and reviewer note so the workflow can be repeated.
Match the effort to the change. A one-file fix needs a clear done state and a typecheck, and a plan adds little. A change across several files is where a plan pays for itself, and where the check should include tests and a reviewer who knows that code.
What should you keep after the run?
Keep whatever lets someone rerun the work or pick it up later. A finished task is the merged code plus a short trail that shows how it got there.
- The prompt or plan that shaped the work.
- The files changed and the reason each file changed.
- The command, screenshot or review note that proved the result.
- The rule, checklist or template you would reuse next time.
The last item pays off over time. A rule or template saved from one good run means the next run starts from what already worked, not from a blank prompt.
Should the agent start from the type error or the failing test?
Start from whichever one you can rerun with a single command, and give the agent its real output instead of your summary of it. In a TypeScript repo, that is usually the compiler. A type error names a file, a line and the shape the compiler expected, which is most of a prompt already. A failing test tells you behavior is wrong without saying where.
The order matters because types and tests fail at different distances from the cause. A type error usually sits next to the mistake. A test failure can sit several layers away, and an agent given only the test will often satisfy the assertion at whichever layer it happened to be reading. That fix lands in the wrong place, and it still typechecks.
When both are broken, fix the types first and rerun the test before you change anything else. The type fix can take the test failure with it, which makes it the cheaper order to try.
Why does a patch that typechecks still fail review?
Because passing the typecheck and being correctly typed are two different claims. The quickest route to a green build is to make a type less specific: an any, a cast, a non-null assertion, or a generic loosened one parameter at a time. All of those compile, and each one moves a check out of the build and into a later incident.
So read the type edits before the logic edits: scan the diff for signatures that got wider, then look for behavior that changed. The widened signature is the edit that outlives the ticket, because the next person to call that function reads its type as a promise about what it accepts.
None of this is unique to agent-written code, but an agent produces these edits faster than review habits were built to catch them.
How do you keep an agent inside one package in a monorepo?
Write the boundary down where the package lives. Cursor reads AGENTS.md files in any subdirectory and applies them to files in that directory and its children. It combines them with the parent instructions, and the more specific file takes precedence. A package that must not import from a sibling can say so in its own AGENTS.md, instead of relying on a root file that tries to describe every package at once.
If you use project rules instead, get the extension right first. A plain .md file in .cursor/rules is ignored, because it has no frontmatter to hold description, globs and alwaysApply. Use .mdc, or use AGENTS.md and skip frontmatter altogether.
For a typing convention the agent should apply to every TypeScript file, use globs instead of a description. With alwaysApply: false and a comma-separated pattern list such as globs: **/*.ts, **/*.tsx, the rule attaches automatically whenever a matching file is in context. With a description and no globs, the agent reads the description and decides for itself whether the rule applies. It can get that call wrong on the one edit where the convention mattered.
It is tempting to run the check only on the package you touched. But a package that compiles on its own and breaks its consumers is the standard monorepo failure. The agent reports it as finished, because from inside the package it is. Run the dependent's build before you believe the result.
Hooks cover the mechanical half. They live in hooks.json, and afterFileEdit fires after the agent edits a file. Running formatters after edits is one of the documented uses, so the diff you sit down to read is already formatted.
Frequently asked questions
Who is this guide for?
TypeScript teams that use coding agents in application repos and package monorepos.
What should I do next?
Take one failing typecheck or test from your backlog and give the agent its exact output. When the diff comes back, read the type edits before the logic, and run the builds of any packages that depend on the one it changed.
Should an agent start from the type error or the failing test?
Start from whichever one you can rerun with a single command, usually the compiler, and give the agent its real output. A type error names the file, the line and the shape the compiler expected. When both fail, fix the types first and rerun the test.
How do I stop an agent from loosening types to pass the build?
Read the type edits before the logic edits. Scan the diff for an any, a cast, a non-null assertion or a loosened generic, because each one compiles while it moves a check out of the build.
How do I keep an agent inside one package in a monorepo?
Put an AGENTS.md file in the package. Cursor applies nested AGENTS.md files to files in that directory and its children, and the more specific file takes precedence. Then run the builds of the packages that depend on it before you trust the result.
Sources & last verified
- Cursor agent best practices
- Cursor Learn: working with agents
- Cursor Learn: context
- Cursor docs: prompting agents
- Cursor docs: Rules
- Cursor docs: Hooks
Cursor ships frequently. Facts verified against primary sources on October 28, 2026.