# zsh-users/zsh-autosuggestions architecture

> Architecture diagram of the GitHub repository zsh-users/zsh-autosuggestions, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/zsh-users/zsh-autosuggestions
- Repository: https://github.com/zsh-users/zsh-autosuggestions

## Overview

zsh-autosuggestions is a Zsh line-editor plugin that displays a muted inline suggestion as the user types. Its principal workflow is: ZLE widget activity triggers a fetch, configured strategies search history or ask the completion system, and the resulting suggestion is displayed; accept widgets can copy all or part of it into the command buffer. The README documents the capabilities and strategy behavior, but the runtime source was not excerpted, so internal call edges are omitted where their ownership cannot be verified.

Main entry points: [`src/fetch.zsh`](https://github.com/zsh-users/zsh-autosuggestions/blob/master/src/fetch.zsh) (Strategy selection), [`src/strategies/completion.zsh`](https://github.com/zsh-users/zsh-autosuggestions/blob/master/src/strategies/completion.zsh) (Completion strategy), [`src/start.zsh`](https://github.com/zsh-users/zsh-autosuggestions/blob/master/src/start.zsh) (Startup setup), [`src/bind.zsh`](https://github.com/zsh-users/zsh-autosuggestions/blob/master/src/bind.zsh) (Widget mapping)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Plugin entry"]
  node_plugin_entry["Plugin loader"]
  node_plugin_script["Plugin script"]
  node_startup["Startup setup<br/>[start.zsh]"]
  node_configuration["Configuration<br/>[config.zsh]"]
end

subgraph group_interaction["ZLE interaction"]
  node_widget_mapping["Widget mapping<br/>[bind.zsh]"]
  node_widgets["Suggestion widgets<br/>[widgets.zsh]"]
end

subgraph group_suggestion["Suggestion generation"]
  node_fetch["Suggestion fetch<br/>[fetch.zsh]"]
  node_async["Async fetching<br/>[async.zsh]"]
  node_strategies["Strategy selection<br/>[fetch.zsh]"]
  node_history_strategy["History strategy<br/>[history.zsh]"]
  node_completion_strategy["Completion strategy<br/>[completion.zsh]"]
  node_prev_command_strategy["Prior-command strategy<br/>[match_prev_cmd.zsh]"]
end

subgraph group_presentation["Presentation"]
  node_highlight["Suggestion highlighting<br/>[highlight.zsh]"]
end

node_user(("Shell user"))
node_zsh["Zsh shell"]
node_history[("Zsh history")]
node_completion["Zsh completion system"]
node_zpty["Zsh zpty module"]

node_user -->|"types commands"| node_zsh
node_zsh -->|"invokes widgets"| node_widget_mapping
node_widget_mapping -->|"dispatches behavior"| node_widgets
node_widgets -->|"fetches suggestion"| node_fetch
node_fetch -->|"tries strategies"| node_strategies
node_strategies -->|"selects strategy"| node_history_strategy
node_strategies -->|"selects strategy"| node_completion_strategy
node_strategies -->|"selects strategy"| node_prev_command_strategy
node_history_strategy -->|"matches history"| node_history
node_prev_command_strategy -->|"matches history"| node_history
node_completion_strategy -->|"requests completions"| node_completion
node_completion_strategy -.->|"requires module"| node_zpty
node_fetch -->|"fetches asynchronously"| node_async
node_fetch -->|"shows suggestion"| node_highlight
node_configuration -->|"configures strategy"| node_strategies
node_configuration -->|"sets style"| node_highlight
node_startup -.->|"sets up widgets"| node_widget_mapping
node_plugin_entry -.->|"loads plugin"| node_startup
node_plugin_script -.->|"loads plugin"| node_startup

click node_plugin_entry "https://github.com/zsh-users/zsh-autosuggestions/blob/master/zsh-autosuggestions.zsh"
click node_plugin_script "https://github.com/zsh-users/zsh-autosuggestions/blob/master/zsh-autosuggestions.plugin.zsh"
click node_startup "https://github.com/zsh-users/zsh-autosuggestions/blob/master/src/start.zsh"
click node_configuration "https://github.com/zsh-users/zsh-autosuggestions/blob/master/src/config.zsh"
click node_widget_mapping "https://github.com/zsh-users/zsh-autosuggestions/blob/master/src/bind.zsh"
click node_widgets "https://github.com/zsh-users/zsh-autosuggestions/blob/master/src/widgets.zsh"
click node_fetch "https://github.com/zsh-users/zsh-autosuggestions/blob/master/src/fetch.zsh"
click node_async "https://github.com/zsh-users/zsh-autosuggestions/blob/master/src/async.zsh"
click node_strategies "https://github.com/zsh-users/zsh-autosuggestions/blob/master/src/fetch.zsh"
click node_history_strategy "https://github.com/zsh-users/zsh-autosuggestions/blob/master/src/strategies/history.zsh"
click node_completion_strategy "https://github.com/zsh-users/zsh-autosuggestions/blob/master/src/strategies/completion.zsh"
click node_prev_command_strategy "https://github.com/zsh-users/zsh-autosuggestions/blob/master/src/strategies/match_prev_cmd.zsh"
click node_highlight "https://github.com/zsh-users/zsh-autosuggestions/blob/master/src/highlight.zsh"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_plugin_entry,node_plugin_script,node_startup,node_configuration,node_user toneBlue
class node_widget_mapping,node_widgets,node_history toneAmber
class node_fetch,node_async,node_strategies,node_history_strategy,node_completion_strategy,node_prev_command_strategy toneMint
class node_highlight toneRose
class node_zsh,node_completion,node_zpty toneIndigo
```

## Components

### Plugin entry

- [Plugin loader](https://github.com/zsh-users/zsh-autosuggestions/blob/master/zsh-autosuggestions.zsh): `zsh-autosuggestions.zsh`
- [Plugin script](https://github.com/zsh-users/zsh-autosuggestions/blob/master/zsh-autosuggestions.plugin.zsh): `zsh-autosuggestions.plugin.zsh`
- [Startup setup](https://github.com/zsh-users/zsh-autosuggestions/blob/master/src/start.zsh): `src/start.zsh`
- [Configuration](https://github.com/zsh-users/zsh-autosuggestions/blob/master/src/config.zsh): `src/config.zsh`

### ZLE interaction

- [Widget mapping](https://github.com/zsh-users/zsh-autosuggestions/blob/master/src/bind.zsh): `src/bind.zsh`
- [Suggestion widgets](https://github.com/zsh-users/zsh-autosuggestions/blob/master/src/widgets.zsh): `src/widgets.zsh`

### Suggestion generation

- [Suggestion fetch](https://github.com/zsh-users/zsh-autosuggestions/blob/master/src/fetch.zsh): `src/fetch.zsh`
- [Async fetching](https://github.com/zsh-users/zsh-autosuggestions/blob/master/src/async.zsh): `src/async.zsh`
- [Strategy selection](https://github.com/zsh-users/zsh-autosuggestions/blob/master/src/fetch.zsh): `src/fetch.zsh`
- [History strategy](https://github.com/zsh-users/zsh-autosuggestions/blob/master/src/strategies/history.zsh): `src/strategies/history.zsh`
- [Completion strategy](https://github.com/zsh-users/zsh-autosuggestions/blob/master/src/strategies/completion.zsh): `src/strategies/completion.zsh`
- [Prior-command strategy](https://github.com/zsh-users/zsh-autosuggestions/blob/master/src/strategies/match_prev_cmd.zsh): `src/strategies/match_prev_cmd.zsh`

### Presentation

- [Suggestion highlighting](https://github.com/zsh-users/zsh-autosuggestions/blob/master/src/highlight.zsh): `src/highlight.zsh`

### Other components

- **Shell user**
- **Zsh shell**
- **Zsh history**
- **Zsh completion system**
- **Zsh zpty module**

## Connections

- Shell user → Zsh shell: types commands (evidence: `README.md`)
- Zsh shell → Widget mapping: invokes widgets (evidence: `README.md`)
- Widget mapping → Suggestion widgets: dispatches behavior (evidence: `README.md`)
- Suggestion widgets → Suggestion fetch: fetches suggestion (evidence: `README.md`)
- Suggestion fetch → Strategy selection: tries strategies (evidence: `README.md`)
- Strategy selection → History strategy: selects strategy (evidence: `README.md`)
- Strategy selection → Completion strategy: selects strategy (evidence: `README.md`)
- Strategy selection → Prior-command strategy: selects strategy (evidence: `README.md`)
- History strategy → Zsh history: matches history (evidence: `README.md`)
- Prior-command strategy → Zsh history: matches history (evidence: `README.md`)
- Completion strategy → Zsh completion system: requests completions (evidence: `README.md`)
- Completion strategy → Zsh zpty module: requires module (evidence: `README.md`)
- Suggestion fetch → Async fetching: fetches asynchronously (evidence: `README.md`)
- Suggestion fetch → Suggestion highlighting: shows suggestion (evidence: `README.md`)
- Configuration → Strategy selection: configures strategy (evidence: `README.md`)
- Configuration → Suggestion highlighting: sets style (evidence: `README.md`)
- Startup setup → Widget mapping: sets up widgets
- Plugin loader → Startup setup: loads plugin
- Plugin script → Startup setup: loads plugin
