Context

Context - ProcessWire Module

Export your ProcessWire site structure as AI-optimized context for ChatGPT, Claude, and other AI assistants.

What It Does

Context automatically generates comprehensive documentation of your ProcessWire site in formats optimized for AI assistants. Export in both JSON (standard) and TOON (AI-optimized) formats.

Perfect for:

Features

Dual Format Export

Core Exports (Always Generated)

Optional Features

Site Type Customization

Code snippets are automatically customized for your site type:

Requirements

Installation

Method 1: Manual Installation

cd /site/modules/
git clone https://github.com/mxmsmnv/Context.git

Then refresh modules in admin and install.

Method 2: Modules Directory

  1. Download the module from the ProcessWire Modules Directory
  2. Place files in /site/modules/Context/
  3. In ProcessWire admin: Modules → Refresh
  4. Click Install next to “Context”

Quick Start

1. Configure the Module

Setup → Modules → Context → Configure

  1. Choose your site type (Blog, E-commerce, Business, Catalog, or Generic)
  2. Enable TOON format - Export TOON Format (AI-Optimized) - Recommended!
  3. Enable optional features you need:
    • Export Content Samples
    • Generate API Documentation
    • Create Code Snippets
    • Create AI Prompts
  4. Set samples per template (1-10)
  5. Enable auto-update if you want automatic exports on template/field changes

2. Export Your Site

Click “Re-Export Context for AI” or visit:

/processwire/module/?name=Context

Files are generated in: /site/assets/context/

3. Use with AI

Upload these files to your AI assistant:

For AI Development (Recommended - Use TOON):

For Development Tools (Use JSON):

Example prompt:

I've uploaded my ProcessWire site context in TOON format. 
Please help me create a new template for blog posts with 
title, body, author, and categories fields. Follow the 
existing patterns in templates.toon.

Generated Files

Directory Structure

/site/assets/context/
├── README.md                      # Documentation with format guide
├── SKILL.md                       # AI agent skill definition (for Cline, Junie, etc.)
├── tree.json                      # Complete site structure (templates + fields + pages)
├── tree.toon                      # Complete site structure (TOON - AI optimized!)
├── structure.json                 # Page tree (JSON)
├── structure.toon                 # Page tree (TOON - AI optimized!)
├── structure.txt                  # ASCII tree visualization
├── templates.json                 # Templates (JSON)
├── templates.toon                 # Templates (TOON - AI optimized!)
├── templates.csv                  # Templates in CSV
├── matrix-templates.json          # Repeater Matrix types (ProFields) - if installed
├── matrix-templates.toon          # Repeater Matrix types (TOON) - if installed
├── config.json                    # Configuration (JSON)
├── config.toon                    # Configuration (TOON)
├── modules.json                   # Installed modules (JSON)
├── modules.toon                   # Installed modules (TOON)
├── classes.json                   # Custom page classes (JSON)
├── classes.toon                   # Custom page classes (TOON)
│
├── samples/                       # Content examples (optional)
│   ├── product-samples.json
│   └── product-samples.toon       # AI-optimized samples!
├── api/                           # API schemas (optional)
├── snippets/                      # Code library (optional)
├── prompts/                       # AI prompts (optional)
│   ├── project-context.md         # Main project prompt
│   ├── create-template.md         # Template creation guide
│   ├── create-api.md              # API creation guide
│   ├── debug-issue.md             # Debugging helper
│   └── project-summary.md         # Session continuity template
└── metadata/                      # Technical data (optional)

File Format Comparison

File JSON Size TOON Size Savings Use For
structure.* 45 KB 28 KB ~38% Page hierarchy
templates.* 12 KB 6 KB ~50% Template definitions
samples/* 8 KB 4 KB ~50% Content examples

Tip: When uploading to AI, use .toon files to save tokens and reduce API costs!

Understanding TOON Format

What is TOON?

TOON (Token-Oriented Object Notation) is a compact, human-readable format designed specifically for AI prompts. It represents the same data as JSON but uses 30-60% fewer tokens.

Example Comparison

JSON (120 tokens):

{
  "products": [
    {
      "id": 1045,
      "title": "Dark Chocolate 70%",
      "price": 12.99,
      "category": "Dark"
    },
    {
      "id": 1046,
      "title": "Milk Hazelnut",
      "price": 9.99,
      "category": "Milk"
    }
  ]
}

TOON (65 tokens - 46% savings!):

products[2]{id,title,price,category}:
1045,Dark Chocolate 70%,12.99,Dark
1046,Milk Hazelnut,9.99,Milk

When to Use Which Format

Use TOON (.toon) for:

Use JSON (.json) for:

Viewing TOON Files

Use Cases

1. AI-Assisted Development (Save 30-60% on API Costs!)

# Upload to Claude/ChatGPT (TOON format):
- structure.toon
- templates.toon
- samples/product-samples.toon

# Then ask:
"Create a product filter with price range, category, and brand 
using the patterns from my site structure"

Result: Same quality response, but using 40% fewer tokens!

2. Onboarding New Developers

Share the /site/assets/context/ folder with new team members. They get:

3. Building APIs

# Upload (JSON format for technical work):
- api/schemas/product-schema.json
- snippets/api-examples.php

# Ask:
"Create a REST API endpoint for products with search and filtering"

4. Large-Scale AI Tasks

# For big projects with lots of data:
- Use TOON format to fit more context in AI's window
- 100 products in JSON = ~15,000 tokens
- 100 products in TOON = ~7,000 tokens
- Difference: You can include 2x more examples!

5. Cost Optimization

Real savings example:

Your site: 50 templates, 500 pages to document

JSON export: ~85,000 tokens
TOON export: ~42,000 tokens
Savings: 43,000 tokens per prompt

With Claude Sonnet ($3 per million input tokens):
- JSON cost: $0.255 per prompt
- TOON cost: $0.126 per prompt
- Savings: $0.129 per prompt

If you use 100 prompts/month: Save ~$13/month
If you use 1000 prompts/month: Save ~$130/month

Auto-Update Feature

Enable Auto-Update on Changes to automatically regenerate context when you:

Hooks into:

Auto-update exports both JSON and TOON formats if TOON export is enabled.

Best Practices

Working with AI Assistants

  1. Always include prompts/project-context.md - contains system instructions
  2. For token efficiency - use .toon files instead of .json
  3. For field questions - include templates.toon
  4. For site structure - include structure.toon or structure.txt
  5. For coding - include snippets/selectors.php
  6. For debugging - include relevant samples/*-samples.toon

File Upload Strategy

When to Re-Export

Module Settings

Export Formats

Site Type Selection

Choose your site type to get customized code snippets:

Content Features

Advanced Settings

Technical Details

Requirements

Performance

Security

Server-Specific Setup:

Apache (HestiaCP, cPanel, etc.):

Nginx (CloudPanel, etc.):

Important: Update to v1.1.6+ for proper security. Versions < 1.1.6 used unprotected site/assets/context/ path.

TOON Format Details

File Locations

Format Comparison in Module Admin

When TOON export is enabled, the module admin page shows a comparison table:

File Type JSON Size TOON Size Savings
structure 45.2 KB 27.8 KB -38.5%
templates 12.1 KB 6.3 KB -47.9%
config 2.4 KB 1.6 KB -33.3%

This helps you see the actual token/cost savings for your specific site!

FAQ

General Questions

Q: Do I need to install any external libraries for TOON support?
A: No! TOON conversion is built-in with pure PHP. No Composer packages or external dependencies required.

Q: Is TOON format lossless?
A: Yes! TOON contains exactly the same data as JSON, just in a more compact format. You can convert back and forth without any data loss.

Q: Which AI assistants support TOON?
A: Claude, ChatGPT, and most modern LLMs understand TOON natively. Just upload the .toon file as you would a .json file.

Q: Can I use both JSON and TOON formats?
A: Absolutely! Both formats are generated simultaneously. Use JSON for development tools and APIs, TOON for AI assistants.

Q: How much does TOON actually save?
A: Typically 30-60% fewer tokens. The exact savings depend on your data structure - uniform arrays see the biggest gains (up to 60%).

Technical Questions

Q: Does TOON export slow down my site?
A: No. Export happens on-demand when you click the button, not on every page load. The TOON conversion adds < 0.5s to the export time.

Q: What if I disable TOON format later?
A: No problem! Simply uncheck “Export TOON Format” in settings. Your next export will only generate JSON files.

Q: Can I edit TOON files manually?
A: Yes, TOON files are plain text and human-readable. However, it’s easier to make changes in ProcessWire and re-export.

Q: Are there any file size limits?
A: TOON files follow the same limits as JSON. Both are text files with no artificial size restrictions.

Q: How do I view TOON files?
A: TOON files are plain text. Use any text editor. For syntax highlighting: VS Code/Cursor (install “TOON Language Support” extension) or PhpStorm (use YAML highlighting).

Troubleshooting

Q: Export failed with “permission denied”
A: Ensure /site/assets/ directory is writable by your web server user. Check file permissions (755 or 775).

Q: TOON files not being created
A: Check that “Export TOON Format” is enabled in module settings and you’ve clicked “Re-Export Context for AI” after enabling it.

Q: AI assistant doesn’t understand my TOON file
A: TOON is plain text - just upload it as you would any text file. Make sure the file has a .toon extension.

Best Practices

AI Coding Agents (Cline, Junie, etc.)

SKILL.md Auto-Generation

The module automatically generates SKILL.md for AI coding agents. This file helps agents understand how to use your ProcessWire context.

Setup for Cline (PHPStorm/VSCode):

  1. Set export path to .agents/skills/context/
  2. Enable “Generate SKILL.md for AI Agents”
  3. Re-export Context
  4. Cline will auto-discover the skill

Setup for Junie (PHPStorm):

  1. Set export path to .junie/skills/docs/
  2. Enable “Generate SKILL.md for AI Agents”
  3. Re-export Context
  4. Junie will use the context in your coding sessions

Session Continuity

Problem: AI agents don’t remember previous sessions. Each new session starts from scratch.

Solution: Create a project checkpoint file at the end of each coding session.

Prompt template (suggested by @psy):

Create a structured project checkpoint summary.

Output MUST follow this exact format and headings. Use short bullet points only. No paragraphs.

## Project
(one line description)

## Current State
- ...

## Decisions Made
- ...

## Known Issues
- ...

## What We Tried
- ...

## Constraints
- ...

## Next Steps
1.
2.
3.

## Do NOT Do
- ...

Rules:
- Be concise and factual
- Do not explain reasoning unless critical
- Do not invent anything not discussed
- Prefer clarity over completeness

Save this as: [your-export-path]/prompts/project-summary.md
Overwrite the file.
Do not add any extra commentary outside the file contents.

Workflow:

  1. Work on your project with AI agent
  2. Before closing: Ask AI to create checkpoint using the template above
  3. AI saves prompts/project-summary.md
  4. Next session: AI reads Context exports + project-summary.md
  5. AI understands where you left off and continues seamlessly

Why this works:

File Upload Strategy

When working with AI assistants:

License

MIT License - see LICENSE file for details

Author

Maxim Alex