agentleFS
Cogni-AI-OUCogni-AI-OU/cogni-ai-agent-skills/direnv/SKILL.md

direnv

Skill4 starsChanged 6 months agoMITView on GitHub

How to maintain credentials and authenticate using direnv without exposing secrets to the output.

  • Reads credentials

2 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

9 rules. About 0 are common, 2 are distinctive, and 7 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 7

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Authorize Directory: Run direnv allow <path-to-env-dir> to approve the environment variables.

    line 15
  2. Very specific:

    Export Variables: Run eval "$(direnv export bash)" to inject the variables into the current session.

    line 16
  3. Distinctive:

    Security Focus: Never print, echo, or expose API keys and secrets in the terminal output.

    line 20
  4. Very specific:

    Session Persistence: Always follow direnv allow with eval "$(direnv export bash)" to ensure the agent's shell session properly loads the …

    line 21
  5. Distinctive:

    When you need to automatically load environment variables upon entering a specific project directory.

    line 25
  6. Very specific:

    When an agent needs to execute commands that depend on project-specific credentials stored in .env.

    line 27
  7. Very specific:

    When running commands in isolated, ephemeral Docker containers where environment variables are passed via --env-file.

    line 33
  8. Very specific:

    Do not manually source or cat .env files.

    line 63
  9. Very specific:

    Do not run direnv allow without immediately running eval "$(direnv export bash)" within the same execution context.

    line 64

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Skill: direnv

<!-- markdownlint-disable MD013 MD023 MD031 MD032 -->

Guidance for using direnv to securely maintain credentials and load environment variables without exposing them in agent outputs.

Core Process

  1. Setup Environment: Copy .env.example to .env if .env does not exist and needs configuration.
  2. Authorize Directory: Run direnv allow <path-to-env-dir> to approve the environment variables.
  3. Export Variables: Run eval "$(direnv export bash)" to inject the variables into the current session.

Core Principles

  • Security Focus: Never print, echo, or expose API keys and secrets in the terminal output.
  • Session Persistence: Always follow direnv allow with eval "$(direnv export bash)" to ensure the agent's shell session properly loads the variables, as standard direnv shell hooks may not be active.

When to Use

  • When you need to automatically load environment variables upon entering a specific project directory.
  • To safely manage API keys and secrets in local development without committing them to version control.
  • When an agent needs to execute commands that depend on project-specific credentials stored in .env.

When Not to Use

  • In production CI/CD pipelines where secrets are securely injected by the runner environment (like GitHub Actions secrets).
  • For managing global, system-wide environment variables (use ~/.bashrc or ~/.profile instead).
  • When running commands in isolated, ephemeral Docker containers where environment variables are passed via --env-file.

Common Pitfalls

  • Forgetting to Eval: Running direnv allow but forgetting to run eval "$(direnv export bash)", meaning the variables never actually load into the agent's current shell session.
  • Committing Secrets: Adding sensitive keys to .env but failing to ensure .env is listed in the project's .gitignore.
  • Assuming Global State: Expecting direnv variables to persist if the agent changes directories (cd ..), which naturally unloads them.

Commands / Usage Patterns

To authenticate when API keys are missing (e.g., loading from ../../):

direnv allow ../../
eval "$(direnv export bash)"

Full Workflow Example

Example usage for maintaining credentials and running commands from a subdirectory:

cp ../../.env.example ../../.env
# Edit ../../.env and set real values using file editing tools
direnv allow ../../
eval "$(direnv export bash)"

What to Avoid

  • Do not manually source or cat .env files.
  • Do not run direnv allow without immediately running eval "$(direnv export bash)" within the same execution context.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.