GitHub Copilot CLI is a coding agent you start with copilot in a TypeScript project folder. It reads project-specific instructions from .github/copilot-instructions.md or AGENTS.md, runs terminal commands, and edits files. This guide shows how to set it up for strict TypeScript work and get reliable, reviewable changes. See GitHub Copilot CLI for the agent itself.
Why Copilot CLI fits a strict TypeScript workflow
TypeScript development depends on fast feedback from the compiler and clear type boundaries. GitHub Copilot CLI works directly in the terminal, so it can run pnpm typecheck, read the exact tsc errors, and edit the code that caused them. It is not a separate IDE plugin; the loop is the same commands you already run in CI.
For strict TypeScript codebases, this matters because the agent sees the real compiler output instead of guessing. It can add generic utilities, narrow union types, and refactor across monorepo package boundaries while respecting each package’s tsconfig. The combination of terminal access and TypeScript-aware reasoning makes it useful for tasks that require both type-level changes and runtime behavior.
Prepare your TypeScript repo with precise agent instructions
Put the instructions in .github/copilot-instructions.md at the repo root. AGENTS.md at the root also works. Keep the file short and concrete: build, test, lint commands, folder conventions, and TypeScript-specific rules. The agent reads this every session, so do not include vague preferences.
# Copilot instructions for this TypeScript repo
## Commands
- Install: pnpm install
- Build: pnpm build (runs tsc -p tsconfig.json)
- Typecheck: pnpm typecheck (tsc --noEmit)
- Test: pnpm test (vitest run)
- Lint: pnpm lint (eslint .)
## TypeScript rules
- TypeScript is in strict mode. Do not use `any` without a comment explaining why.
- Prefer type narrowing with `in`, `typeof`, `instanceof`, and discriminated unions over type assertions.
- Use generics for reusable utilities. Avoid `as` casts unless necessary.
- Do not add `@ts-ignore` or `@ts-expect-error` without explicit approval.
- Use `import type` for type-only imports to keep module boundaries clear.
## Folders
- `src/` application code
- `src/types/` shared types
- `src/utils/` pure functions, no React imports
- `tests/` colocated tests with `.test.ts` suffix
Monorepo note: each package has its own `tsconfig`; use `pnpm --filter <pkg> ...`.
For large TypeScript monorepos, also describe package boundaries or include a short codebase map so the agent can locate code without grep. See Codebase map for AI agents.
Small steps, typecheck, review: a practical loop
Run copilot in the project root, then work in small steps. Ask for a plan first for anything non-trivial, then let the agent edit one area at a time. After each change, have it run the typecheck and the relevant test command, then review the diff before moving on.
Example prompts for common TypeScript work:
- “Add a
Result<T, E>generic type withokanderrconstructors and anisOktype guard. Use it insrc/fetchUser.tsand remove the currentanyreturn type. Runpnpm typecheckafter editing.” - “Refactor
src/utils/parseConfig.tsto replace type assertions with discriminated union narrowing. Keep behavior identical and runpnpm test.” - “In the
packages/apiworkspace, add strict typing tohandleRequestwithout changing runtime behavior. Runpnpm --filter @app/api typecheck.” - “Write a unit test for the generic
paginatefunction insrc/utils/paginate.ts, covering empty input and type inference. Run the test file.” - “Read
tscoutput forsrc/components/UserTable.tsxand fix all errors without usingany; then run lint and tests.”
The pattern is always: small scope, explicit command to verify, then review. Do not ask the agent to “make the codebase stricter” in one shot; it will produce a huge diff.
Where the agent shines, and TypeScript-specific pitfalls
The table below shows tasks where the agent is usually reliable and the prompt style that works.
| Task | Good prompt |
|---|---|
| Add a generic utility | “Create a generic DebouncedFunction<T extends (...args: any[]) => any> type and a debounce wrapper with correct this typing.” |
| Narrow a discriminated union | “Refactor handleMessage to switch on message.kind instead of using as casts.” |
| Fix strict-mode errors | “Run pnpm typecheck and fix the errors under strict, keeping the public API unchanged.” |
| Write typed tests | “Add tests for the Result helpers using expectTypeOf from vitest.” |
Watch closely in these areas:
- The agent may introduce
anyto silence complex generic errors. Review diffs for newanyand ask for a typed alternative. - It sometimes overuses
ascasts, especially when narrowing unions. Ask it to use type guards instead. - In monorepos, it may edit the root
tsconfiginstead of the packagetsconfig, or add a root-level type declaration that conflicts with package types. - It can add
@ts-ignorecomments if the compiler error is hard to solve. Set an instruction that these require approval. - Strict mode plus
exactOptionalPropertyTypesornoUncheckedIndexedAccesscan generate many small errors; the agent may “fix” them by relaxing the tsconfig. Do not accept tsconfig changes that weaken strictness without a discussion.
Verify types and tests before you merge
Type safety is the first verification gate. Always have the agent run pnpm typecheck (or npx tsc --noEmit) before tests. For code with generics, add type-level tests with expectTypeOf from Vitest or tsd to lock the intended inference. After typecheck passes, run the unit tests and lint.
The agent can run browser tests for frontend TypeScript as well. If the project has a Vite or Next.js dev server, ask it to start the app and check a feature end-to-end. See AI agent browser testing for a practical setup.
In CI, keep tsc --noEmit as a blocking check. The agent should not be able to merge changes that only pass tests but fail typecheck. Always review the tsc command output before accepting the diff.
Parallel TypeScript agents with AgentVera
For a TypeScript project, AgentVera can run GitHub Copilot CLI alongside other CLIs in separate terminal panels. Each agent can work in its own git worktree, so parallel agents do not overwrite each other’s type changes. Automatic code review runs a second model over the diff, which often catches unsafe any or added as casts before merge. Checkpoints snapshot every turn, so a bad type refactor is easy to undo and replay. Token budgets cap each agent per turn and per day, stopping runaway loops that keep editing the same generic.
Wrap-up
GitHub Copilot CLI becomes much more useful on a TypeScript project when you give it exact commands and strict type rules. Start with a short instruction file, work in small compiler-verified steps, and always review the diff for type-system shortcuts. With that loop, the agent can handle generics, union narrowing, and monorepo refactors without turning the codebase into a pile of any.