6 Lesser-Known Heroku CLI Commands You Probably Aren’t Using
- Last Updated: August 25, 2026
Every time you move your hands off the keyboard to reach for the mouse, your engineering velocity drops. Clicking through web UIs to find an environment variable feels fast in the moment, but those micro-interruptions steadily chip away at your focus and disrupt your workflow.
The cost of context switching adds up fast. Bouncing between your terminal and browser breaks your stride, and if a quick check derails into a secondary distraction, regaining your focus takes far longer than just switching windows. Over a standard sprint, those context switches can cost you hours.
Improving developer experience in the command line relies on minimizing these context switches. While most engineers use the Heroku CLI strictly for basic tasks like pushing code, it contains a powerful suite of command line tools built to optimize your terminal workflow. If you want to keep your focus locked on writing code, these six Heroku CLI commands will instantly upgrade your daily productivity.
CLI tip 1: Export app configuration with heroku config
Setting up a local environment often means copying configuration variables one by one. You can bypass the tedious copying of keys and values from the web dashboard entirely using the CLI. The heroku config -s command prints your active variables as standard shell key-value pairs.
While pulling configuration values directly from a live production app is a dangerous anti-pattern, syncing from a dedicated sandbox or staging app is a massive workflow shortcut.
# Export all staging config vars directly and overwrite your local .env file
$ heroku config -s -a your-staging-app > .env
By appending > .env to the command, you pipe that output directly into a local environment file. Note that this completely overwrites any existing .env file you have in your directory. If you already have a working local setup and just need to pull down a newly added key, you can grab a specific variable and safely append it to the bottom of your file using >>.
# Pull a single variable and append it to your existing .env file
$ heroku config:get CONFIG-VAR-NAME -s -a your-staging-app >> .env
Always double check that your .gitignore includes the .env file so you do not leak credentials into version control. Read about config vars in our configuration documentation or learn more about your .env file and running apps locally.
CLI tip 2: Track active database queries with heroku pg:ps
When a Heroku Postgres database experiences a sudden performance degradation, the initial reaction is to open a browser tab to check an APM dashboard. If you try to troubleshoot from the terminal, you often end up writing complex queries against internal system tables inside a raw SQL prompt.
Running heroku pg:ps bypasses that friction entirely by inspecting your active database replica and listing every query currently executing on your Heroku Postgres instance.
$ heroku pg:ps
The output clearly displays how long each query has been running, its current execution status, and its exact backend process ID. This allows you to quickly isolate a rogue, unindexed query that might be locking up your tables before it impacts your users.
Most engineers view the CLI as just a basic gateway to connect to a raw prompt. Using this command gives you deep infrastructure intelligence instantly without forcing you to log into a web UI or parse raw log streams.
CLI tip 3: Secure live debugging with heroku ps:exec
When an application behaves erratically in production but works perfectly in your local sandbox, your logs do not always tell the whole story. You often need to inspect active application threads, profile sudden CPU spikes, or tail live framework logs inside the container.
Running heroku ps:exec establishes a secure SSH tunnel directly into a specific, running dyno inside your application cluster. This command connects your terminal session straight to the live container routing environment.
# Connect to a random web dyno in the cluster
$ heroku ps:exec
# Target a specific dyno instance for isolated debugging
$ heroku ps:exec --dyno=web.2
Unlike traditional server infrastructure, you do not have to manage complex SSH keys or puncture holes in your firewalls to get diagnostic access. The traffic moves securely through an encrypted channel managed automatically by the platform.
This gives you a powerful tool to make runtime thread dumps or profile resource usage under true production loads. You can diagnose the exact state of your application without impacting your live user traffic or altering your deployment package.
CLI tip 4: Fire and forget tasks with heroku run:detached
When executing heavy administrative tasks like migrating a large production database, running a love-lived cleanup script, or backfilling data, a standard terminal session using heroku run introduces unnecessary risk. If your local machine goes to sleep or your Wi-Fi drops, the remote process is terminated. This can leave your production system in an inconsistent or partially complete state.
Using heroku run:detached solves this problem. This command tells the platform to spin up a worker container, inject your execution script, and run the process entirely in the background.
# Execute a heavy database migration script in the background
$ heroku run:detached rake db:migrate
Running rake db:migrate... up, run.1234
Use 'heroku logs --dyno run.1234' to view the log output.
# Stream the logs from a detached background task
$ heroku logs --dyno run.1234 --tail
Because the task’s execution is fully decoupled from your local machine, you can safely close your laptop or disconnect from the internet without worry. The command line tools output a unique container ID that you can use to stream or audit the progress using your log streams at a later time.
CLI tip 5: Speed up commands with heroku autocomplete
Typing out full application names, specific flag combinations, or long add-on identifiers manually slows you down when using the Heroku CLI. Friction increases even more when you have to constantly run list commands to remember the exact spelling of a resource.
Using native shell autocomplete eliminates this cognitive overhead entirely. This built-in configuration updates your local terminal environment to dynamically predict and complete your Heroku commands as you type.
# Install and configure autocomplete for your active shell
$ heroku autocomplete
# Refresh the local cache after adding new apps or addons
$ heroku autocomplete:refresh
Once configured, hitting the tab key twice suggests available commands, flags, and application names matching your current context. The terminal handles the tedious lookup work behind the scenes, allowing you to move through deployment tasks without leaving your current command line flow state.
CLI tip 6: Open add-on dashboards instantly with heroku addons:open
When you need to check a third-party service attached to your app like a logging provider or monitoring tool) the typical workflow can be tedious. You open a browser, log into the Heroku dashboard, navigate to your app, and scroll through the overview tab to find the add-on dashboard link.
Using heroku addons:open cuts out that entire browser navigation sequence. This command authenticates your session and opens the target add-on’s web dashboard directly from your terminal.
# Launch the add-on dashboard
$ heroku addons:open papertrail
# Launch the add-on dashboard for a specific app
$ heroku addons:open papertrail -a example-app
You can append the -a flag to specify an app explicitly if managing multiple environments like staging and production or working outside of your project directory. The CLI opens the dashboard directly in your browser, keeping you focused on troubleshooting instead of clicking through web menus.
Upgrade your developer experience, one command at a time
These six Heroku CLI tips are just a sampling of what you can do with the Heroku CLI. You don’t need to change your entire routine overnight. Start using a command that solves your biggest daily annoyance and expand from there.
Using the Heroku CLI keeps you more focused in the terminal window instead of getting sidetracked in browser tabs. To explore the full scope of what you can control and automate, dig into the Heroku CLI command reference.
- Originally Published:
- CLIDeveloper Tools