# Code generation (AI)

> Canonical: https://skillalmanac.com/glossary/code-generation | Last verified: 2026-11-25 | Index status: index-eligible

AI code generation is the use of a language model to produce program code, usually from a plain-language description or the code around the cursor. The output is text that may contain bugs, so it needs review and testing.

Also called: AI code generation, code generation AI, LLM code generation, generate code with AI, AI-generated code.

## In plain language

AI code generation means asking a program to write code for you. You describe what you want, for example a function that checks whether an email address looks valid, and the model writes a first version. It is like asking a fast junior colleague for a draft: useful, but you check it. The draft can be buggy, duplicative or unnecessary, and it can introduce security problems, so you run it and read it before relying on it. Generating code is also not the same as running it. The model produces text; a separate step has to execute that text and see whether it works.

## Technical definition

Code-generation models are language models trained on large amounts of source code and text and used to continue a prompt, such as a docstring, a comment or surrounding code, with code. The Codex paper (Chen et al.) evaluated a GPT model fine-tuned on public GitHub code on writing Python functions from docstrings, and evaluated results for functional correctness on the HumanEval benchmark. Its pass@k evaluation counts whether any of k sampled candidates passes the benchmark tests; that evaluation does not mean deployment has access to an oracle for selecting correct code. Tools around the model add context from your files and can run tests on the output.

## How it shows up when you use agents

In a coding agent, generation is one step in a loop. You describe a task, the model writes code, and the tool can write it to files and run it. IBM defines AI code generation as producing code from natural language instructions or partial code snippets. The Claude Code overview describes the same flow, planning an approach, writing code across multiple files and verifying it works.

The generated text is a proposal. IBM states that AI-powered coding software can generate code that is buggy, duplicative, inaccurate or unnecessary, and that it might introduce security vulnerabilities. In a session this shows up as a function that compiles but ignores an edge case, or a call to a library method that does not exist (see [Hallucination](/glossary/hallucination)).

What breaks when this is misunderstood: you accept a large generated change because it reads well. A safer habit is to ask for a test first, run it, read the diff and keep changes small. The [AI coding assistant](/glossary/ai-coding-assistant) entry covers the tools that do this, and [HumanEval](/glossary/humaneval) covers how generation is scored by unit tests.

## Common confusions

- **Generation versus completion.** Completion continues a supplied input and can produce multiple lines or a whole function. It is one way to generate code, so the two categories overlap.
- **Generation versus execution.** The model writes text. Running it, and learning whether it works, is a separate step done by you or by an agent.
- **Generation versus vibe coding.** Code generation is the technique. [Vibe coding](/glossary/vibe-coding) is a working style that relies on it heavily.
- **Myth: passing a benchmark means correct in your project.** The Codex paper scored Python functions against unit tests; your codebase, libraries and requirements differ, so test in place.

## Worked examples in this catalogue

### [tdd](https://skillalmanac.com/skills/mattpocock/tdd)

Status: illustrative example from the item's own documentation, not executed for this page.

What you see: A test-first red-to-green loop for a feature or bug fix, one slice at a time. This pinned skill leaves refactoring to the review stage.

Why it exercises the concept: The Codex paper evaluated generated code for functional correctness; writing the test first gives generated code the same kind of check before you accept it.

### [spec-driven-build](https://skillalmanac.com/skills/skill-almanac/spec-driven-build)

Status: illustrative example from the item's own documentation, not executed for this page.

What you see: Builds a feature from an agreed spec, one numbered requirement at a time, with acceptance tests as evidence for each requirement.

Why it exercises the concept: A written spec is the prompt that generation starts from, and the tests supply evidence about the requirements instead of relying only on the draft.

### [What Is Vibe Coding and When You Must Read the Code](https://skillalmanac.com/learn/what-is-vibe-coding)

Status: illustrative example from the item's own documentation, not executed for this page.

What you see: The guide explains vibe coding, building software by describing it to an AI tool, and what to check before you ship the result.

Why it exercises the concept: Vibe coding is code generation used as the main way of working, so the guide shows the review step that this entry says is needed.

### [Claude Code](https://skillalmanac.com/tools/claude-code)

```
claude
```

Status: illustrative example from the item's own documentation, not executed for this page.

What you see: Claude Code starts in your project, and its docs describe it as planning an approach, writing code across multiple files and verifying that it works.

Why it exercises the concept: It shows generation inside an agent that can run the result, not only produce text.

## Related terms

- [AI coding assistant](https://skillalmanac.com/glossary/ai-coding-assistant.md)
- [Large language model (LLM)](https://skillalmanac.com/glossary/large-language-model.md)
- [Vibe coding](https://skillalmanac.com/glossary/vibe-coding.md)
- [HumanEval](https://skillalmanac.com/glossary/humaneval.md)
- [Coding agent](https://skillalmanac.com/glossary/coding-agent.md)
- [AI hallucination](https://skillalmanac.com/glossary/hallucination.md)
- [Text-to-SQL](https://skillalmanac.com/glossary/text-to-sql.md)

## Sources

- [Evaluating Large Language Models Trained on Code](https://arxiv.org/abs/2107.03374), arXiv (Chen et al.) (accessed 2026-11-24)
- [What is AI code generation?](https://www.ibm.com/think/topics/ai-code-generation), IBM (accessed 2026-11-24)
- [Claude Code overview](https://code.claude.com/docs/en/overview), Anthropic (Claude Code Docs) (accessed 2026-11-24)

Definitions are written by Skill Almanac from the sources above and checked against them on 2026-11-25. [Glossary index](https://skillalmanac.com/glossary.md).
