Skip to content

Overview

contox_populate batch creates or updates contexts using schemaKeys as identifiers. This is the primary tool used by the codebase scanner and CLI to push structured sub-contexts into the brain hierarchy. All created contexts default to the draft state.

The tool uses content-hash deduplication — if a context's content has not changed since the last populate, it is marked as unchanged and not re-written.

Parameters

NameTypeRequiredDefaultDescription
nodesarrayYesList of nodes to populate (see schema below)
dryRunbooleanNofalseIf true, only return diff stats without writing
sourcestringNoSource identifier (e.g., "cli-scan", "mcp-populate")

Node schema

Each node in the nodes array has the following structure:

FieldTypeRequiredDescription
schemaKeystringYesUnique schema key (e.g., "root/api/auth")
namestringYesDisplay name for the context
contentstringNoMarkdown content
descriptionstringNoBrief description
contextTypeenumNoOne of: system, reference, memory
tiernumberNoTier level: 1 (always loaded), 2 (on-demand), 3 (archive)
parentSchemaKeystringNoParent schema key for hierarchy

Return value

Returns a summary of the populate operation:

FieldTypeDescription
runIdstringUnique identifier for this populate run
creatednumberNumber of new contexts created
updatednumberNumber of existing contexts updated
unchangednumberNumber of contexts with identical content (skipped)
errorsnumberNumber of errors during processing

Usage examples

Populating API documentation contexts

Claude calls: contox_populate({
  nodes: [
    {
      schemaKey: "root/api",
      name: "API Layer",
      description: "REST API routes and handlers",
      contextType: "reference",
      tier: 2
    },
    {
      schemaKey: "root/api/auth",
      name: "Auth API",
      content: "## Endpoints\n\n### POST /api/auth/login\nAccepts email and password...",
      parentSchemaKey: "root/api",
      contextType: "reference",
      tier: 2
    },
    {
      schemaKey: "root/api/users",
      name: "Users API",
      content: "## Endpoints\n\n### GET /api/users\nReturns paginated user list...",
      parentSchemaKey: "root/api",
      contextType: "reference",
      tier: 2
    }
  ],
  source: "mcp-populate"
})

Response:
Populate completed.
- Run ID: run_abc123
- Created: 3
- Updated: 0
- Unchanged: 0
- Errors: 0

Dry run to preview changes

Claude calls: contox_populate({
  nodes: [...],
  dryRun: true
})

Response:
Populate (dry run) completed.
- Run ID: run_def456
- Created: 2
- Updated: 1
- Unchanged: 5
- Errors: 0

Notes

  • Nodes should be ordered depth-first (parents before children) to ensure parent contexts exist when children reference them.
  • The schemaKey is the unique identifier — if a context with the same schemaKey already exists, it will be updated rather than duplicated.
  • Created contexts start in draft state. Use contox_approve to make them visible in the brain document.
  • The source field is recorded in the audit trail for tracking which tool or process created each context.