cldc compiles repository policy from CLAUDE.md and related YAML files into .claude/policy.lock.json, then enforces that policy over explicit runtime evidence, Claude Code hook session state, and git-derived diffs.
- Language: Python 3.11+
- Packaging:
uvwithuv_build - Runtime dependencies:
PyYAML,textual - Test runner:
pytest(+pytest-asyncio,hypothesis,pytest-cov,pytest-benchmark) - Entry point:
cldc
src/cldc/__init__.py: typed exception re-exports and the package version resolver.src/cldc/_logging.py: library logging setup (NullHandlerby default, CLI stderr handler on demand).src/cldc/errors.py: typed exception hierarchy rooted atCldcError(ValueError).src/cldc/cli/main.py: argparse CLI, command routing, exit codes, JSON/text output.src/cldc/ingest/discovery.py: repo-root discovery and source inventory.src/cldc/ingest/source_loader.py: source loading, inlinecldcblock extraction, include-pattern validation, andextends:preset resolution.src/cldc/parser/rule_parser.py: rule validation and normalized policy model.src/cldc/compiler/policy_compiler.py: lockfile generation anddoctordiagnostics.src/cldc/presets/: bundled opinionated policy packs (default,strict,docs-sync) and the preset loader API.src/cldc/runtime/evaluator.py: policy evaluation against reads, writes, commands, command outcomes, claims, and git-derived write sets.src/cldc/runtime/events.py: machine-readable runtime evidence ingestion.src/cldc/runtime/reporting.py: saved report validation and rendering.src/cldc/runtime/remediation.py: deterministic fix-plan generation and rendering.src/cldc/runtime/git.py: staged and base/head diff collection.src/cldc/runtime/hooks.py: hook artifact generation for git and Claude Code integration.src/cldc/runtime/claude_code_adapter.py: stateful Claude Code session adapter used by generated hooks.src/cldc/runtime/report_schema.py: versionedpolicy-report/v1constants.src/cldc/scaffold.py:cldc initscaffolding for a fresh repo.src/cldc/tui/: Textual-based interactive TUI (cldc tui).app.pyhostsCldcApp,state.pyowns theTuiStatedataclass + loaders,widgets.pydefines the custom panes, andstyles.tcssis the dark theme stylesheet.tests/fixtures/repo_a/: canonical fixture repo used by compile/runtime/CLI tests.tests/e2e/: narrated langchain demo runner plus the raw pytest e2e suite (make e2e/make e2e-test).docs/library-usage.md: full library reference for embedders.docs/rfcs/: frozen implementation contracts.
uv sync --locked
uv run pytest -q
uv build
uv run cldc --help
uv run cldc init /path/to/new/repo --preset default
uv run cldc compile tests/fixtures/repo_a
uv run cldc check tests/fixtures/repo_a --write src/main.py --json
uv run cldc ci tests/fixtures/repo_a --base HEAD --head HEAD --json
uv run cldc explain tests/fixtures/repo_a --write src/main.py --format markdown
uv run cldc fix tests/fixtures/repo_a --write src/main.py --json
uv run cldc preset list
uv run cldc preset show default
uv run cldc tui tests/fixtures/repo_a
uv run cldc hook generate claude-code --json
uv run cldc hook claim . ci-green- Use explicit
encoding="utf-8"for repository file I/O. - Keep JSON artifacts deterministic: sorted keys, stable ordering, explicit schema/version fields.
- Fail closed on malformed or tampered artifacts; do not silently ignore unsupported rule kinds.
- Keep the CLI shell thin. Put behavior in ingest/parser/compiler/runtime modules, then expose it in
cli/main.py. - Add or update tests with every behavior change, especially for stale lockfiles, malformed inputs, and boundary cases.
- Do not change
docs/rfcs/unless the specification itself is changing. - Treat
.claude/policy.lock.json, policy report JSON, and fix-plan JSON as versioned contracts. cldc checkmust refuse stale or schema-drifted lockfiles instead of guessing.- Rule kinds that are not supported by the runtime must raise explicit errors, not degrade to a silent pass.
- Keep include patterns repo-local; do not allow config globs to escape the repo root.
- This repository has a top-level
AGENTS.mdfor agent context, but it intentionally contains nocldcrules. require_claimis a path-scoped rule: writes matchingwhen_pathsfail the rule unless at least one of the listedclaimsis asserted via--claim, an events file, stdin JSON, or an event payload.couple_changemeans a write matchingpathsrequires an additional write matchingwhen_paths; the same path does not satisfy both sides of the rule.compileupdates the lockfile state in its returned metadata; missing-lockfile warnings from discovery should not survive a successful compile.
As of April 8, 2026, the shipped CLI surface is init, compile, doctor, check, ci, explain, fix, preset, tui, and hook.
Implemented:
- deterministic source discovery and lockfile generation
cldc initonboarding scaffolder (.claude-compiler.yaml+ stubCLAUDE.md, repeatable--preset, safe by default)- doctor diagnostics for malformed, stale, and drifted artifacts
- runtime enforcement for
deny_write,require_read,require_command,require_command_success,forbid_command,couple_change, andrequire_claim - claim ingestion via
--claim, events file, stdin JSON, and event payloads - bundled preset policy packs (
default,strict,docs-sync) reachable viaextends:in.claude-compiler.yamland inspectable withcldc preset list/cldc preset show - saved policy report rendering and deterministic fix-plan generation
- git-aware CI entrypoints for staged and base/head diffs
- stateful Claude Code hook adapter with
SessionStart,PreToolUse,PostToolUse,PostToolUseFailure,Stop, andSessionEnd - explicit Claude Code session claims via
cldc hook claim - git pre-commit and Claude Code hook generation via
cldc hook cldc tuiinteractive policy explorer
Known limitations:
- no semantic extraction of free-form prose into rules yet; only structured policy is compiled today
- no automatic repo mutation or autofix execution
- no separate lint/type/coverage enforcement in CI yet