Configuration

Configure Phantom with config files, hooks, templates, and environment variables.

Phantom can be configured via YAML config files, environment variables, and command-line flags. This page covers all configuration options.

Config File

The main configuration file is located at ~/.phantom/config.yaml. You can create it with:

phantom init

Default Configuration

# Phantom Configuration
# Generated by: phantom init

# Base directory for all Phantom data
data_dir: ~/.phantom

# Overlay settings
overlays:
  # Directory where overlays are stored
  dir: ~/.phantom/overlays

  # Directory where overlays are mounted
  mount_dir: ~/.phantom/mnt

  # Default timeout for agent runs
  default_timeout: 30m

  # Maximum number of parallel overlays
  max_parallel: 5

# Git settings
git:
  # Auto-commit after agent finishes
  auto_commit: true

  # Default branch prefix
  branch_prefix: phantom/

  # Push on apply
  push_on_apply: false

# Hooks (global)
hooks:
  on_success: []
  on_failure: []
  on_complete: []

# Logging
logging:
  # Log level: debug, info, warn, error
  level: info

  # Log file location
  file: ~/.phantom/phantom.log

# Agent defaults
agents:
  # Default agent command
  default: claude --print

  # Timeout for individual agents
  timeout: 30m

# Projects mapped to absolute paths
projects:
  myapp: "/Users/user/Projects/myapp"

Configuration Locations

Phantom looks for configuration in the following order (later files override earlier):

  1. /etc/phantom/config.yaml - System-wide config
  2. ~/.phantom/config.yaml - User config (default)
  3. ./.phantom.yaml - Project-specific config
  4. --config flag - Explicitly specified config

Environment Variables

All configuration options can be set via environment variables with the PHANTOM_ prefix:

# Set data directory
export PHANTOM_DATA_DIR=~/.phantom

# Set default timeout
export PHANTOM_OVERLAYS_DEFAULT_TIMEOUT=1h

# Set log level
export PHANTOM_LOGGING_LEVEL=debug

# Disable auto-commit
export PHANTOM_GIT_AUTO_COMMIT=false

Environment Variable Reference

Environment VariableConfig PathDefault
PHANTOM_DATA_DIRdata_dir~/.phantom
PHANTOM_OVERLAYS_DIRoverlays.dir~/.phantom/overlays
PHANTOM_OVERLAYS_MOUNT_DIRoverlays.mount_dir~/.phantom/mnt
PHANTOM_OVERLAYS_DEFAULT_TIMEOUToverlays.default_timeout30m
PHANTOM_OVERLAYS_MAX_PARALLELoverlays.max_parallel5
PHANTOM_GIT_AUTO_COMMITgit.auto_committrue
PHANTOM_GIT_BRANCH_PREFIXgit.branch_prefixphantom/
PHANTOM_GIT_PUSH_ON_APPLYgit.push_on_applyfalse
PHANTOM_LOGGING_LEVELlogging.levelinfo
PHANTOM_LOGGING_FILElogging.file~/.phantom/phantom.log
PHANTOM_AGENTS_DEFAULTagents.defaultclaude --print
PHANTOM_AGENTS_TIMEOUTagents.timeout30m

Hooks

Hooks are commands that run at specific points in the overlay lifecycle.

Hook Types

TypeWhen it runs
on_successAfter agent completes successfully
on_failureAfter agent fails
on_completeAfter agent finishes (success or failure)

Configuring Hooks

In config file:

hooks:
  on_success:
    - command: npm test
      timeout: 5m
    - command: npm run lint
      timeout: 2m
  on_failure:
    - command: 'notify-send "Phantom" "Agent failed"'
  on_complete:
    - command: ./scripts/cleanup.sh

Via CLI:

# Add a hook
phantom hook add my-overlay --type on_success --command "npm test"

# List hooks
phantom hook list my-overlay

# Remove a hook
phantom hook remove my-overlay --index 0

Hook Context

Hooks receive environment variables with context about the overlay:

VariableDescription
PHANTOM_OVERLAY_NAMEName of the overlay
PHANTOM_OVERLAY_PATHPath to overlay mount point
PHANTOM_BASE_PATHPath to base directory
PHANTOM_AGENT_COMMANDThe agent command that ran
PHANTOM_AGENT_EXIT_CODEExit code of the agent
PHANTOM_TASKTask description

Hook Examples

Run tests on success:

hooks:
  on_success:
    - command: npm test
      timeout: 10m

Notify on failure:

hooks:
  on_failure:
    - command: 'curl -X POST $SLACK_WEBHOOK -d "{\"text\": \"Phantom task failed: $PHANTOM_OVERLAY_NAME\"}"'

Cleanup temp files:

hooks:
  on_complete:
    - command: rm -rf /tmp/phantom-*

Templates

Templates are reusable configurations for common workflows.

Creating Templates

# Generate an agents template
phantom template agents > agents.yaml

# Generate a chain template
phantom template chain > chain.yaml

# Generate a hooks template
phantom template hooks > hooks.yaml

Agents Template

# agents.yaml - Configuration for parallel agents
agents:
  - name: feature
    command: claude --print
    task: "Implement the feature"
    timeout: 30m
    hooks:
      on_success:
        - npm test

  - name: tests
    command: aider
    task: "Add tests for the feature"
    timeout: 20m

  - name: docs
    command: gemini
    task: "Update documentation"
    timeout: 15m

Chain Template

# chain.yaml - Configuration for sequential chain
steps:
  - name: implement
    command: claude --print
    task: "Implement the feature"

  - name: test
    command: aider
    task: "Add comprehensive tests"

  - name: review
    command: claude --print
    task: "Review code for issues and improvements"

Project Configuration

Create a .phantom.yaml file in your project root for project-specific settings:

# .phantom.yaml - Project-specific Phantom configuration

# Project-specific hooks
hooks:
  on_success:
    - command: npm run test:unit
    - command: npm run lint

# Default agents for this project
agents:
  default: claude --print --model claude-3-opus

# Project-specific timeouts
overlays:
  default_timeout: 45m

# Exclude patterns (not monitored by watch)
exclude:
  - node_modules/**
  - dist/**
  - .git/**

Advanced Configuration

Custom Mount Options

overlays:
  # Linux overlayfs options
  overlayfs_options:
    - index=off
    - metacopy=on

  # FUSE options (macOS/fuse-overlayfs)
  fuse_options:
    - allow_other
    - uid=1000
    - gid=1000

Resource Limits

# Resource limits for agents
agents:
  # Maximum memory (0 = unlimited)
  max_memory: 2GB

  # Maximum CPU percentage
  max_cpu: 80

  # Maximum file descriptors
  max_fds: 1024

Security Settings

security:
  # Allowed agent commands (empty = all allowed)
  allowed_agents:
    - claude
    - aider
    - gemini

  # Sandbox agent processes
  sandbox: true

  # Network access for agents
  network: true

Config Commands

# View current configuration
phantom config

# Get a specific value
phantom config get overlays.default_timeout

# Set a value
phantom config set git.auto_commit false

# Open config in editor
phantom config edit

# Show config file path
phantom config path

Path Protection (.phantomignore)

You can protect specific files and directories in your repository from being modified by Phantom overlays using a .phantomignore file. This is useful for preventing agents from accidentally deleting crucial configuration files, credentials, or sensitive data.

How it works

When you run phantom apply, Phantom checks for a .phantomignore file in the root of your base directory. If it exists, it validates every change in the overlay against the rules defined in the file. If any modification (add, update, or delete) matches a rule, the apply operation is rejected.

Syntax

The .phantomignore file uses a syntax similar to .gitignore:

  • Lines starting with # are comments.
  • Empty lines are ignored.
  • Patterns without a slash match any file or directory with that name anywhere in the tree.
  • Patterns starting with a / are anchored to the repository root.
  • Patterns ending with a / match directories and all their contents.
  • * can be used as a wildcard (matching within a single directory).

Example

# Protect critical infrastructure configs
/config/database.yml
/config/secrets.yml

# Protect all .env files anywhere
.env*

# Protect the build directory entirely
build/

# Protect any secret keys
*.key

Configuration Best Practices

  1. Use project config for team settings - Commit .phantom.yaml to version control
  2. Use user config for personal preferences - Timeouts, log levels
  3. Use hooks for quality gates - Run tests, linters before applying
  4. Set appropriate timeouts - Prevent runaway agents
  5. Use templates - Standardize workflows across your team