What the agent does
The agent clones the repository into its own cloud sandbox and reads how the tests already run. In a library like sindresorhus/ky, package.json is an ESM package for Node 22 and later whose test script chains xo, npm run build, tsc --project tsconfig.test.json and ava; the ava block runs .ts files as modules through --import=tsx/esm with workerThreads off, and there is no coverage tool among the dev dependencies. .github/workflows/main.yml runs npx ava 'test/**' '!test/browser.ts' on macOS for three Node versions and a separate job that installs Playwright for test/browser.ts. The readme already shows a Codecov badge for the repository, but no job uploads anything, so the badge has nothing behind it. tsconfig.dist.json emits source maps with inlined sources, and .npmrc sets package-lock=false.
It wires coverage into the run that already exists rather than adding a second one. c8 goes into devDependencies, and a coverage script runs c8 --reporter=lcov --reporter=text-summary --include='source/**' ava 'test/**' '!test/browser.ts'. Because ava loads the tests with tsx, V8 reports coverage against the compiled modules and c8 maps it back through the source maps, so the report names source/core/Ky.ts, source/utils/body.ts and the other files under source/ rather than anything under distribution/. The browser file stays excluded on purpose: it serves the built distribution/ bundle to Chromium and WebKit through Playwright, and its coverage would describe the bundle, not the source. coverage/ is added to .gitignore next to distribution/.
Then it changes the workflow as little as possible. In the test job, the matrix entry for Node 22 runs npm run coverage instead of the bare ava command and uploads coverage/lcov.info with the Codecov action; the other two Node versions keep running the tests as before, since coverage from three runs of the same suite would be identical. The upload step is written for a public repository: it uses the action's OIDC option so no secret is needed, and the description says where to put a CODECOV_TOKEN if the team prefers one. The YAML follows .editorconfig, which asks for two-space indentation in .yml files while the rest of the repository uses tabs.
Before opening anything it runs npm install, npm run build and npm run coverage in its sandbox and reads the text summary and coverage/lcov.info to confirm the file paths are the TypeScript sources. It runs xo too, because the repository's lint step is the first thing npm test does and a new script line in package.json is fair game for it. The summary table is pasted into the pull request.
Start it with one API call
POST https://api.phoenix.so/o/{org}/sessions with this body:
{
"agent": "claude",
"input": "Add test coverage reporting to this TypeScript library's CI. Read package.json, .npmrc, .gitignore, .editorconfig, tsconfig.json, tsconfig.dist.json, tsconfig.test.json, readme.md and .github/workflows/main.yml first, and confirm no coverage tool is configured today and whether a coverage badge already exists. Add c8 as a dev dependency and a coverage script that wraps the existing ava command for the Node tests, excludes the browser test, includes only source/ and writes lcov and a text summary. Make sure the report maps to the TypeScript files under source/, not the built output. In the workflow, run the coverage script on one Node version and upload lcov.info to Codecov with the action's OIDC option, leaving the other matrix entries as they are. Add the coverage directory to .gitignore. In your sandbox run npm install, npm run build, npm run coverage and xo, check that lcov.info names files under source/, and open a pull request that lists the files changed and the coverage summary.",
"resources": [
{
"url": "https://github.com/your-org/your-app"
}
]
}- Get an API key. In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
- Send the request. POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
- Read what came back. Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.
What comes back
What comes back is a pull request touching package.json, .gitignore and .github/workflows/main.yml. The description shows the text summary from the sandbox run, names the first three files lcov.info lists to prove they are under source/, and explains why the browser test is outside the measurement.
The run's record holds the npm run build, npm run coverage and xo output, so a reviewer can see the suite passed under c8 with the same test selection CI uses, and that the lint step accepted the new script line.
Before merging, a reviewer confirms the repository is enabled on Codecov and either lets the OIDC upload stand or adds a token, and decides whether to set a threshold in a codecov.yml so a pull request that drops coverage gets a failing status rather than a comment.
Run it on every new library repository
An organisation that publishes several packages starts one run per repository. A handler on its own server receives GitHub's organisation webhook for a new repository, checks the repository has a package.json with a test script, and sends this request with that repository's URL in resources. Each run reads the test runner it finds, so a package on ava gets c8 around ava and a package on another runner gets the equivalent wrapper.
Every run lands in its own sandbox and opens its own pull request. The key that starts it reports each finished run to its webhook_url, so the handler can post the coverage summary where the maintainers read it.
The use case this job follows, with its automation and trigger: Hand off a long task.
Why run it on Rush?
Coverage in a TypeScript project fails in quiet ways: a report that names compiled files nobody edits, a browser test that drags the number down for the wrong reason, a badge that points at nothing. The agent reads the runner configuration, the loader and the tsconfig together and then runs the measurement in a sandbox, so the pull request arrives with the summary already in it and the file paths already checked.
The same request runs against every package an organisation maintains, each in its own sandbox with its own package.json read first, and each pull request keeps the command record. A maintainer reads the summary and the three-file diff together and spends their time on the threshold question only they can answer.
Frequently asked questions
Why c8 rather than Istanbul instrumentation?
c8 reads the coverage V8 collects while the tests run, so nothing is instrumented and the tests run as they do today. With tsx loading the .ts files and source maps available, it maps the result back to source/, which is what the report should name.
Why is the browser test left out?
It runs the built bundle in real browsers through Playwright, so the code it executes is distribution/, and its numbers would describe the bundle rather than the TypeScript. The Node tests cover the same source and are what the summary measures.
Does the upload need a secret?
For a public repository the Codecov action can authenticate with the workflow's OIDC token, which is what the pull request configures. If the team prefers a repository token, the description names the secret to add and the one line that changes.
Will it slow down CI?
Only one matrix entry runs under c8, and collecting V8 coverage adds little to a suite that already runs on three Node versions. The other two entries are unchanged.
More TypeScript library jobs
The same job on other stacks
- Add Test Coverage to CI for a Vapor App (Vapor)
- Add Vitest Coverage to CI for a Vite React App (Vite + React)
- Add Code Coverage to CI for a VS Code Extension (VS Code extension)