agentleFS
agulaya24agulaya24/BaseLayer/CLAUDE.md

BaseLayer

CLAUDE.md5 starsChanged 9 months agoApache-2.0View on GitHub

Claude Code-specific guide for working in the Base Layer repo. This file complements AGENTS.md (provider-neutral) with Claude Code harness specifics. For background on the project, read AGENTS.md and README.md first. This file is shorter on purpose. Base Layer is the interpretive layer above memory. The pipeline takes text (conversations, journals, essays, books) and produces a behavioral specification: a structured document in three layers that captures how a specific person interprets information, decides, and communicates. Memory systems retrieve facts. The specification…

  • In this repository2 other files it gives its agents.

The file

Show its rules and text

We split this CLAUDE.md into the rules it gives an agent

14 rules. About 0 are common, 10 are distinctive, and 4 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈10

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 4

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    If you are running in this repo as Claude Code, you are most likely doing one of four things:

    line 11
  2. Distinctive:

    If the user's request is ambiguous, ask before running anything that spends API budget.

    line 18
  3. Distinctive:

    When you generate user-facing text in this repo (commit messages, doc edits, blog drafts, paper edits, recipes, comments in source), follow …

    line 22
  4. Distinctive:

    No em-dashes. Restructure sentences.

    line 24
  5. Distinctive:

    No GTM language ("beats", "crushes", "outperforms", "wins").

    line 25
  6. Distinctive:

    No marketing prose. Action-first.

    line 27
  7. Distinctive:

    Write for a technical product owner: someone who directs the architecture and evaluates results, rather than someone who reads every line …

    line 28
  8. Very specific:

    All commands invoked as baselayer <subcommand>.

    line 34
  9. Very specific:

    Monitoring: Every resource read and tool call emits a stderr log line of the form [base-layer] INFO: mcp_call name=<tool> [k=v ...].

    line 91
  10. Distinctive:

    When writing new prose, use "specification" and "interpretive layer".

    line 130
  11. Very specific:

    Do not invent commands or flags: If a flag is not in cli.py, it does not exist.

    line 135
  12. Distinctive:

    Do not POST to unknown endpoints: Read the route handler first.

    line 136
  13. Very specific:

    Do not run the pipeline without the cost-estimate gate: Use baselayer run (which gates by default) or run baselayer estimate before …

    line 139
  14. Distinctive:

    Ask the user before doing anything irreversible.

    line 145

≈ “Common” is an estimate: at least 1 in 5 of the 29,248 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
CLAUDE.md

CLAUDE.md

Claude Code-specific guide for working in the Base Layer repo. This file complements AGENTS.md (provider-neutral) with Claude Code harness specifics.

For background on the project, read AGENTS.md and README.md first. This file is shorter on purpose.

Project context

Base Layer is the interpretive layer above memory. The pipeline takes text (conversations, journals, essays, books) and produces a behavioral specification: a structured document in three layers that captures how a specific person interprets information, decides, and communicates. Memory systems retrieve facts. The specification supplies the framework those facts are read through.

If you are running in this repo as Claude Code, you are most likely doing one of four things:

  1. Running the pipeline on the user's text data (ChatGPT export, journal directory, document corpus).
  2. Debugging extraction, authoring, or composition (a stage produced too few facts, a layer regenerated wrong, etc.).
  3. Exploring example specifications under examples/ to understand the output format.
  4. Connecting the local MCP server to inject the specification into a Claude conversation.

If the user's request is ambiguous, ask before running anything that spends API budget.

Voice and prose constraints

When you generate user-facing text in this repo (commit messages, doc edits, blog drafts, paper edits, recipes, comments in source), follow the project's voice constraints:

  • No em-dashes. Restructure sentences. Do not substitute hyphens.
  • No GTM language ("beats", "crushes", "outperforms", "wins"). Scientific framing only.
  • Canonical terms: "interpretive layer" and "specification" body-primary. "Behavioral specification" on first mention. Do not use "behavioral compression" or "identity model" in new prose.
  • No marketing prose. Action-first. Direct.
  • Write for a technical product owner: someone who directs the architecture and evaluates results, rather than someone who reads every line of code.

The same constraints are kept in the maintainer's private agent notes. Follow the list above.

Commands an AI agent should know

All commands invoked as baselayer <subcommand>. Source of truth: src/baselayer/cli.py.

CommandOne-liner
baselayer initInitialize a fresh database under the data root (MEMORY_SYSTEM_ROOT; unset, code run from this clone uses the clone's own data/; never the current directory).
baselayer import <file>Import ChatGPT/Claude export, journal, text file, or directory.
baselayer estimatePreview of extraction cost only, from the imported text and the dated rate table in src/baselayer/distillation/spend.py. A floor, not a budget; authoring is not priced here.
baselayer extractExtract facts via Haiku 4.5 (a suggested list of 46 predicates, AUDN lifecycle). Add --turn-contract to ground every fact in the subject's own turns, on Haiku 5.5 at effort medium (see below). Legacy extraction stays on Haiku 4.5 because on published text the newer model would not credit the writing to the person on the legacy prompt; a legacy comparison is pending.
baselayer embedEmbed imported messages into ChromaDB for baselayer search. Fact vectors are written during extraction.
baselayer author --layer allAuthor anchors, core, and predictions layers (Sonnet 4.6).
baselayer composeOptional, legacy: compose a unified prose brief from the three layers (Opus 4.6). Not run by baselayer run.
baselayer distill, assemble, author-from-packageThe experimental cited path: distillation leaves (Sonnet 5), one package per layer (no model), layers with mandatory citations (Opus 5). distill and author-from-package print an estimate and refuse to start without --confirm-spend or BASELAYER_SPEND_CEILING_USD. Always pass --layer to distill. See docs/PIPELINE.md.
baselayer run <file>The older, quicker static pipeline in one command, with a cost prompt and far fewer checks than the cited path. Runs init if needed -> import -> estimate and confirm -> extract -> coverage gate -> author, then a traceability phase (tier, embed, vector provenance, a tension check on Haiku 4.5). No brief: compose is optional and separate.
baselayer statsDatabase stats: conversations, facts, tier breakdown.
baselayer search "<query>"FTS keyword search across active facts.
baselayer provenance --claim A1Trace a specification claim back to its supporting facts.
baselayer verify --layer allThe older provenance audit of the static layers (vector proximity, recurrence, cross-domain span, optional local NLI with --nli). Writes rows into the corpus database. Not verify-spec.
baselayer verify-spec <spec_dir> --label L --corpus C --out ORead-only post-specification verification: citation resolution, per-fact voice, re-gating of every evidence span. Dry run by default; no model is called unless --run-model.
baselayer consolidate <spec_dir> --out O [--grouping G --categories C]Mechanical, no model: the served form of a finished spec (always-on claims in full, trigger categories whose lines name claim ids, an index JSON for pulling claims), a duplicate mapping, and 14 checks. Reads the spec dir, writes only --out. The judged inputs (duplicate verdicts, trigger grouping, categories) come from python -m baselayer.consolidation.build judge|group|categorize, which calls a model (API priced and capped, or claude -p). docs/core/CONSOLIDATION.md.
baselayer checkpoint extractionQuality gate after extraction. Reports only; no --fix flag exists.
baselayer chunks list|retry|quarantine|ack-modelThe chunk ledger of a turn-contract extraction: list chunks by status, requeue failed or quarantined ones, quarantine one. list --review shows every quarantined chunk with why it failed plus requests to re-extract a finished conversation; list --backlog shows done work made by another extraction model, which nothing re-runs (ack-model records that it was seen). baselayer run does not author over quarantined chunks without --accept-gaps; authored artifacts state them in a coverage_gaps*.json manifest beside them.
baselayer forget --allHide (soft-delete) all active facts. Raw text stays and written layers are not regenerated. Not a reset. Confirm before running.
baselayer journalGuided prompts when the user has no conversation history.

For long-form usage details and step-by-step pipeline structure, see AGENTS.md. Do not invent commands. If a flag does not appear in cli.py, it does not exist.

Turn contract. docs/core/TURN_CONTRACT.md, decision D-108. Import records each turn's speaker and voice class; only the subject's typed or spoken turns can be cited. extract --turn-contract gates every fact on verbatim own-voice spans in code, and writes rejection counts by reason (no_grounding, no_turn, not_own_voice, span_not_found, span_length, self_object) to <corpus>/data/database/extraction_runs/. Read that record after every run. Facts carry stamps (model, prompt hash, git commit, repo-relative code path, contract version). Set subject_names in the import config before importing; turn-mode extraction refuses to start without it. Build into a fresh corpus directory.

MCP server quick-connect

Register the Base Layer MCP server with Claude Code:

claude mcp add --scope user --transport stdio base-layer -- baselayer-mcp

Once registered, the next Claude Code session loads two resources and eight tools. The server serves the three layers in data/identity_layers/ (the baselayer run path); it does not serve a cited-path specification or consolidate output.

Resources (always-on, client-controlled):

  • memory://specification. The structural specification inline: CORE (communication and context), ANCHORS (foundational beliefs and reasoning patterns), PREDICTIONS (situation-to-response patterns), plus a brief manifest. Its size depends on the corpus. The server also sends this text in its MCP instructions; some clients may truncate long instructions, and reading the resource returns the full text.
  • memory://identity. Deprecated alias for memory://specification. Forwards to the same content. Retained for backward compatibility.

On-demand specification tool:

  • get_brief(reason). The optional prose brief, if one was composed. The model fetches this when the query is broad, abstract, or self-reflective. Provides a private one-sentence rationale via reason; not user-facing.

Memory tools (model-controlled, called on demand):

  • recall_memories(query). Semantic retrieval of relevant facts plus episodic memories for a query.
  • search_facts(query, limit=15). Keyword search across active facts (FTS5 with LIKE fallback).
  • trace_claim(claim_id). Provenance from a specification claim (e.g. A1, P3, C2) back to its linked facts: fact text, tier, recurrence, link method and source conversation title, plus up to three evidence spans (the person's quoted words and turn id) per fact that came from turn-contract extraction.
  • verify_claims(claim_id="", layer="all"). Run the binary verification checks (existence, recurrence, cross-domain coverage, temporal consistency, contradictions).
  • get_stats(). Database summary: conversations, messages, active and superseded facts, tier and source breakdowns.
  • get_call_log(limit, name_filter). Recent MCP calls in this session.
  • get_help(topic). Comprehensive Base Layer agent reference. Consult any time the user asks about Base Layer itself; the guide includes intent-to-action mappings so the agent can run the right command rather than telling the user what to type.

Monitoring. Every resource read and tool call emits a stderr log line of the form [base-layer] INFO: mcp_call name=<tool> [k=v ...]. Per-session traces live at ~/.baselayer/sessions/<pid>/log.jsonl. The baselayer log list/show/tail/stats CLI inspects them.

Design note (0.4.0). Earlier 0.3.0 split CORE on the resource and ANCHORS/PREDICTIONS behind on-demand get_anchors/get_predictions tools. Live use surfaced two issues: the model had to make routing decisions about layers it could not see, and the token savings were negligible. 0.4.0 inlines all three structural layers so the spec is fully present without a routing decision. Only the unified narrative brief stays on-demand.

Where to find what

PathContents
src/baselayer/cli.pyCLI entry point. Source of truth for all subcommands and flags.
src/baselayer/extract_facts.pyFact extraction with the AUDN lifecycle (Add, Update, Delete, NOOP; delete is a soft supersession).
src/baselayer/author_layers.pyThree-layer authoring (anchors, core, predictions).
src/baselayer/agent_pipeline.pyOptional prose brief composition (compose, Opus 4.6).
src/baselayer/mcp_server.pyMCP server. Resources + tools.
src/baselayer/config.pyConstants, paths, database singletons. Also the extraction predicate vocabulary: CONSTRAINED_PREDICATES, a suggested list of 46 predicates (45 behavioral plus an unknown fallback).
src/baselayer/verify_provenance.pyThe provenance audit behind baselayer verify and the verify_claims tool.
lexicon_schema.yamlElement-type schema for authored specification containers (axiom, prediction, context_mode, meta_section) plus provenance syntax. Not the predicate vocabulary; that lives in config.py.
tests/The test suite. pytest tests/ runs it.
src/baselayer/voice.py, turns.py, turn_import.py, import_config.pyTurn-contract import: detectors, the turn table, per-source builders, the local config loader.
src/baselayer/turn_contract.pyTurn-contract extraction: chunking, rendering, the gate, the run record.
src/baselayer/verification/verify-spec, read-only post-specification verification.
src/baselayer/consolidation/consolidate: one module per stage, JSON in and JSON out, each stamped.
src/baselayer/distillation/The cited path: distill, assemble, author-from-package, the quote gate, the spend table. Every step: docs/PIPELINE.md. Terms: docs/DEFINITIONS.md.
docs/core/Architecture, decisions, design principles. Read on demand, not at session start.
docs/internal/Internal plans (refactor plans, agent-facing reviews, runbooks). Exists only in the private working copy; not tracked in this repo.
examples/Example specifications: zitkala_sa/ (the one whose claims cite fact ids; its fact database is not published), then Franklin, Buffett, Douglass, Roosevelt, Wollstonecraft, Marks, patents.
recipes/Copy-paste agent task recipes.
data/User data (database, vectors, layers, briefs). Do not touch unless the task requires it.

Phase A naming alignment status

Phase A of the identity-to-specification refactor shipped 2026-05-06. The pattern is additive aliases, not renames. Both old and new names live forever; the new name is canonical.

  • memory://specification is the canonical MCP resource URI.
  • memory://identity is the deprecated alias. Forwards to the same content.
  • The CLI flag --identity-only will gain a --specification-only alias in Phase B.
  • The Python class IdentityLayer and module identity_layers will gain SpecificationLayer and specification_layers aliases in Phase B.

Full plan: docs/internal/identity_to_specification_refactor_plan.md (private working copy only; not tracked in this repo). Do not duplicate that plan in new docs; reference it by path.

When writing new prose, use "specification" and "interpretive layer". Do not reintroduce "identity" terminology.

Things NOT to do

  • Do not run destructive commands without confirmation. baselayer forget --all hides every active fact. python -m baselayer.extract_facts --reset permanently deletes extracted facts, the extraction log, and the fact vectors, with no confirmation prompt of its own. baselayer init --force re-runs initialization (it drops nothing). If the user did not explicitly request the action, ask first.
  • Do not invent commands or flags. If a flag is not in cli.py, it does not exist. Read the source before running anything you have not run before.
  • Do not POST to unknown endpoints. Read the route handler first. The S101 incident wiped tracking data for 48 subjects because an agent called a cleanup endpoint without reading it.
  • Do not modify lexicon_schema.yaml or CONSTRAINED_PREDICATES casually. lexicon_schema.yaml governs the element types of authored layers; CONSTRAINED_PREDICATES in config.py governs extraction, and predicate changes invalidate stored facts under the AUDN lifecycle. Read docs/core/ARCHITECTURE.md and the extraction code first.
  • Do not re-extract without clearing both SQLite and ChromaDB. Old vectors cause AUDN to return NOOP and you get 12-42 facts instead of 200+. python -m baselayer.extract_facts --reset deletes extracted facts, the extraction log, and the fact vectors so every conversation is reprocessed. It is irreversible and has no confirmation prompt; confirm with the user first. It keeps imported conversations and user-corrected facts and does not touch layers already written under data/identity_layers/. The safest clean start is a fresh data root: point MEMORY_SYSTEM_ROOT at an empty directory. baselayer forget --all plus deleting data/vectors/ is not a reset: the extraction log still marks every conversation as done, so re-extraction processes nothing.
  • Do not run the pipeline without the cost-estimate gate. Use baselayer run (which gates by default) or run baselayer estimate before baselayer extract. The estimate prices extraction only and is a floor, not a budget.
  • Do not use the brief or chat subcommands for new work. Both are archived. The three layers are the specification; compose writes an optional prose brief from them.
  • Do not retry the same failing approach more than twice. Diagnose and redesign. If extraction returns zero facts twice, stop and read extract_facts.py.

When in doubt

Ask the user before doing anything irreversible. Read the source before invoking unfamiliar commands. Prefer one fewer step over one extra step.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.