kcl
CLAUDE.md2.4k starsChanged 13 days agoApache-2.0View on GitHub
This document provides a comprehensive overview of the KCL repository to help AI assistants understand the codebase for future work. KCL (KCL Constraint-based Record & Functional Language) is an open-source configuration and policy language designed for cloud-native scenarios. It's a CNCF Sandbox project that enhances the writing of complex configurations through advanced programming language technology. Frontend (Parsing & Analysis): - kcl-lexer - Lexical analysis and tokenization - kcl-parser - Parse KCL source into AST - kcl-ast - Abstract Syntax Tree…
We split this CLAUDE.md into the rules it gives an agent
4 rules. About 0 are common, 4 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈4
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 292
Test coverage is critical: - Add tests for any new functionality
- Distinctive: line 294
Cross-platform support: - Consider multiple platforms when making changes
- Distinctive: line 295
Documentation: - Keep docs in sync with code changes
- Distinctive: line 297
Recent migration from serde_yaml to serde_yaml: - Use the new library
≈ “Common” is an estimate: at least 1 in 5 of the 25,680 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.
Files
KCL Repository Overview for AI Assistants
This document provides a comprehensive overview of the KCL repository to help AI assistants understand the codebase for future work.
What is KCL?
KCL (KCL Constraint-based Record & Functional Language) is an open-source configuration and policy language designed for cloud-native scenarios. It's a CNCF Sandbox project that enhances the writing of complex configurations through advanced programming language technology.
Main Purpose
- Generate low-level static configuration data (JSON, YAML) for cloud-native applications
- Reduce boilerplate in configuration through schema modeling
- Define and validate configuration data with rule constraints
- Manage large-scale configurations with GitOps and automation
- Mutate/validate Kubernetes resources through various tool plugins
- Platform engineering language for modern application delivery (used with KusionStack)
Key Use Cases
- Kubernetes configuration management and abstraction
- Terraform resource model abstraction
- Configuration validation and constraint checking
- Large-scale infrastructure as code
- Platform engineering and GitOps workflows
Production Users
Ant Group, Youzan, and Huawei are notable production users managing large-scale Kubernetes deployments.
Repository Structure
Top-Level Organization
/crates/ Core KCL VM and compiler implementation (main codebase)
/compiler_base/ Base compiler libraries and utilities (WIP, rustc-derived)
/cli/ Command-line interface binary wrapper
/test/ Integration and grammar tests
/grammar/ Extensive grammar test cases
/integration/ Integration test suites
/docs/ Developer guides and documentation
/dev_guide/ Development guide (architecture, quick start, etc.)
/design/ Design documents
/scripts/ Build and release automation scripts
/.github/workflows/ CI/CD pipelines for multiple platformsKey Files
Makefile- Top-level build orchestrationLICENSE- Apache License 2.0README.md- Project documentation
Technology Stack
Primary Language: Rust
- 362+ Rust source files
- ~32,673 lines of Rust code in core modules
- Requires Rust 1.91+ for building
- Rust 2024 edition
Secondary Languages
- KCL - The language itself (.k files for examples and tests)
- Python - Integration tests and test infrastructure
- Shell/Bash - Build scripts and automation
- C/C++ - Runtime interop and FFI interfaces
Key Dependencies
- Protobuf - API definitions and RPC communication
- WASM - WebAssembly compilation target support
- tokio - Async runtime (for LSP and server)
- salsa - Incremental computation (for LSP)
Architecture
Compilation Pipeline
Source Code (.k files)
↓
[Lexer] → Tokens
↓
[Parser] → AST
↓
[Resolver/Sema] → Semantic Analysis & Type Checking
↓
[Evaluator/Runner] → Execution
↓
Output (YAML/JSON)Key Components (/crates)
Frontend (Parsing & Analysis):
kcl-lexer- Lexical analysis and tokenizationkcl-parser- Parse KCL source into ASTkcl-ast- Abstract Syntax Tree definitions and walkerkcl-ast-pretty- AST formatting and pretty-printingkcl-span- Source code span/position trackingkcl-error- Error handling and diagnostics
Semantic Analysis:
kcl-sema- Semantic analysis, type checking, and validationkcl-loader- Module loading and dependency managementkcl-query- Code query and information retrieval
Compilation & Execution:
kcl-evaluator- Expression evaluation enginekcl-runner- Program execution environmentkcl-driver- Compilation driver and orchestration
Runtime:
kcl-runtime- Runtime support libraries with extensive standard library- Value representation and type system
- Standard library modules: json, yaml, base64, regex, crypto, datetime, math, net, etc.
- Template rendering (handlebars)
- File I/O and manifests
Tooling:
kcl-tools- Development tools- Format, Lint, Fix, Vet
- Testing infrastructure
- LSP (Language Server) - Full IDE support with autocomplete, goto-definition, diagnostics
kcl-api- Public API layer for multi-language SDKskcl-cmd- CLI command implementation
Utilities:
kcl-config- Configuration parsingkcl-version- Version managementkcl-utils- Common utilitieskcl-primitives- Primitive type definitionskcl-macros- Procedural macros
Language Server Architecture
- Salsa-based incremental compilation for performance
- VFS (Virtual File System) for handling unsaved changes
- Thread pool for concurrent request handling
- Event-driven architecture (Tasks + LSP Messages)
- Compile unit discovery for projects without explicit config
- Located at:
/crates/tools/src/LSP
Build System
Build Tools
- Cargo - Primary Rust build system (workspace-based with 20+ crates)
- Make - Top-level orchestration
- Docker - Containerized build environment (recommended:
kcllang/kcl-builder)
Common Build Commands
make build # Standard build
make release # Release build
make check # Type checking
make build-lsp # Language server
make build-wasm # WASM targetBuild Features
- Workspace with 20+ member crates
- Support for multiple targets: native, WASM (wasm32-wasip1), WASM-unknown
- Cross-platform: Linux (AMD64, ARM64), macOS (AMD64, ARM64), Windows (MinGW)
- Release profile optimized for size (opt-level = "z", LTO enabled)
Major Dependencies
- serde/serde_json - Serialization
- 3rdparty/serde_yaml - YAML support (note: migrated from serde_yaml)
- prost/protobuf - Protocol buffers
- tokio - Async runtime
- lsp-server/lsp-types - Language Server Protocol
- salsa - Incremental computation
- rustc_lexer - Rust's lexer for tokenization
- petgraph - Graph data structures
- regex/fancy-regex - Regular expressions
Testing
Testing Strategy
1. Unit Tests:
- Cargo-based unit tests across all crates
- Command:
make testorcargo test --workspace
2. Grammar Tests:
- Extensive grammar test suite in
/test/grammar - Python-based pytest framework
- Parallel execution:
pytest -v -n 5 - Tests both AST evaluator and fast evaluator
- Command:
make test-grammar
3. Integration Tests:
tests/grammar- Python integration tests
4. Runtime Tests:
- Python-based runtime library tests
- Command:
make test-runtime
CI/CD
Comprehensive GitHub Actions workflows (11 pipelines) for:
- Linux AMD64 and ARM64
- macOS AMD64 and ARM64
- Windows (MSVC and MinGW)
- Alpine Linux (musl)
- CentOS 7
- WASM/WASI
- Compiler base tests
Documentation
Primary Documentation Sources
- Official Website: https://kcl-lang.io/
- User guides, language tour, API reference
- Installation instructions
- Tutorial and examples
- Repository Documentation:
/README.md- Project overview and quick start/README-zh.md- Chinese documentation/docs/dev_guide/- Developer guide1.about_this_guide.md- Guide overview2.quick_start.md- Building and setup3.coding_conventions.md- Code style4.architecture.md- Compiler architecture5.source_code.md- Source code structure6.languager_server.md- LSP implementation
- Governance:
/GOVERNANCE.md- Project governance (CNCF sandbox)/CODE_OF_CONDUCT.md- Community guidelines/ADOPTERS.md- Production users/MAINTAINERS- Maintainer list
Language Design Principles
- Spec-driven: Independent syntax and semantics specification
- Functional: Low side-effects, no system-level operations (no threads/IO)
- Constraint-based: Schema + Rule + Lambda for configuration validation
- API-first: Multi-language SDKs (Rust, Go, Python, .NET, Java, Node.js)
- Cloud-native: Native support for OpenAPI, K8s CRD, KRM spec
- Type Safety: Static type system with constraints and validation rules
Development Workflow
Setting Up Development Environment
# Recommended: Use Docker builder image
docker pull kcllang/kcl-builder
# Or install dependencies locally
# - Rust 1.91+
# - Python 3.x (for tests)
# - Protobuf compiler
# Build the project
make build
# Run tests
make test
make test-grammarIDE Support
- Full Language Server Protocol (LSP) support
- VSCode extension available
- Rust-analyzer recommended for Rust development
- Dev container configuration in
.devcontainer/
Notable Features
- Production-Ready: Used by major companies for large-scale Kubernetes management
- Multi-Platform: Exceptional cross-platform support including ARM and WASM
- Rich Ecosystem:
- Kubectl, Kustomize, Helm, KPT, Crossplane plugins
- Package registry at artifacthub.io
- Integration with GitOps workflows
- Developer Experience:
- Full LSP implementation with IDE support
- Comprehensive tooling (format, lint, test, vet)
- Extensive test coverage and fuzzing
- Performance Focus:
- WASM compilation target
- Size-optimized release builds
Git Workflow
- Main branch:
main(use this for PRs) - License: Apache License 2.0
- Current version: 0.11.2
- Recent focus areas: YAML serialization fixes, LSP formatter improvements, documentation
Important Notes for AI Assistants
- Always check existing code patterns - This is a mature codebase with established conventions
- Test coverage is critical - Add tests for any new functionality
- Performance matters - This is used in production for large-scale configurations
- Cross-platform support - Consider multiple platforms when making changes
- Documentation - Keep docs in sync with code changes
- The codebase uses workspaces - Changes may affect multiple crates
- Recent migration from serde_yaml to serde_yaml - Use the new library
Quick Reference
| Task | Command |
| Build | make build |
| Test | make test |
| Format | cargo fmt |
| Lint | cargo clippy |
| Grammar tests | make test-grammar |
| Build LSP | make build-lsp |
| Build WASM | make build-wasm |
| Release build | make release |
Support
- Official website: https://kcl-lang.io/
- GitHub: Current repository
- CNCF: Sandbox project with formal governance
Trending
Quiet this year.about the whole repository
Who's talking about kcl-lang/kcl
- NixOS/nixpkgs“update kcl to version 0.9.3”GitHub · Jul 15, 2024 · 6 reactions
- kcl-lang/krm-kcl“New release (kpm and proxy variables)”GitHub · Aug 13, 2025 · 2 reactions
- kcl-lang/kcl-lang.io“[Example Issue] kcllang/kcl:latest docker image has problems processing variables.”GitHub · Mar 5, 2024 · 2 reactions
- cncf/sandbox“[Sandbox] KCL”GitHub · Jul 24, 2023 · 2 reactions
- NixOS/nixpkgs“kcl-language-server: bump to 68b4062 to fix build with Rust 1.89”GitHub · Oct 26, 2025 · 1 reactions
The biggest 5 of 23 mentions linking to the repository that our crawl found. Each line is their own headline.
See all 23
Talked about on GitHub and Bluesky (23 times).
On GitHub · 22
- Jul 15, 2024update kcl to version 0.9.3 — NixOS/nixpkgs6 reactions · 6 comments
- Aug 13, 2025New release (kpm and proxy variables) — kcl-lang/krm-kcl2 reactions · 4 comments
- Mar 5, 2024[Example Issue] kcllang/kcl:latest docker image has problems processing variables. — kcl-lang/kcl-lang.io2 reactions · 3 comments
- Jul 24, 2023[Sandbox] KCL — cncf/sandbox2 reactions · 18 comments
- Oct 26, 2025kcl-language-server: bump to 68b4062 to fix build with Rust 1.89 — NixOS/nixpkgs1 reaction · 5 comments
17 more on GitHub
- May 10, 2025kclvm: 0.11.1 -> 0.11.2 — NixOS/nixpkgs1 reaction
- Feb 10, 2025fix: fix escape error in document — kcl-lang/kcl-go1 reaction · 2 comments
- Nov 30, 2024kclvm_cli: 0.10.3 -> 0.10.8 — NixOS/nixpkgs1 reaction
- Oct 20, 2024kclvm_cli: 0.10.0 -> 0.10.3 — NixOS/nixpkgs1 reaction
- Sep 16, 2024kclvm_cli: 0.9.3 -> 0.10.0 — NixOS/nixpkgs1 reaction · 2 comments
- Jul 16, 2024kclvm_cli: 0.8.7 -> 0.9.0 — NixOS/nixpkgs1 reaction · 1 comment
- Jul 15, 2024buildGoModule: `dontStrip = true` for go binary dependent on external binaries and libraries crashes on darwin — NixOS/nixpkgs1 reaction
- Jun 20, 2024fix: optional attr min and max validation generation — kcl-lang/kcl-openapi1 reaction · 1 comment
- Jun 11, 2024Question about the order of LSP requests and notifications (didChange and semanticTokens) — microsoft/vscode-languageserver-node1 reaction · 6 comments
- Dec 25, 2023[Track] Enhancement KCL IaC Security through a CodeQL approach. — kcl-lang/codeql-kcl1 reaction
- Aug 29, 2023feat: generate kcl data from json — kcl-lang/kcl-go1 reaction · 1 comment
- Aug 8, 2023feat: support more keywords when generating from json schema — kcl-lang/kcl-go1 reaction · 1 comment
- Aug 7, 2023feat: generate documentation comments from json schema — kcl-lang/kcl-go1 reaction
- Jul 30, 2023feat: adds kcl — asdf-vm/asdf-plugins1 reaction
- Jul 19, 2023[WIP] [Sandbox] KCL — kcl-lang/kcl-lang.io1 reaction
- Sep 26, 2024[ bug ] panic: Undefined symbol "kclvm_service_new" on FreeBSD — kcl-lang/cli0 reactions · 2 comments
- Mar 8, 2024Configuration Language — keinsell/junkyard0 reactions
On Bluesky · 1
- Feb 7, 2025KCL allows developers to create modular, scalable, and stable configurations Key features include constraint-based records, functional… — @kube.archi1 likes and repost
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
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.

