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.1

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.1
File Size Uploaded
cgh_codegen-0.1.1.tar.gz 33.0 kB Details

Built distribution (wheel)

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

Total release size: 60.2 kB

Release files / cgh_codegen-0.1.1.tar.gz

Download URL cgh_codegen-0.1.1.tar.gz
Size 33.0 kB
Tags Source
SHA-256 checksum
How to use checksums
0c2b82168f8a070853f3a0daa0d5b91e4f5a6faf80450f4a6bc5ae0c0d86401a
BLAKE2b-256 checksum
How to use checksums
8afa63f7c316ab34469ec91170cd3e1e0f35b5d4717af46f2402b7b2241a1b6f
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 29, 2026.

Transparency log

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

Download URL cgh_codegen-0.1.1-py3-none-any.whl
Size 27.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
51c5a300dff9686c2e1411332a431e821f0c8733888d3fb7ccb170435ce6ead0
BLAKE2b-256 checksum
How to use checksums
55b36918344b26220dca2c211842d62e31864a29b97e7a3a92eca50bd6d1771f
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 29, 2026.

Transparency log

Release history Release notifications | RSS feed

0.1.2

2 release files

This release

0.1.1 This release

2 release files

0.1.0

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