dsh-direnv: Enabling DSH Child Processes to Inherit direnv Environment Based on Working Directory

Preface

In DeepSeek Harness (DSH), models execute commands within the repository using tools like shell and subprocess. If a project uses direnv to manage .envrc, tools such as cargo or variables like DATABASE_URL are often already available in your local terminal. However, the subprocesses launched by Harness by default may not inherit this same environment. Common workarounds involve manual exports, writing wrappers, or repeatedly reminding the model to “source first” during conversations. dsh-direnv takes over the Harness subprocess seam, executing direnv export json based on the actual working directory of each spawn. It merges the differences into the subprocess environment, allowing different directories within the same session to correspond to their respective direnv states.

What is this

dsh-direnv is a community plugin maintained by Snowy117, categorized under Workflow in the DSH plugin directory. In short: it enables DSH to automatically load direnv for every workspace (based on the resolved cwd), eliminating the need for manual activation before every command. The plugin does not execute direnv allow for you; .envrc files must still be approved beforehand according to standard direnv conventions.

  • Directory Page: https://www.skillhub.cn/plugins/Snowy117/dsh-direnv
  • Source Code & Docs: https://github.com/Snowy117/dsh-direnv
  • License: MIT (see repository package.json)

The community directory is an independent site with no official affiliation with DeepSeek or High-Flyer. The DSH ecosystem philosophy is “everything is a plugin,” and this plugin extends official subprocess capabilities via bundle patches.

Core Functionality

The README summarizes the behavior into three distinct paths sharing the same data source, without blocking one another:

Path Behavior
Injection On spawn, it looks up the direnv diff from the cache based on the directory and merges it into the subprocess environment. Unknown directories are forwarded as-is initially, with evaluation happening asynchronously in the background; spawnTerminal (PTYs you open) waits for evaluation to complete before spawning.
Gate When the session environment is not yet known, tool calls are briefly held—the model can still chat and request tools, but the call waits as if the tool itself were slow. The gate waits for a maximum of loadTimeoutMs per session; it releases upon timeout, determined results, or cancellation, and does not cancel ongoing direnv evaluation.
Surfaces Sends a notice with provenance to the model (explaining what was loaded); a sidebar tab displays variable names, PATH diffs (added/removed/unchanged), and a list of credentials. The UI components come from DSH itself to follow the theme.

The anchor is the resolved cwd of each spawn: if a command cds into a subdirectory, that subdirectory’s environment is used; any .envrc changes take effect on the next tool call.

Coverage (README Limits): Harness’s shell, subprocess, search, git, and PTY consumers utilize this seam; MCP SDK or host-process-side spawns do not go through this path. It occupies only one subprocess provider slot; if replaced by another provider, the plugin will report a distinct error.

Installation and Enablement

Prerequisites: direnv must be on your local PATH, and the plugin will not run direnv allow for you.

  1. Verify direnv is available:
direnv version

If this fails, please install direnv first before proceeding.

  1. Install the plugin (official README command):
dsh plugin add dsh-direnv

The README also notes: when installing from a local checkout, you must first build lib/ (since exports points to that directory):

npm install && dsh plugin add "file:$PWD"
  1. Confirm the patch has landed; you should expect to see disabled: true (as stated in the README, indicating the existence of the subprocess-related patch entry):
dsh --profile <name> --dump-config | grep -A3 'id: subprocess'

package.json declares Node >=22.18 and has a peer range for @deepseek-ai/dsh-subprocess-local. If you see dsh: skipping profile bundle "dsh-direnv" on startup, you need to upgrade DSH or use dsh plugin allow-version (see Troubleshooting).

Default configuration snippet (adjustable in the profile by id direnv-subprocess):

- id: direnv-subprocess
  name: 'dsh-direnv'
  config:
    enabled: true
    direnvPath: ''            # If empty, resolves direnv from PATH
    loadTimeoutMs: 300000     # Max time to wait for tool calls before proceeding anyway
    evaluateTimeoutMs: 0      # Kill direnv subprocess on timeout (0 = never kill)
    gateTools: all            # all | spawning | none
    injectSensitive: all      # all | filter
    notifyModel: true         # One sourced message per workspace state change
    sidebar: true             # Sidebar tab and composer placeholder
    disabledDirs: []          # List of absolute paths to ignore

injectSensitive: filter withholds variables with names resembling credentials (/KEY|PASSWORD|SECRET|TOKEN/i); this is useful for cautious scenarios but may break dev shells that rely on these variable names.

Typical Usage

The README uses a directory tree to illustrate behavior: when running dsh web under ~/.dsh (with no .envrc there), once the session enters ~/projects/api, commands like bash: build should carry the cargo, DATABASE_URL, etc., provided by that directory’s direnv.

To verify it works:

  1. Open a session in a workspace with an approved .envrc.
  2. Ask the model to execute (replace SOME_VAR_YOUR_ENVRC_SETS with a variable name set in your .envrc):
bash -c 'echo $SOME_VAR_YOUR_ENVRC_SETS'
  1. Check the direnv tab in the right sidebar: status, variable names, and PATH diffs ranked by priority.

If step 2 outputs nothing, the environment was not loaded. Check Troubleshooting and the sidebar tab (statuses like blocked, unreadable, absent are reported separately).

Applicable Scenarios and Notes

Who it is for: Teams with multiple repositories, multiple flakes/devshells, or independent .envrc files in subdirectories; those who want commands executed by the model in DSH to match the shell environment after direnv loads in that directory, without repeating exports in the prompt.

Security and Permissions (README Security is mandatory reading):

  • .envrc is arbitrary code; it runs bash under your user identity during evaluation. The plugin only evaluates files that direnv would evaluate anyway and will not approve them for you. Check the source code and MIT license before installing, and understand that the plugin runs with the permissions of the current dsh process.
  • Variable values do not enter the model context in plaintext by default; notices only contain counts, paths, and warnings. Specific values are revealed in the sidebar on demand.
  • By default, injectSensitive: all, meaning credential-shaped variable names enter the command environment (layered on top of the environment already scrubbed by Harness). If you need to be conservative, set filter, but this may break dependencies.
  • Before evaluation, all DIRENV_* variables are stripped from the environment passed to direnv to prevent “resurrecting” scrubbed variables when starting Harness from a shell where direnv has already been loaded.

Common Silent Failures (excerpt): The entire package is skipped due to peer mismatch; the patch did not land after @deepseek-ai/dsh-base; lib/ is missing because npm install was not run during checkout installation; Web clients require dsh.client.platform to be exactly "web" and the inject package name to match precisely, otherwise the sidebar tab may not appear. Both startup logs and --dump-config stderr should be checked—their predictive capabilities are not identical.

Other Limitations: Unreadable .envrc files can be difficult to distinguish from “no .envrc” in terms of output; a failed .envrc may have already applied some variables (degraded status is reflected in notices and the sidebar).

Conclusion

dsh-direnv connects direnv’s “directory-specific environment walking” to DSH’s subprocess layer. The installation command is dsh plugin add dsh-direnv, provided that direnv is already installed locally and .envrc files in various directories have been allowed according to convention. If you are already using direnv to manage development environments, you can verify the integration in a DSH session by comparing variable echoes with the right-hand direnv tab.

  • Plugin Directory: https://www.skillhub.cn/plugins/Snowy117/dsh-direnv
  • GitHub: https://github.com/Snowy117/dsh-direnv
羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

Xiaoye