Skip to main content

Codemixture

A literate programming system for the AI coding era.

Programs are written as markdown documents with executable code in standard fenced code blocks. The prose — design rationale, specifications, constraints, prompts — is interwoven with the code. The documents are simultaneously human-readable documentation, AI-readable context, and executable programs.

The Problem

Code and documentation live in separate worlds. Comments rot. READMEs drift. Design docs go stale the moment code ships. AI coding agents work from context that's scattered across files, commit messages, and Slack threads.

The Idea

What if the documentation was the program? What if the markdown you write to explain your design also contained the code that implements it?

Codemixture documents are valid CommonMark. Code lives in standard fenced code blocks. Metadata lives in invisible HTML comments. Macros are expressed as comments in the target language. Everything renders correctly on GitHub, in VS Code, in any markdown viewer — with zero preprocessing.

Example

Here's a complete codemixture document:

# Hello World

<!-- codemixture
type: module
file: hello.py
language: python
-->

A simple greeting program.

```python
def main():
    print("Hello from codemixture!")

if __name__ == "__main__":
    main()
```

Run cm tangle hello.md and out comes hello.py.

For more complex programs, named sections let you define code in the order that makes sense for explanation, then assemble it in the order the language requires:

```python
# @begin(imports)
import sys
# @end(imports)
```

Later, we can include that section:

```python
# @include(imports)

def main():
    print("hello")
```

Quick Start

# Clone and bootstrap
git clone <repo-url> && cd codemixture
python3 bootstrap.py tangler.md
python3 bootstrap.py cli.md

# Install with uv
uv sync --all-extras

# Tangle, check, test
uv run cm tangle tangler.md cli.md checker.md watcher.md
uv run cm check tangler.md cli.md checker.md watcher.md
uv run pytest tests/ -v

How It Works

Tangling extracts executable code from .md files:

cm tangle mymodule.md              # Single file
cm tangle *.md                     # Project (enables cross-document refs)
cm tangle mymodule.md --dry-run    # Preview without writing

Checking validates documents without tangling:

cm check *.md           # Report errors and warnings
cm check *.md --strict  # Treat warnings as errors

Watching re-tangles on file changes:

cm watch *.md           # Requires: pip install codemixture[watch]

Initializing scaffolds a new project:

cm init myproject --language python

Self-Hosting

Codemixture is written in codemixture. The .md files in this repository are the source of truth:

Document Produces Description
tangler.md tangle.py The tangler — code extraction and macro resolution
cli.md cli.py, __init__.py The cm command-line tool
checker.md check.py Document validator
watcher.md watch.py File watcher with debouncing

bootstrap.py is the only non-.md Python source — a minimal ~90-line tangler that bootstraps the real one.

Format Specification

See codemixture.md for the complete format specification, including:

  • Document anatomy (prose, code, metadata)
  • The macro system (@begin/@end, @include, @append)
  • Cross-document references
  • Multiple output files
  • Metadata fields

License

MIT

Release files for codemixture 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for codemixture 0.1.0
File Size Uploaded
codemixture-0.1.0.tar.gz 10.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for codemixture 0.1.0
File Interpreter ABI Platform
codemixture-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 25.0 kB

Release files / codemixture-0.1.0.tar.gz

Download URL codemixture-0.1.0.tar.gz
Size 10.9 kB
Tags Source
SHA-256 checksum
How to use checksums
cae8db8977847404e444f88ee65a89e72c37a5fb7672bde233dc9465066e6ace
BLAKE2b-256 checksum
How to use checksums
f69a6b0667a9f4add6e796a672157eb1c8165258a7be2d6c4f813d5615f7775f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.19

Release files / codemixture-0.1.0-py3-none-any.whl

Download URL codemixture-0.1.0-py3-none-any.whl
Size 14.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2713ed6830cfe20bf3e68f1fc0d42e5cdef5a2284d4dce96f230858e5cc8509f
BLAKE2b-256 checksum
How to use checksums
a51c0acb21a38ad1bbe93b37be2910112dd1b5459f3152b97f184cfdb37f1d73
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.19

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page