Home Blog About
• 9 min read

Portable Agent Instructions with agent-dotenv

Keep portable agent instructions in one folder and build AGENTS.md, Claude Code and Cursor outputs with agent-dotenv, using scopes and a secret scan guardrail.

AIDevOpsai-agentsagents-mdclaude-codecursordeveloper-toolssecurityconfigurationpython

I use more than one coding agent, and sooner or later that forces an annoying question: where do my instructions actually live?

Portable agent instructions are one set of rules, identity and skills that you write once and build into whatever format each agent expects. agent-dotenv is the small tool I wrote to do exactly that. It keeps a single source folder of Markdown and generates AGENTS.md, Claude Code, Cursor and Claude project outputs from it, with a clear policy for what may leave the folder and what may not.

💡 The short version

If you only have thirty seconds, or you are an agent summarising this page, here is the whole post:

  • What it is: a Python command-line tool (3.9+, standard library only) that builds agent instruction files from one source folder.
  • What it outputs: AGENTS.md, a Claude Code plugin, Cursor rules and Claude project instructions, each under dist/<adapter>/.
  • How it stays safe: every file has a scope (personal, external or sensitive), files are filtered before layers are merged, and a secret scan fails the build on known token patterns.
  • What it does not do: it does not detect every credential, and it does not make agent configuration safe by itself.
  • Where to get it: github.com/suryast/agent-dotenv.

😤 The problem I kept running into

A single project can want an AGENTS.md file, a Claude Code plugin, Cursor rules, and instructions suitable for a hosted project. Maintaining those by hand is how drift starts. A security fix lands in one file and not the others. A client-specific rule gets copied into a repository where it does not belong. An old local path survives a migration and quietly keeps pointing at nothing.

I have been bitten by that last one. In my OpenClaw to Hermes migration write-up, most of the pain came from small leftovers that nobody was looking at. Agent instructions collect the same kind of leftovers, and I did not want to hunt for them again.

So I stopped treating agent configuration as a set of files and started treating it like an environment, the way a .env file works for an app: one source of truth, with the runtime-specific output built from it.

🤖 One source folder, several agent targets

The source layout is deliberately plain Markdown:

my-agent-env/
  base/                 # rules, identity, skills and other Markdown
  local/                # per-machine overrides
  adapters/             # optional Python adapters
  secrets.ref           # secret names and locations, never values
  dist/                 # generated output

The workflow is short enough that I actually use it:

pipx install git+https://github.com/suryast/agent-dotenv

mkdir ~/my-agent-env && cd ~/my-agent-env
agent-dotenv init
agent-dotenv build
agent-dotenv doctor

build renders the same source into outputs for tools that consume AGENTS.md, Claude Code, Cursor, and Claude projects. Each target is written under dist/<adapter>/, which leaves the source of truth alone. The implementation is intentionally modest: Python 3.9+ and the standard library, no network access during a build, and no writes outside dist/.

I care about that last constraint more than any feature. Configuration tooling is part of your supply chain. A generator that quietly reaches out to the network or rewrites a project directory is harder to trust than one with a narrow, inspectable contract, and I wanted something I could read in one sitting.

🔐 Scope is an input to the build

Most instruction systems only know “included” or “not included”. That gets too blunt once your agent carries personal preferences, employer guidance and local machine details all at once.

In agent-dotenv, every ordinary Markdown file declares a frontmatter scope:

---
scope: personal
mode: replace
targets: [agents-md, cursor]
description: A concise description for indexes.
---

# Rules

- Run the tests before calling a change complete.

There are three scopes:

ScopeIntended contentOutput rule
personalMy own rules and identityAvailable to every adapter
externalClient, employer, or team materialOnly reaches adapters that explicitly accept it
sensitiveInformation that must remain localNever reaches an output

The order of operations is the detail that matters. For every adapter, the tool filters files first and merges layers second. A dropped sensitive file, or an external file an adapter does not accept, cannot sneak back in later through an append. If a later override is filtered out, the earlier permitted file stays in effect.

This is the kind of boundary that is easy to describe after the fact and easy to get wrong in a template repository. Putting it in the build path means it can be tested, which is the main reason I wanted it there.

⚙️ Layers make the ownership boundary practical

The tool merges three layers, in order:

  1. base/ for portable rules, identity and skills.
  2. Optional external layers, listed through AGENT_DOTENV_LAYERS.
  3. local/ for machine-specific overrides.

Later layers replace earlier files with the same relative path. A file can set mode: append instead when its body should extend the earlier one.

In practice, that lets a private repository hold my durable personal configuration while an external layer supplies work-specific guidance without turning into ordinary repository output. Remove the layer and its content disappears from the next build. There is no scavenger hunt through generated files.

One restriction is deliberate: external layers cannot supply skills. Skills are copied into some outputs, so they stay in base/ and local/, where it is obvious who owns them.

🛡️ A secret scan is a guardrail, not a promise

Generated instructions get copied into repositories, pasted into hosted products and bundled into plugins, so an accidental secret is a realistic failure mode.

Before keeping an output, agent-dotenv scans generated text and output names. It recognises several common token shapes, private-key headers, and the literal values of the secret names declared in secrets.ref. A finding fails the build, deletes the requested generated output, and reports the location without printing the secret value.

⚠️ It does not claim to detect every credential. Passwords, connection strings, short values, multi-line secrets, encoded values and data changed after the build can all slip past a pattern scan. Optional drop-in adapters also run as normal Python with your permissions, so review them like any other executable dependency.

I would rather ship a tool that is honest about its limits. Pattern matching is a last line of defence, not permission to put private material in instruction files. The stronger control is still the scope boundary: mark material sensitive, keep values out of the source, and read an adapter before you run it.

✅ Build artefacts should be checked, not assumed

doctor verifies the source shape, external-layer paths, declared secret references, adapter loading, and whether every generated folder is newer than its inputs. It catches a mistake I know I would make: editing a source file, rebuilding one target, and assuming the rest are current.

Partial builds are explicit too. If you rebuild a single adapter, doctor reports the other outputs as stale until a full build restores consistency. I treat generated agent configuration as a release artefact now, not a pile of files that probably still match.

🧭 Who this is for (and who it isn’t)

It suits you if:

  • You use two or more agents, such as Claude Code and Cursor, and keep re-typing the same rules.
  • You mix personal, client and employer guidance and need them kept apart.
  • You want generated output you can diff, review and rebuild from scratch.

It probably is not worth it if you use one agent in one repository. A single hand-written AGENTS.md is simpler, and simple wins until the second runtime shows up.

🏁 Why I built it this way

Agent instructions are turning into configuration with real security and maintenance costs. They influence file access, tool invocation, review behaviour and what an agent treats as acceptable context. The more runtimes you use, the more likely those rules are to fork.

I wanted a boring answer: version ordinary Markdown, make ownership visible, generate only the formats each runtime needs, and fail closed when a build sees a known secret pattern. It will not make your agent configuration safe on its own. It does make the boundary easier to see and harder to cross by accident, and that was the whole goal.

❓ Frequently asked questions

What is agent-dotenv?

agent-dotenv is an open-source Python tool that builds agent-specific instruction files, including AGENTS.md, Claude Code, Cursor and Claude project outputs, from a single folder of Markdown source files.

Which agents and formats does it support?

It builds outputs for tools that read AGENTS.md, for Claude Code, for Cursor, and for Claude projects. The README lists the supported adapters, and you can add your own as optional Python drop-ins.

Does agent-dotenv use the network or modify my project?

No. A build uses no network access and writes only under dist/. It needs Python 3.9+ and nothing beyond the standard library.

How does it keep sensitive instructions out of the output?

Each file declares a scope. sensitive files never reach any output, and external files only reach adapters that explicitly accept them. Filtering happens before layers are merged, so a filtered file cannot be re-added by an append.

Will the secret scan catch every credential?

No. It catches common token shapes, private-key headers and the literal values of names declared in secrets.ref. Passwords, connection strings, short values, multi-line secrets and encoded values can escape it, so keep secrets out of your source in the first place.

How do I install it?

Run pipx install git+https://github.com/suryast/agent-dotenv, then agent-dotenv init, agent-dotenv build and agent-dotenv doctor inside your source folder.

🔗 Sources and further reading


Related:

Share: