---
title: "Heroku CLI: Completing Autocomplete"
description: "Heroku CLI Autocomplete had to support a dynamic, plugin-based command set while completing values that often reside behind the Heroku API. Instead of static shell case statements, its cache builder iterates through installed commands and generates setters that supply command, flag, and value completions when the user presses Tab. A shim sourced from the user’s .bashrc or .zshrc limits profile changes, fails silently when unavailable, and permits updates without repeated edits. API-backed values are cached on disk, while oclif custom hooks invalidate or rebuild relevant caches after commands change data. The completion function also parses the partially entered command line to provide contextual results, such as add-on aliases for a specified app; the work is being incorporated into an oclif plugin."
---

# Heroku CLI: Completing Autocomplete

[Heroku](https://yomu.fyi/company/heroku) · Philipe Navarro · Jun 12, 2018

**Type:** Explainer

## Summary

Heroku CLI Autocomplete had to support a dynamic, plugin-based command set while completing values that often reside behind the Heroku API. Instead of static shell case statements, its cache builder iterates through installed commands and generates setters that supply command, flag, and value completions when the user presses Tab. A shim sourced from the user’s .bashrc or .zshrc limits profile changes, fails silently when unavailable, and permits updates without repeated edits. API-backed values are cached on disk, while oclif custom hooks invalidate or rebuild relevant caches after commands change data. The completion function also parses the partially entered command line to provide contextual results, such as add-on aliases for a specified app; the work is being incorporated into an oclif plugin.

## Context

The Heroku CLI supports user-installed plugins, varied shell configurations, and completion data stored behind an API rather than locally. The work also needed to address cache invalidation and completions dependent on values already supplied in a command.

## Approach / What changed

The implementation builds a cache from installed commands, generates setters for dynamic completion, sources a controlled shim from the shell profile, caches API responses on disk, uses oclif custom hooks for invalidation, and parses existing command-line input for contextual completions.

## Takeaways

- The autocomplete cache builder includes commands from installed plugins and generates setters containing the information needed to complete each command’s flags and values.
- A shim stored in the user’s cache directories can be updated without further shell-profile edits and fails silently if it cannot be found, preventing autocomplete problems from blocking the shell.
- oclif custom hooks let commands trigger targeted completion-cache invalidation or rebuilding without coupling the CLI lifecycle to whether the autocomplete plugin is installed.

**Tags:** [API](https://yomu.fyi/topic/api), [Caching](https://yomu.fyi/topic/caching), [oclif](https://yomu.fyi/topic/oclif)

- Source: [Heroku](https://www.heroku.com/blog/completing-autocomplete)
- Source URL: https://www.heroku.com/blog/completing-autocomplete
- Ingested by Yomu: 2026-09-09T14:26:38.082Z

[Read original post](https://www.heroku.com/blog/completing-autocomplete)
