# shell-env

> Get environment variables from the shell

Latest version **4.0.3** (published 2026-02-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install shell-env
pnpm add shell-env
yarn add shell-env
bun add shell-env
```

## Health

**Score 65/100 (B)** — status: stable.

Positive: has types; esm support; no vulnerabilities; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 4.0.3 |
| Published | 2026-02-01 |
| First published | 2016-01-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Node | ^12.20.0 \|\| ^14.13.1 \|\| >=16.0.0 |
| Dependencies | 3 |
| Unpacked size | 6.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 87 |
| Author | Sindre Sorhus |
| Maintainers | sindresorhus |
| Keywords | env, environment, variable, shell, sh, zsh, bash, macos, electron |

## Links

- npm: https://www.npmjs.com/package/shell-env
- Repository: https://github.com/sindresorhus/shell-env
- Homepage: https://github.com/sindresorhus/shell-env#readme
- Issues: https://github.com/sindresorhus/shell-env/issues
- Funding: https://github.com/sponsors/sindresorhus
- npm.io page: https://npm.io/package/shell-env

## Dependencies (3)

- [execa](https://npm.io/package/execa.md) ^5.1.1
- [strip-ansi](https://npm.io/package/strip-ansi.md) ^7.0.1
- [default-shell](https://npm.io/package/default-shell.md) ^2.0.0

## Alternatives

- [replicas-cli](https://npm.io/package/replicas-cli.md) — 3.0K weekly downloads
- [env-contract](https://npm.io/package/env-contract.md) — 133 weekly downloads
- [@openveo/api](https://npm.io/package/@openveo/api.md) — 61 weekly downloads
- [@ryniaubenpm2/cumque-error-reiciendis](https://npm.io/package/@ryniaubenpm2/cumque-error-reiciendis.md) — 54 weekly downloads
- [ts-global-type-extra](https://npm.io/package/ts-global-type-extra.md) — 11 weekly downloads

## Recent versions

- 4.0.3 (latest) — 2026-02-01
- 4.0.2 — 2026-01-14
- 4.0.1 — 2021-09-13
- 4.0.0 — 2021-08-24
- 3.0.1 — 2021-01-17
- 3.0.0 — 2019-04-06
- 2.2.0 — 2019-02-01
- 2.1.0 — 2018-09-14
- 2.0.1 — 2018-06-20
- 2.0.0 — 2018-06-14
- 1.0.0 — 2017-12-15
- 0.3.0 — 2016-11-09
- 0.2.0 — 2016-07-30
- 0.1.2 — 2016-07-05
- 0.1.1 — 2016-02-03
- … 1 more at https://npm.io/package/shell-env/versions

## README

# shell-env

> Get [environment variables](https://en.wikipedia.org/wiki/Environment_variable) from the [shell](https://en.wikipedia.org/wiki/Shell_(computing))

Especially useful for Electron apps as GUI apps on macOS doesn't inherit the environment variables defined in your dotfiles *(.bash_profile/.zshrc/etc)*.

## Install

```sh
npm install shell-env
```

## Usage

```js
import {shellEnv} from 'shell-env';

console.log(await shellEnv());
//=> {TERM_PROGRAM: 'Apple_Terminal', SHELL: '/bin/zsh', ...}

console.log(await shellEnv('/bin/bash'));
//=> {TERM_PROGRAM: 'iTerm.app', SHELL: '/bin/zsh', ...}
```

## API

> [!NOTE]
> For Bash, it reads [`.bash_profile`, but not `.bashrc`](https://apple.stackexchange.com/questions/51036/what-is-the-difference-between-bash-profile-and-bashrc).

> [!NOTE]
> If your default shell is a non-POSIX shell (e.g., Nushell), it will fall back to `/bin/zsh` or `/bin/bash`.

> [!NOTE]
> It disables the oh-my-zsh tmux plugin auto-start by setting `ZSH_TMUX_AUTOSTARTED` and `ZSH_TMUX_AUTOSTART=false` so the shell does not launch tmux while capturing environment variables.

### shellEnv(shell?)

Return a promise for the environment variables.

### shellEnvSync(shell?)

Returns the environment variables.

#### shell

Type: `string`\
Default: [User default shell](https://github.com/sindresorhus/default-shell)

Shell to read the environment variables from.

## Related

- [shell-path](https://github.com/sindresorhus/shell-path) - Get the $PATH from the shell
- [fix-path](https://github.com/sindresorhus/fix-path) - Fix the $PATH on macOS when run from a GUI app
- [shell-history](https://github.com/sindresorhus/shell-history) - Get the command history of the user's shell

## Maintainers

- [Sindre Sorhus](https://sindresorhus.com)
- [@silverwind](https://github.com/silverwind)

---
_Source: https://npm.io/package/shell-env · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
