# AI Code Completion

> The AI Code Completion is an editor feature that suggests the next lines of code using a language model.

## How does AI code completion work?

The editor feature that predicts and suggests code as the developer types, from single lines to whole functions, based on the surrounding code. Speeds up writing routine code but suggestions must be reviewed.

- Topic: Agentic Coding
- Type: technology

## Example

Wrong:

```ts
const client = createClient({
  apiKey: 'abc123-test-key',
});
```

Right:

```ts
const client = createClient({
  apiKey: process.env.API_KEY,
});
```

A completion that fills in a sample key gets committed easily, so the key should come from the environment.

## Common mistakes

- Accepting a long suggestion with Tab without reading it.

## Key points

- Accepted suggestions use APIs that exist in the project's dependencies, not invented ones.
- Suggested code does not include hardcoded secrets, keys or sample credentials.
- Suggestions match the project's style and types, and pass the type checker.

## Interview questions

### Code completion vs coding agent: what is the difference?

Completion suggests the next lines while you type, and you accept each one. A coding agent takes a whole task, edits many files and runs commands.

### Does AI code completion send my code to a server?

Usually yes, the surrounding code is sent to the model as context. Check the tool's settings and exclude files with secrets or private data.

### Why does code completion suggest functions that do not exist?

The model predicts likely code, not code verified against your dependencies. A type checker and tests catch invented APIs.

## Related cards

- [Coding Agent](https://wonderium.dev/ai/coding-agent.md)
- [Agentic Coding](https://wonderium.dev/ai/agentic-coding.md)
- [IDE](https://wonderium.dev/engineering/ide.md)
- [Hallucination](https://wonderium.dev/ai/hallucination.md)

---

- Level: [Artificial Intelligence](https://wonderium.dev/ai.md)
- HTML version: https://wonderium.dev/ai/code-completion
- Last updated: 2026-11-25
