Skip to content

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

Open
IstPlayer wants to merge 5 commits into
backnotprop:mainfrom
IstPlayer:feat/plannotator-data-dir-env-var
Open

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

Conversation

@IstPlayer
Copy link
Copy Markdown

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.

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.
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