Autocompletion for Swift Package Manager Commands

I am a Software Engineer working on open source and enterprise mobile SDKs for iOS and MacOS developers written in Swift. From 🇩🇪 and happily living in 🇺🇸
Search for a command to run...

I am a Software Engineer working on open source and enterprise mobile SDKs for iOS and MacOS developers written in Swift. From 🇩🇪 and happily living in 🇺🇸
No comments yet. Be the first to comment.
WWDC26 kicked off on June 8, 2026. The information in this article reflects the information published by Apple on that date. There are 14 new frameworks. Name Description AccessoryAccess Manage

WWDC25 kicked off on June 9, 2025. The information in this article reflects the information published by Apple on that date. New Frameworks NameDescription AlarmKitSchedule prominent alarms and countdowns to help people manage their time. AVR...

WWDC25 is almost here, and I couldn’t be more excited! Whether you're attending the official events, community meetups, or just soaking in the energy around Cupertino, there’s no better time to connect, share ideas, and celebrate everything we love a...

In this blog post, I’ll share an observation and advice regarding the caching behavior of network responses by Apple’s APIs. If you are unfamiliar with caching of network responses then I recommend Apple’s article Accessing cached data that introduce...
WWDC24 kicked off on June 10, 2024. The information in this article reflects the information published by Apple on that date. New Frameworks NameDescription AccessorySetupKitUse AccessorySetupKit to discover accessories with Bluetooth or Wi-Fi...

This blog post will explain how you can leverage autocompletion for Swift Package Manager commands in your shell by using a completion script that can be generated by SwiftPM. This is helpful for people who just started to use Swift Package Manager but also for people who want to speed up their productivity.
I am using the Z shell (ZSH), but most of my explanation will also work if you use another type of shell, e.g. bash.
When you type a command in your shell and hit the TAB key, a completion is attempted depending on the context. This context includes:

The context is then given to one or more completer functions that attempt to complete what you’ve typed. Each of these completers are tried in order and, if the first one can’t complete the context, the next one will try. When the context can be completed, some possible matches will be displayed and you can choose whatever you want. ... [Source]
Swift Package Manager ships with tooling to generate such a completer.

If you are using Oh My Zsh, community-driven framework for managing your zsh configuration, then the installation can be even simplified. Oh My Zsh comes with a plugin that
| Alias | Description | Command |
spi | Initialize a new package | swift package init |
spf | Fetch package dependencies | swift package fetch |
spu | Update package dependencies | swift package update |
spx | Generates an Xcode project | swift package generate-xcodeproj |
sps | Print the resolved dependency graph | swift package show-dependencies |
spd | Print parsed Package.swift as JSON | swift package dump-package |
All you need to do is to add the swiftpm plugin to your plugins array in ~/.zshrc:
plugins=(... swiftpm)
What follows was observed when I wrote this article (August 2022), but I eventually contributed to SPM to get this completion-tool fixed in a future version of a Swift release (beyond Swift 5.7)
If you cannot wait the ohmyzsh has already a working auto-completion script reflecting Swift 5.7
A word of caution: The bundled ZSH completion script in the swiftpm plugin was generated with Swift 5.1 and therefore may not include all subcommands or options available in your local installation.
I tried to generate the _swift completion script with Swift 5.6.1
swift package completion-tool generate-zsh-script > ~/.oh-my-zsh/completions/_swift
but the generated script is incorrect and throws errors during auto-completion :(
I addressed the issue with Apple and hope for a quick resolution.