Skip to content

Separate PAI installation from CC config: CLAUDE_CONFIG_DIR + PAI_DIR=~/.pai #98

@virtualian

Description

@virtualian

Motivation

PAI_DIR currently conflates two concerns: Claude Code's config root (~/.claude) and PAI's installation root (~/.claude/PAI/). This prevents PAI from being installed independently of CC's config directory and makes PAI_DIR's name a lie — it points to the Claude home, not the PAI directory.

Goal: Use the official CLAUDE_CONFIG_DIR for CC config and make PAI_DIR user-configurable at install time, defaulting to ~/.pai.

Architecture

Env Vars After Separation (Two Variables Only)

Variable Purpose Default settings.json
CLAUDE_CONFIG_DIR CC config root ~/.claude env.CLAUDE_CONFIG_DIR (literal absolute)
PAI_DIR PAI installation root (redefined) ~/.pai env.PAI_DIR (literal absolute)
PAI_CONFIG_DIR XDG user preferences ~/.config/PAI Unchanged

Live-tested (2026-04-06): Setting CLAUDE_CONFIG_DIR in settings.json env makes it available to hook commands via shell expansion. It does NOT relocate CC's config directory (CC has already found settings.json by that point). No third variable needed.

What Stays vs What Moves

Stays at CLAUDE_CONFIG_DIR (~/.claude):

  • hooks/ — CC discovers hooks from its config dir
  • MEMORY/ — session state, per-project memory
  • settings.json, CLAUDE.md, projects/

Moves to PAI_DIR (~/.pai):

  • PAI/ — tools, algorithms, documentation
  • skills/ — skill definitions
  • agents/ — agent definitions
  • PAI-Install/ — installer engine
  • VoiceServer/ — voice notification server

Critical Constraint: Hook Command Paths

settings.json hook commands use ${PAI_DIR}/hooks/ (27 references). Changing PAI_DIR breaks hook discovery. Solution: Add CLAUDE_CONFIG_DIR to settings.json env; migrate hook commands from ${PAI_DIR}/hooks/ to ${CLAUDE_CONFIG_DIR}/hooks/ before changing PAI_DIR.

paths.ts Redesign

getConfigDir()  → CLAUDE_CONFIG_DIR || ~/.claude
getPaiDir()     → PAI_DIR || ~/.pai
configPath(...) → getConfigDir() + segments  (hooks, MEMORY, settings)
codePath(...)   → getPaiDir() + segments     (PAI/Tools, Algorithm, docs)
paiPath(...)    → DEPRECATED → configPath()

File Audit

Category Files References
settings.json 1 28 (1 def + 27 hook cmds)
Hook TS files 15 ~20 relative imports
PAI Tool scripts 27 ~70 path constructions
PAI documentation 12 102 hardcoded paths
Installer/build 18 120+ references
Config (CLAUDE.md etc) 3 ~10 references
Skill files 3 ~16 references
Total 79 ~366

Static Dependencies (Cannot Use Env Vars)

Location Why
settings.json env values CC doesn't expand shell vars — must be literal absolute paths
settings.json additionalDirectories Literal paths required
~/.claude.json OAuth state, ignores CLAUDE_CONFIG_DIR entirely

Execution Plan

Pre-Migration Gate — PASSED ✅

  • Add CLAUDE_CONFIG_DIR to settings.json env, change one hook command to use it, verify it fires

Phase 0: Centralise Imports

  • Convert 15 hook files' relative ../PAI/Tools/ imports to use paths.ts resolvers
  • Zero directory changes, zero breakage

Phase 1: Add CLAUDE_CONFIG_DIR + Update paths.ts

  • Add CLAUDE_CONFIG_DIR to settings.json env
  • Add getConfigDir(), configPath(), codePath() to paths.ts
  • Write resolution tests for fallback chain
  • Migrate 27 hook commands from ${PAI_DIR}/hooks/ to ${CLAUDE_CONFIG_DIR}/hooks/

Phase 2: Copy PAI Code + Redefine PAI_DIR

  • Copy PAI/, skills/, agents/, PAI-Install/, VoiceServer/ to ~/.pai/
  • Update settings.json env.PAI_DIR to ~/.pai
  • Update CLAUDE.md hardcoded paths
  • Update PAI Tool scripts

Phase 3: Validate + Documentation

  • Verify all hooks fire correctly
  • Verify loadAtStartup, Algorithm loading, Notify.ts
  • Bulk-replace documentation paths
  • Update installer templates

Phase 4: Cleanup

  • Remove old PAI code from ~/.claude/ after 2-week validation
  • Optional: symlink old locations for safety

Rollback

At any phase: Set PAI_DIR back to ~/.claude in settings.json. Old code never left during Phases 0-3. One-line revert, under 60 seconds.

Pre-migration backup:

tar czf ~/tmp/pai-pre-migration.tar.gz ~/.claude/settings.json ~/.claude/hooks/ ~/.claude/PAI/ ~/.claude/skills/ ~/.claude/agents/ ~/.claude/CLAUDE.md

Council Report

See reports/2026-04-06-council-claude-config-dir-pai-dir-separation.md for the full 3-round debate transcript and detailed analysis.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions