costroid

package module
v1.0.0-alpha.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 7, 2026 License: Apache-2.0 Imports: 1 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Costroid

Costroid is the cost check for pull requests. It runs a coding agent under a budget, records what the run cost per token class as FOCUS rows, and posts the figure on the pull request.

What a pull request gets

Each pull request gets one check, costroid, and one comment. The comment's first line states what the run cost and on what basis. For a recorded run of Claude Code 2.1.316 under claude-code-action on 2026-11-07, it reads:

This run cost USD 0.0391529 at list (Measured). Nothing held it to a budget.

The figure equals the total_cost_usd the run itself reported, as the recording's notes say. docs/comment-example.md is the whole comment, and costroid demo prints it.

Try it on a pull request

With costroid installed, from the root of your repository:

costroid init github --agent claude
gh secret set ANTHROPIC_API_KEY
gh label create costroid-agent
git switch -c try-costroid
git add .github/workflows/costroid.yml costroid.yml
git commit -m "Add the costroid check"
gh pr create --fill

init writes the workflow, pinned to the release the binary belongs to, and a costroid.yml that sets nothing yet. It prints the commands after it and runs none of them. The secret is an Anthropic API key: the workflow runs Claude Code with --bare, so a Claude subscription's token does not work. The label lets a maintainer start the agent on a first contributor's pull request. Each push to the pull request runs the agent again, with a budget of USD 5 for each run.

costroid doctor checks the repository before the pull request, and docs/troubleshooting.md lists what it prints. Already on claude-code-action? costroid init github --agent claude-code-action --existing .github/workflows/claude.yml prints the two blocks to add to the workflow you have, as docs/existing-workflow.md shows.

Bring your own key and your own agent. There is no account, and Costroid runs no service that your data goes to: the key stays in your repository's secrets, the rows stay in the job, and the ledger, if you run one, is yours.

Besides the agent's provider, the GitHub recipes that run an agent call one third-party service. They run step-security/harden-runner on the agent's job, which records the job's outbound calls and sends telemetry to its vendor. docs/recipes.md says what it costs and how to drop it.

Why it exists

An agent's own cost field is an estimate, and a budget flag can be weaker than it sounds. Costroid prices the agent's token counts against a pinned, dated catalog, and it writes down how the budget was enforced. A grade is never shown as stronger than it is.

Install

The commands below install 1.0.0-alpha.10, the release the recipes pin. It is a pre-release. Download the binary for your platform from the release, check it, and put it on your PATH:

curl -fsSLO https://github.com/Costroid/costroid/releases/download/v1.0.0-alpha.10/costroid-linux-amd64
curl -fsSLO https://github.com/Costroid/costroid/releases/download/v1.0.0-alpha.10/SHA256SUMS
grep ' costroid-linux-amd64$' SHA256SUMS | sha256sum --check
chmod +x costroid-linux-amd64
sudo mv costroid-linux-amd64 /usr/local/bin/costroid
costroid version

The last line prints costroid 1.0.0-alpha.10, catalog 0.1.0. The release holds four binaries: costroid-linux-amd64, costroid-linux-arm64, costroid-darwin-amd64 and costroid-darwin-arm64. For another platform, replace linux-amd64 in every line. On macOS, shasum -a 256 --check takes the place of sha256sum --check. Any directory on your PATH works in place of /usr/local/bin.

Each file is signed with cosign, keyless, by this repository's release workflow. To check a signature, with cosign 3 or later:

cosign verify-blob --bundle costroid-linux-amd64.sigstore.json \
  --certificate-identity https://github.com/Costroid/costroid/.github/workflows/release.yml@refs/tags/v1.0.0-alpha.10 \
  --certificate-oidc-issuer https://token.actions.githubusercontent.com costroid-linux-amd64

docs/verify.md checks the image as well.

In GitHub Actions, the action installs the release its own commit belongs to and checks it by its signature. The Claude Code and Codex recipes then need one secret, the provider's API key. docs/bases.md lists what each recipe takes, and what its figures read as a result. The same action is listed on the GitHub Marketplace as Costroid/costroid-action. To build from a checkout instead, with Go 1.27 or later:

make build

To keep rows in your own ledger, docs/install.md has the container, Compose and Helm shapes.

First command

The first command runs Claude Code, so it needs Claude Code installed and signed in, with a Claude subscription or an ANTHROPIC_API_KEY.

costroid run --budget-usd 5 --out rows.jsonl -- claude -p "Fix the failing test."

The agent's stream passes through to stdout. Costroid prints this to stderr, here for a recorded run with one subagent on a Claude subscription:

costroid: claude-code, 4 requests
costroid: 19 rows in rows.jsonl, catalog 0.1.0
costroid: USD 0.001619725 at list, List-equivalent, not billed
costroid: budget USD 5, agent-flag: client-side estimate, can pass the cap
costroid: warning: BillingAccountId reads unknown: pass --billing-account or set COSTROID_BILLING_ACCOUNT

rows.jsonl holds one FOCUS row per request per token class:

{"ChargeDescription":"claude-haiku-5-5 input_uncached tokens; agent-flag: client-side estimate, can pass the cap","ConsumedQuantity":"2","ListCost":"0.0000002","ListUnitPrice":"0.1","SkuMeter":"input_uncached","SkuPriceId":"anthropic:claude-haiku-5-5:global:standard:to-100000:input_uncached"}

That row is shortened. A full row has every column of the row contract, and every amount is a decimal string.

Next

Task Page
Run an agent on a pull request docs/recipes.md
Make the check required docs/required-check.md
Read a line of the job log docs/troubleshooting.md
Read the comment docs/comment-example.md
Read a result from an agent docs/agents.md
Configure a repository docs/configuration.md
Host the ledger docs/install.md, docs/serve.md
Compare a ledger with a provider's report docs/reconcile.md
See how Costroid's own figures match the provider's docs/accuracy.md
Take the rows to a warehouse docs/export.md
Verify a release docs/verify.md
See what a budget grade means docs/adapters.md
See what a cost basis promises docs/bases.md
See what changed in each release CHANGELOG.md

Licence

Apache-2.0. The CLI, the gate, the ledger schema, the plan schema, the FOCUS tag convention, the price catalog and the policy packs stay Apache-2.0 and are never relicensed. Contributions are under the Developer Certificate of Origin.

Documentation

Overview

Package costroid holds the published schema of costroid.yml.

Index

Constants

This section is empty.

Variables

View Source
var ConfigSchema []byte

ConfigSchema is the JSON Schema of costroid.yml.

View Source
var Recipes embed.FS

Recipes holds the CI recipes as this release ships them, under recipes/. A recipe's Costroid pin can name an earlier release, or none, because the commit that pins a release follows its tag. costroid init rewrites each pin to the release the binary belongs to.

Functions

This section is empty.

Types

This section is empty.

Directories

Path Synopsis
Package catalogdata embeds the pinned price sheets.
Package catalogdata embeds the pinned price sheets.
cmd
costroid command
Command costroid is the cost check for pull requests.
Command costroid is the cost check for pull requests.
internal
adapter
Package adapter holds what every agent adapter hands the wrapper.
Package adapter holds what every agent adapter hands the wrapper.
adapter/claudecode
Package claudecode reads Claude Code runs.
Package claudecode reads Claude Code runs.
adapter/codex
Package codex reads `codex exec --json` runs.
Package codex reads `codex exec --json` runs.
catalog
Package catalog prices token classes against the pinned sheets.
Package catalog prices token classes against the pinned sheets.
cicontext
Package cicontext reads what the CI system says about a run.
Package cicontext reads what the CI system says about a run.
comment
Package comment turns FOCUS rows into the check output and the sticky pull request comment.
Package comment turns FOCUS rows into the check output and the sticky pull request comment.
config
Package config checks a costroid.yml against the published schema.
Package config checks a costroid.yml against the published schema.
decimal
Package decimal is an exact base-10 number for money and quantities.
Package decimal is an exact base-10 number for money and quantities.
egress
Package egress is the one way out of costroid serve.
Package egress is the one way out of costroid serve.
fanout
Package fanout runs CPU-bound work over a list on every core the process has.
Package fanout runs CPU-bound work over a list on every core the process has.
focus
Package focus holds the Costroid FOCUS row, version 0.3, and its writer.
Package focus holds the Costroid FOCUS row, version 0.3, and its writer.
gateway
Package gateway gives one CI run its own key on a LiteLLM proxy.
Package gateway gives one CI run its own key on a LiteLLM proxy.
gateway/gatewaytest
Package gatewaytest serves the LiteLLM proxy routes costroid gateway calls, as LiteLLM v1.108.1 answered them on 2026-11-07, for tests.
Package gatewaytest serves the LiteLLM proxy routes costroid gateway calls, as LiteLLM v1.108.1 answered them on 2026-11-07, for tests.
history
Package history reads the result objects earlier reports posted on a pull request's commits, and adds their figures up with this run's.
Package history reads the result objects earlier reports posted on a pull request's commits, and adds their figures up with this run's.
oidc
Package oidc verifies CI OIDC ID tokens and reads a run's identity from them.
Package oidc verifies CI OIDC ID tokens and reads a run's identity from them.
oidc/oidctest
Package oidctest is a stub OIDC issuer for tests: an RSA key, a JWKS endpoint and a signer.
Package oidctest is a stub OIDC issuer for tests: an RSA key, a JWKS endpoint and a signer.
otlp
Package otlp reads OTLP/HTTP traces and logs into per-request usage.
Package otlp reads OTLP/HTTP traces and logs into per-request usage.
policy
Package policy decides the check's conclusion.
Package policy decides the check's conclusion.
recipelint
Package recipelint holds the shipped CI recipes to their security rules: no privileged trigger, every action pinned by SHA, and an agent's job that holds nothing but read access to the code.
Package recipelint holds the shipped CI recipes to their security rules: no privileged trigger, every action pinned by SHA, and an agent's job that holds nothing but read access to the code.
reconcile
Package reconcile compares the ledger with the provider's own reports, per credential per day, in two steps.
Package reconcile compares the ledger with the provider's own reports, per credential per day, in two steps.
run
Package run launches an agent under a budget and turns its usage into rows.
Package run launches an agent under a budget and turns its usage into rows.
scm
Package scm reaches a source-code host through one interface.
Package scm reaches a source-code host through one interface.
scm/scmtest
Package scmtest holds stub GitHub and GitLab APIs for tests.
Package scmtest holds stub GitHub and GitLab APIs for tests.
server
Package server is the ingest service behind costroid serve: the result-stream and OTLP paths, pricing against the pinned catalog, and the per-PR view.
Package server is the ingest service behind costroid serve: the result-stream and OTLP paths, pricing against the pinned catalog, and the per-PR view.
store
Package store is the ledger: FOCUS rows in Postgres, one tenant at a time.
Package store is the ledger: FOCUS rows in Postgres, one tenant at a time.
store/storetest
Package storetest runs Postgres in Docker for the packages that need it.
Package storetest runs Postgres in Docker for the packages that need it.
Package migrations embeds the forward-only schema migrations.
Package migrations embeds the forward-only schema migrations.
scripts
accuracy command
Command accuracy keeps the inputs of one day's reconciliation, writes the accuracy page from every day kept, and checks the page against them.
Command accuracy keeps the inputs of one day's reconciliation, writes the accuracy page from every day kept, and checks the page against them.
record command
Command record turns an agent's run into a test fixture that holds no content: no prompt, no reply, no tool output, no path and no credential.
Command record turns an agent's run into a test fixture that holds no content: no prompt, no reply, no tool output, no path and no credential.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL