Skip to content

feat: add PLANNOTATOR_DATA_DIR env var to customize data directory#795

Merged
backnotprop merged 10 commits into
backnotprop:mainfrom
IstPlayer:feat/plannotator-data-dir-env-var
May 26, 2026
Merged

feat: add PLANNOTATOR_DATA_DIR env var to customize data directory#795
backnotprop merged 10 commits into
backnotprop:mainfrom
IstPlayer:feat/plannotator-data-dir-env-var

Conversation

@IstPlayer
Copy link
Copy Markdown
Contributor

Summary

Add a PLANNOTATOR_DATA_DIR environment variable that allows users to relocate the Plannotator data directory (default: ~/.plannotator) to any path they prefer.

Motivation

Plannotator currently hardcodes ~/.plannotator/ as the base data directory in multiple places — storage.ts, config.ts, draft.ts, improvement-hooks.ts, sessions.ts, codex-review.ts, tour-review.ts, browser.ts, and pr-gitlab.ts. This clutters the home directory and conflicts with XDG conventions (XDG_DATA_HOME, XDG_CACHE_HOME, etc.) that many users follow to keep their home directories clean.

The PASTE_DATA_DIR env var already exists as precedent for customizing sub-paths. This PR extends that pattern to the entire data directory.

Changes

  • New file: packages/shared/data-dir.ts — shared helper getPlannotatorDataDir() that checks PLANNOTATOR_DATA_DIR first (with ~ expansion), falls back to ~/.plannotator
  • 9 source files updated: all hardcoded join(homedir(), ".plannotator", ...) calls replaced with getPlannotatorDataDir()
  • Unused homedir imports removed where possible

Usage

# Move all Plannotator data to ~/.cache
export PLANNOTATOR_DATA_DIR=~/.cache/plannotator

# Or to an XDG-compliant location
export PLANNOTATOR_DATA_DIR=$XDG_DATA_HOME/plannotator

Backward Compatibility

Default behavior is unchanged — when PLANNOTATOR_DATA_DIR is absent or empty, the data directory remains ~/.plannotator.

IstPlayer and others added 2 commits May 26, 2026 13:04
OpenCode plugin and VS Code extension still used hardcoded
~/.plannotator paths, causing the IPC registry and plan backing
file to diverge from the server when PLANNOTATOR_DATA_DIR is set.

Also exports data-dir from @plannotator/shared and documents the
new env var in AGENTS.md.

Co-authored-by: Chris Werner Rau <14326070+cwrau@users.noreply.github.com>
Co-authored-by: João O. Santos <34689526+Joao-O-Santos@users.noreply.github.com>
@backnotprop
Copy link
Copy Markdown
Owner

Thanks for the PR @IstPlayer — clean approach and the right default behavior (nothing changes unless you explicitly set the env var).

I pushed a fix commit (46df9f7a) addressing the two files that still had hardcoded ~/.plannotator paths:

  • apps/opencode-plugin/index.tsgetPlanBackingPath() now uses getPlannotatorDataDir() instead of homedir() + ".plannotator". Without this, OpenCode's active plan backing file would ignore PLANNOTATOR_DATA_DIR.
  • apps/vscode-extension/src/extension.ts — The IPC_REGISTRY path now resolves through the same env var logic. The VS Code extension is a standalone build (can't import from @plannotator/shared), so the resolution logic is inlined. Without this fix, the extension and server would disagree on the IPC registry location when PLANNOTATOR_DATA_DIR is set.
  • packages/shared/package.json — Added the "./data-dir" export so the OpenCode plugin can import it as @plannotator/shared/data-dir.
  • AGENTS.md — Documented PLANNOTATOR_DATA_DIR in the env var table.

For context: There are two other open PRs tackling the same problem with different approaches:

This PR (#795) is the simplest and safest of the three — one env var, opt-in only, zero risk for anyone who doesn't set it. The co-author trailers on the fix commit credit @cwrau and @Joao-O-Santos since their work helped identify the full scope of files that needed updating.

backnotprop and others added 8 commits May 26, 2026 09:16
The Pi extension copies shared/server modules into generated/ at
build time. Without vendoring data-dir.ts and rewriting the
parent-relative imports, typecheck fails on all generated files
that import getPlannotatorDataDir.
- VS Code extension: replace inlined getPlannotatorDataDir() copy with
  import from the canonical packages/shared/data-dir.ts (esbuild bundles
  it, so no runtime dependency needed)
- storage.ts: hoist repeated getPlannotatorDataDir() calls to a
  module-level DATA_DIR constant, matching the pattern config.ts uses
- data-dir.ts: remove inaccurate docstring claim about relative path
  resolution (the code does not call resolve())
- improvement-hooks.ts: hoist to DATA_DIR constant, clarify comments
  on the two-level hook lookup (hooks/ subdir vs root fallback)
A relative value like ./data would break readArchivedPlan's path
traversal guard, which compares a resolve()'d absolute path against
the still-relative planDir prefix. Always return an absolute path
so all callers get consistent path shapes.
Switch from relative ../shared/data-dir imports to the package
export, matching the convention every other server file follows.
Update Pi vendor script sed rules to match the new import style.
…kill

Server modules: switch from relative ../shared/data-dir imports to
@plannotator/shared/data-dir, matching the convention every other
server file follows. Update Pi vendor script sed rules to match.

Compound skill: update hardcoded ~/.plannotator paths to check
PLANNOTATOR_DATA_DIR first, so the skill reads plans and writes
the improvement hook to the correct location when users set a
custom data directory.

Co-authored-by: Chris Werner Rau <14326070+cwrau@users.noreply.github.com>
Co-authored-by: João O. Santos <34689526+Joao-O-Santos@users.noreply.github.com>
- Settings UI: replace hardcoded path in label and placeholder with
  generic text that doesn't assume a specific data directory
- quickLabels: update agent tip to reference PLANNOTATOR_DATA_DIR
  so the agent checks the correct plans directory
- codex-review: hoist getPlannotatorDataDir() to module-level DATA_DIR
  constant, eliminating redundant per-call resolution in debugLog()
- Tests: make submit-plan and storage tests resilient to
  PLANNOTATOR_DATA_DIR being set in the environment
- Install scripts (sh, ps1, cmd): check PLANNOTATOR_DATA_DIR before
  falling back to ~/.plannotator for config.json attestation lookup
install.sh: PLANNOTATOR_DATA_DIR set to ~/... stays literal inside
double quotes, so the config file check silently failed. Add case
statement to expand ~ the same way the runtime data-dir.ts does.

install.test.ts: update three assertions that checked for hardcoded
~/.plannotator paths — now verify PLANNOTATOR_DATA_DIR awareness
instead.
Document the new env var on the marketing site's environment
variables reference page. Include a footnote about ensuring
VS Code inherits the variable when launched from the Dock.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants