import DefinitionCard from "@site/src/components/DefinitionCard";

# What is AI Pair Programming?

## Introduction

**AI pair programming** is writing code together with an AI assistant in short turns. You decide what to build and check each step. The assistant proposes or writes the code, and you accept, edit, or reject it before moving on.

The name comes from human pair programming, where two developers share one task. Martin Fowler's [guide to pair programming](https://martinfowler.com/articles/on-pair-programming.html) describes the **driver** as "the person at the wheel, i.e. the keyboard," and the **navigator** as the person who reviews the code as it is written and keeps the bigger picture in view. In AI pair programming the assistant usually drives and you navigate.

This article explains how the loop works, where it sits next to [coding agents](./coding-agents.mdx), and what it does not replace from a human pair.

## Understanding the Concept

The defining property is the size of each step. You see every change before the next one starts, so a wrong assumption costs one exchange, not an afternoon. That is the difference from delegating a task to an agent and reviewing the result at the end.

AI pair programming tools come in three shapes:

| Shape | How you work | Example |
| --- | --- | --- |
| Inline completion | The assistant suggests the next lines as you type | Tab completion in the editor |
| Editor chat | You describe a change, the assistant edits the open files | A chat panel beside the code |
| Terminal pair | You talk to the assistant in a terminal, it edits files and commits | Aider, which calls itself "AI pair programming in your terminal" |

All three share one rule: the developer stays in the session. The same model can power a coding agent. What changes is how much work it does before it hands control back.

| | AI pair programming | Delegating to a coding agent |
| --- | --- | --- |
| Step size | One edit or one small change | A whole task |
| Review | As each change lands | Once, on the finished diff |
| Your attention | Continuous | At the start and the end |
| Best for | Unclear or design-heavy work | Well-specified, repeatable work |

## Applying It in Practice

Start the session with the goal and the constraints, then work in small slices. A good slice is one function, one test, or one refactor step. Ask for a short plan first on anything that touches more than two files, and correct the plan before any code is written.

Commit after each accepted slice. [Aider](https://aider.chat/) does this for you: it "automatically commits changes with sensible commit messages." Small commits let you undo one bad step with Git instead of untangling it by hand.

Read every change before you accept it. Check that it reuses existing helpers, follows the project's patterns, and does not touch files outside the slice. Run the tests yourself after each step. The assistant's summary is not a test result.

Switch roles when it helps. Write the tricky part yourself and let the assistant write the tests, or the reverse. The assistant does not tire of typing, so give it the mechanical half.

## Engineering Considerations

A human navigator pushes back. An AI assistant tends to accept your direction, even when the direction is wrong. Ask it directly for problems with your approach, and treat agreement as no evidence either way.

Human pairing also spreads knowledge across a team. Two people leave the session understanding the code. With an AI pair, only you do. Keep human review on changes that other people will have to maintain.

The tight loop is slower per task than delegating. That cost is worth paying when the requirements are unclear, when the design is new, or when the code is security-sensitive. For routine work with a clear outcome, hand the task to an agent and review the diff at the end.

## Scaling and Operations

AI pair programming scales with your attention, which is one session at a time. Teams usually pair on the hard work and delegate the routine work to agents that run on their own.

Once you delegate, each agent needs its own working copy and its output needs review. Treq gives each agent its own workspace and shows each change as a pull-request-style diff. You can send [inline review comments](/docs/tutorials/code-review-workflow) back to the agent, which keeps the review step close to the pairing loop. [Human-in-the-loop development](./human-in-the-loop-development.mdx) covers where those review points belong.

## Next Steps

- [What are Coding Agents?](./coding-agents.mdx): what changes when the assistant works through a task alone
- [What is an AI Software Engineer?](./ai-software-engineer.mdx): agents that take a ticket and return a pull request
- [What is AI-Assisted Software Engineering?](./ai-assisted-software-engineering/index.mdx): the full range from autocomplete to autonomous agents
- [Human in the Loop AI Code Review](/learn/ai-code-review): review AI-written changes before they merge
