Skip to main content

cgh-codegen

A cgh plugin that delegates predictable, pattern-following code (tests, stubs, config, boilerplate) to a cheap model so the primary model spends no tokens producing it. Its distinguishing move: cgh picks the reference file to mirror straight from the code graph, so you do not have to name it.

Installs through cgh's plugin entry point. Inert without cgh.

Surfaces

cgh codegen pick

Report the existing file a generator should mirror for a target, and why.

cgh codegen pick --target tests/test_user_service.py
# reference: tests/test_order_service.py
# defines a matching symbol, sibling in the same directory

The pick combines two signals: the graph (a file defining a symbol related to the target's name) and the filesystem (a sibling of the same kind in the target's directory). It degrades to a filesystem-only pick when the graph is not readable (no index yet, or an owner holds the write lock). Pass --reference to validate a specific file instead.

cgh codegen gen

Generate a file from a spec, mirroring the reference, and write it.

cgh codegen gen --spec "pytest tests for UserService: create, update, delete" \
                  --target tests/test_user_service.py

The reference (picked, or forced with --reference) is run through the egress gate before it reaches a cloud model: a confidential or PII-labeled reference is refused. A local backend skips the gate. An existing target is never overwritten without --force; --stdout prints instead of writing.

--extend grows a file that already exists instead of writing a new one:

cgh codegen gen --extend --target tests/test_user_service.py \
                  --spec "add a test for the soft-delete path" \
                  --verify "pytest tests/test_user_service.py -q"

The file itself goes to the model as the thing to add to, and the model returns only the block to append, so nothing already in the file passes through the model's output and nothing can be dropped from it. The block lands before a trailing if __name__ == "__main__": guard rather than after it. With --verify, a check that never passes restores the original: a damaged existing file is worse than no change, which is the opposite of the tradeoff for a new file, where the failed draft is left for you to read. Anything the addition needs must already be imported in the file.

Configure the backend in .codegraph/config.toml:

[plugin.codegen]
command = "claude -p"   # any agent CLI, invoked with the prompt on stdin

The generated code is a proposal. Verify it by running the type-checker, linter, or tests, never by trusting that it is correct because a later check was green. This matters most for generated tests: a green run of tests you did not read proves nothing.

codegen_pick and codegen_write (MCP tools)

codegen_pick(target, reference?) returns the selection as JSON. codegen_write(spec, target, reference?, force?) generates and writes the file, returning what it wrote, the reference used, the egress decision, and the cost. Both run inside the owner, so the graph read reuses its connection.

License

MIT. Plugins that interact with cgh only through the documented plugin interfaces are not derivative works of cgh.

Metadata

Release files for cgh-codegen 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 cgh-codegen 0.1.0
File Size Uploaded
cgh_codegen-0.1.0.tar.gz 31.6 kB Details

Built distribution (wheel)

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

Total release size: 58.0 kB

Release files / cgh_codegen-0.1.0.tar.gz

Download URL cgh_codegen-0.1.0.tar.gz
Size 31.6 kB
Tags Source
SHA-256 checksum
How to use checksums
43991cde0c796d46101e122fb69e3494813566871ca2a3659ddcf0b20f7d0ae1
BLAKE2b-256 checksum
How to use checksums
c14efcea310dca24b58749c73d67397ba20f3f0aea55cc22aa18ecccf37ae36b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 22, 2026.

Transparency log

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

Download URL cgh_codegen-0.1.0-py3-none-any.whl
Size 26.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a0e8bf2dabdc046401fc98ff29a239176edad363617ef866d183182d87f54314
BLAKE2b-256 checksum
How to use checksums
b0c93064db0fd3bc85247ba17dabf01b9a78f64f04374e736732c3e9cd4a5a4c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 22, 2026.

Transparency log

Release history Release notifications | RSS feed

0.1.2

2 release files

0.1.1

2 release files

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