When you hand issues, or work items, to AI coding agents, each issue can mix human and agent work. Telemetry is the usage data an agent exports. A session groups an agent's execution; tokens are units used to count model input and output. Claude Code can report tokens and cost for a session, but its standard telemetry attributes don't identify the issue it serves.
If you can link each run to its issue, you can line up, per issue, how many times AI ran, what it cost, and how continuous integration (CI) and review went. That turns rework, cost hot spots, and the places agents got stuck into something you can discuss in the same unit you plan with.
The obstacle is that runs and issues share no reliable key. Some work happens on branches without an issue ID, some happens on the default branch, and some agents don't emit a session ID at all, so you can't link every run with certainty. If you silently drop the runs you can't link, or blend guessed links into confirmed ones, the numbers look precise and still point you the wrong way.
This guide uses the Harnessforce correlation specification as a design example. It assigns each link a confidence score from 0.0 to 1.0, with 0.8 or above counting as confirmed. The link rate is the share of runs in a period that have a confirmed issue link. The specification sets a target of 80% or higher for that rate. These thresholds belong to this design; they aren't universal standards for every team.
Below, we'll cover the types of values you can measure per issue, the 4 capabilities per-issue measurement needs, and how to operate and improve it over time.
In this article
Start with the types of measurements, then work through the capabilities and operating practices. The role-based section gives you a starting point for your responsibilities.
- Types of per-issue measurements
- 4 capabilities per-issue measurement needs
- Operating and improving per-issue measurement
- Getting started by role
Types of per-issue measurements
Per-issue measurements fall into 3 groups: values from the agent's runs, values from pull requests (proposals to merge code changes), CI, and review, and values that describe the link itself. You need the third group to roll up the first two. Without it, you can't tell whether an issue was cheap or whether its runs simply never got linked.
| Group | Examples | Source |
|---|---|---|
| Run values | Number of runs, tokens, cost, duration, tool calls and failures | Agent telemetry |
| Delivery values | Pull requests, CI failures, changes requested in review | GitHub and similar records |
| Link values | Confirmed, inferred, unlinked, not measured | Your linking rules |
For Claude Code, run values come from events, records of individual occurrences (monitoring documentation). Each api_request event carries model, input_tokens, output_tokens, cache_read_tokens, cache_creation_tokens, duration_ms, and cost_usd. Each tool_result event reports whether an operation the agent invoked, or tool, succeeded in success.
Be careful with cost. The documentation describes cost_usd as an estimated cost, so treat it as an estimate rather than your invoice. The Harnessforce specification uses the cost the agent reports when it exists. Otherwise, it calls for an estimate from a per-model price table and token counts, labeled as an estimate. When the agent reports no cost and the price table lacks a model needed for estimation, Harnessforce leaves the cost blank.
4 capabilities per-issue measurement needs
Per-issue measurement needs 4 capabilities: identifying runs, linking them to issues through several routes, keeping confirmed links apart from inferred ones, and showing what you couldn't collect. Without any one of them, you can still produce per-issue numbers, but you can't tell whether to trust them.
1. Identify runs by session
Use one agent session as the unit you link to an issue. Claude Code defines session.id as a standard attribute for metrics (aggregate measurements) and events, but metrics can omit it when OTEL_METRICS_INCLUDE_SESSION_ID=false. Do not assume it will always arrive.
Events also carry prompt.id, which ties together the events produced while handling one user instruction, or prompt. With the session as the unit, the tokens, cost, and tool failures from the start of a request to its end roll up into one run. We have a guide to Claude Code OpenTelemetry that covers turning this telemetry on.
Telemetry alone doesn't give you what you need to find the issue: the repository, branch, and commit. Setting OTEL_METRICS_INCLUDE_REPOSITORY=true (Claude Code v2.1.269 or later) adds repository attributes. It's off by default, though, and none of those attributes carries the branch. The Harnessforce design collects the repository, branch, and commit with a hook, a command triggered at session start.
Joining hooks to telemetry has a catch of its own. The hooks documentation states that the prompt_id a hook receives matches the prompt.id on telemetry events. It says nothing about the hook's session_id matching telemetry's session.id. Harnessforce therefore treats a hook record and a telemetry session as the same run when either the session ID or the first prompt ID matches.
2. Link runs to issues through several routes
One route may not link every run, so set up several routes of different strength and give each one a confidence level. These are the routes and confidence levels Harnessforce designed.
| Route | How it works | Confidence |
|---|---|---|
| Explicit | The engineer names the issue when starting the run | 1.0 with authenticated-user credentials; 0.6 for registration through a shared Workspace key |
| Manual | Someone links, or unlinks, a run and an issue by hand | 1.0 to confirm; unlinked relationships are excluded |
| Key pattern | An issue ID appears in the branch name, pull request title or body, or a commit message | 0.9 |
| Run to pull request | The run's repository and branch match the pull request's repository and head branch, and the run starts before merge or close | 0.9 |
| Transitive | Run to pull request, then pull request to issue | Lowest confidence along the path |
| Inferred | Same repository, and a pull request that was open when the run started | 0.6 or lower |
Explicit-link confidence also depends on authentication. A Workspace groups users and data within Harnessforce, and an IngestKey is a key used to send data. A shared Workspace key cannot establish the user identity. This also applies to registrations from the command-line interface (CLI) or the Model Context Protocol (MCP), which connects AI agents to tools. With that shared key, naming the issue gives a confidence of 0.6, not a confirmed link.
For a transitive link, take the lower of the 2 steps on each path, and when there are several paths, take the highest of those. For example, say a branch match (0.9) links a run to a pull request, and Fixes #45 in the pull request body (0.9) links that pull request to an issue. The run then links to the issue at 0.9.
The key pattern matching is case-insensitive and looks for shapes like these.
| Shape | Example | Resolved within |
|---|---|---|
KEY-number | ENG-42, branch eng-42-login | Any repository in the same Project |
owner/repo#number | acme/api#45 | The named repository |
#number | Fixes #45 | The repository of the branch, pull request, or commit |
gh-number | branch gh-45-fix | Branch names only, in that branch's repository |
To avoid false matches, an ID only counts when the character before KEY isn't alphanumeric and the character after the digits isn't a digit, so XENG-42 doesn't match ENG-42. An ID found in a commit message links through a pull request that contains the commit. A commit that isn't in any pull request links to nothing.
3. Keep confirmed and inferred apart
In this design example, count links at 0.8 or above as confirmed, and label everything below as inferred. For runs without a confirmed explicit reference or manual link, automatic inference covers repository matches without a branch and runs on the default branch. If exactly 1 pull request in that repository was open when the run started, the link gets 0.6. If 2 or more were open, each gets 0.4, and if none were, there's no link. A transitive link built on an inferred step never becomes confirmed.
When issues from different sources share an ID and a reference doesn't say which one it means, link to every candidate at 0.6 and let a person confirm. Once someone removes a link by hand, no other route adds it back.
The link rate shows how much of the received activity has a confirmed link to an issue.
Link rate = runs in the period confirmed against an issue ÷ runs received in the period
For example, if you received 50 runs in a week and confirmed 42 of them against issues, the link rate is 84%. These numbers only illustrate the calculation; they aren't measurements.
4. Show unlinked and unmeasured explicitly
Keep runs you couldn't link and values you couldn't collect separate from zero and from empty. List runs without a confirmed link to any issue as unlinked, and let people pick the right issue from that list. Show sources you haven't connected as not connected, areas you don't measure as not measured, and inferred relationships as inferred.
Apply the same rule to missing values. In the Harnessforce specification, a run with no api_request events gets a blank token count, not zero. Telemetry without a session ID doesn't produce runs, and Harnessforce reports that gap when that telemetry is arriving. Once you can see where coverage stops, you can tell a genuinely small number from a gap in measurement.
Operating and improving per-issue measurement
Once measurement is running, review the link rate and the unlinked runs on a regular cadence and remove the causes one by one. Start by checking how work was started and which identifiers arrived.
- Put the issue ID in the branch name: A branch like
eng-42-loginorgh-45-fixsupplies an issue ID for key-pattern matching and can be matched to a pull request on the same branch. - Reference the issue in the pull request body: Writing
Fixes #45links the pull request to the issue even when the branch name has no ID. - Don't rely on automatic inference alone. A run on the default branch linked only through automatic inference stays out of confirmed totals. A link established through another route that meets the confirmation criteria, such as an authenticated explicit reference or a manual link, does count.
- Link unlinked runs regularly: When someone links an unlinked run by hand, it can be included in that issue's history and cost total. A manual link has a confidence of 1.0.
- Change something at every review: Harnessforce counts deciding at least one process change per weekly review, based on per-issue data, as one of the success measures for a rollout.
Sometimes a pull request exists before its issue does. The Harnessforce specification stores unresolved IDs and links them if the issue is created within the specified time window.
How Harnessforce can help
Building your own linking rules and maintaining confidence levels and unlinked lists takes real effort. Harnessforce shows AI runs issue by issue.
Harnessforce can help you:
- Turn AI work into data: Harnessforce turns AI work into data your team can analyze.
- Follow every issue: For each issue, see how many times AI ran, what it did, what it cost, and how CI and review went, then inspect traces (operation flows), logs (event records), and metrics (aggregate measurements).
- Show gaps as gaps: Anything that can't be collected is marked as not measured, never shown as if it had been collected.
- Say what happens to content: Prompt and response content arrives only from machines that send it. Machines send it by default, and each member can stop it on their own machine. The workspace decides whether it is stored, who can read it, and for how long.
- Work alongside your tools: Harnessforce doesn't replace the tools you already use; it runs alongside them.
Read the Harnessforce installation guide, or talk to us.
Getting started by role
Engineers leave issue IDs in their work, while team leads check the link rate. If you build the pipeline, start by matching identifiers between hooks and telemetry.
Engineers
Create a branch that includes the issue ID before you start, and reference the issue in the pull request body, as in Fixes #45. Those 2 habits let your runs link at 0.9 through both the branch name and the pull request body.
Engineering managers and PMs
Check the link rate first to see how much of the received activity is included in issue totals. While the rate is low, fix the causes of unlinked runs before you compare cost or run counts across issues.
Whoever builds the pipeline
Collect the repository, branch, and commit with a hook at session start, and join hooks to telemetry on the hook's prompt_id and the event's prompt.id. Plan for session IDs that don't match by also joining on the first prompt ID.
Glossary
These terms follow the Harnessforce design example used in this guide. A run is the unit of work; confidence describes the strength of its link to an issue. Keep confirmed, inferred, unlinked, and not measured distinct when you read the totals.
Run
The work from one agent session. Tokens, cost, and tool calls are totaled per run.
Confidence
A value from 0.0 to 1.0 that says how certain a link between a run and an issue is. Each route sets its own value, and a transitive link takes the lowest value along its path.
Confirmed link
A link with a confidence of 0.8 or higher. Only runs with confirmed links count toward issue totals.
Inferred link
A link of 0.6 or lower, based on a matching repository and overlapping time. It's labeled as inferred and kept out of confirmed totals.
Link rate
The share of runs received in a period that have a confirmed link to an issue.
Unlinked and not measured
An unlinked run has no confirmed link to any issue. Not measured marks an area you don't collect, shown separately from zero and from empty.
This guide was written with AI assistance and reviewed by the author.