# Linking sessions to issues

Harnessforce links sessions, pull requests, and CI runs to issues and counts only confirmed links, with confidence of 0.8 or higher, toward an issue.

```sh
/plugin marketplace add lambda-script/harnessforce-agent
/plugin install harnessforce@harnessforce-agent
/harnessforce:setup
```

Harnessforce links sessions, pull requests, and CI runs to issues automatically, and records how certain each link is as a confidence value from 0.0 to 1.0. Links with a confidence of 0.8 or higher are confirmed links, and only confirmed links count toward an issue's totals. Anything below that is labeled "Inferred."

Put the issue identifier in your branch name and linking happens without extra work. For example, if you work on the branch `eng-42-login` and open a pull request, both the pull request and the runs on that branch link to ENG-42.

## How links are made

Each path has its own confidence. When several paths link the same pair, Harnessforce uses the highest confidence.

| Path        | How it works                                                                                                                                                                                       | Confidence                  |
| ----------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------- |
| Hook        | The plugin hook registers the session's repository, branch, and commit, and sends the branches the session worked on along the way (work locations), which link to an issue through a pull request | Transitive value            |
| Import      | `harnessforce import` registers past sessions, which link to an issue through a pull request                                                                                                       | Transitive value            |
| CLI         | `harnessforce run --issue` resolves the issue when it starts                                                                                                                                       | 1.0                         |
| MCP         | The agent registers the issue and session through the MCP server's `start_session`                                                                                                                 | 1.0                         |
| Manual      | Someone links it in the app                                                                                                                                                                        | 1.0                         |
| Key pattern | Detects issue identifiers in branch names, pull request titles and descriptions, and commit messages                                                                                               | 0.9                         |
| Head SHA    | Links a CI run to a pull request when the check run's `head_sha` matches the pull request's head SHA                                                                                               | 1.0                         |
| Transitive  | Follows session → pull request and pull request → issue to link the session and the issue                                                                                                          | Lowest value along the path |
| Inferred    | Estimated from overlapping repository, branch, and time                                                                                                                                            | 0.6 or lower                |

If a CLI or MCP registration that names an issue arrives with a workspace ingest key, its confidence is 0.6 and it doesn't become a confirmed link.

## How transitive confidence works

A transitive link takes the lower confidence of its two steps. If there are several paths, Harnessforce uses the highest of them.

For example, if you open a pull request from the branch `eng-42-login`:

1. **The pull request links to ENG-42.** The key pattern finds `eng-42` in the branch name, with a confidence of 0.9.
2. **The session links to the pull request.** The session's repository and branch (the branch at the start of the session or a work location's branch) match the pull request's head branch, and the session started before the pull request was merged or closed, so the confidence is 0.9.
3. **The session links to ENG-42.** *min(0.9, 0.9) = 0.9*, which is 0.8 or higher, so it's a confirmed link.

## Branches the session moved to

Work that moves to a worktree or a new branch after the session starts also links to that branch's pull request. The hook records the repository and branch of the places the agent worked (the working directory and the Git working tree of each file it edited) as work locations, and sends them at the end of a turn in which they changed.

* It sends only the repository and the branch. It doesn't send paths, commits, file names, or the content of edits.
* In Claude Code it watches the working directory and files edited with `Write` and `Edit`. In Codex it watches files edited with `apply_patch`.
* A session linked through a work location still shows the branch at the start of the session in the app and the API.
* In Codex, work locations are sent once you trust all three hooks (`SessionStart`, `PostToolUse`, and `Stop`) in `/hooks`. On a machine set up with an earlier `harnessforce login`, run `harnessforce login` again.

## Writing issue identifiers

The key pattern recognizes these forms. Matching is case-insensitive.

| Form                      | Example                         | Resolved within                                               |
| ------------------------- | ------------------------------- | ------------------------------------------------------------- |
| `KEY-<number>`            | `ENG-42`, branch `eng-42-login` | The project the pull request was received into                |
| `<owner>/<repo>#<number>` | `acme/api#45`                   | The project the pull request was received into                |
| `#<number>`               | `Fixes #45`                     | The repository of the scanned branch, pull request, or commit |
| `gh-<number>`             | branch `gh-45-fix`              | Branch names only, in that branch's repository                |

* `KEY` is one of your workspace's project keys.
* A `KEY` preceded by a letter or digit isn't detected. For example, `XENG-42` isn't read as ENG-42.
* `#<number>` and `gh-<number>` resolve to GitHub Issues in that repository, never to pull request numbers.
* Identifiers in commit messages link through the pull request that contains the commit.
* If a pull request arrives before its issue, the link is made when the issue is created, as long as that happens within 90 days of detection.

## Starting a session for a specific issue

To make sure work links to an issue even when the branch name doesn't contain its identifier, start the agent with `harnessforce run` and name the issue:

```sh
harnessforce run --issue ENG-42 -- claude
```

If the identifier can't be resolved, `harnessforce run` doesn't start the agent.

## Inferred links

When a session has no branch, or its branch is the default branch, Harnessforce infers its relationship to pull requests in the same repository. A session with a work location on a branch other than the default branch in that repository isn't inferred, because the branch it worked on is known:

* If exactly one pull request was open when the session started, it links them with a confidence of 0.6.
* If two or more were open, it links the session to each with a confidence of 0.4.
* If none were open, it doesn't link anything.

A session-to-issue link derived from an inferred link never becomes confirmed. When an `<owner>/<repo>` name isn't the current name of any repository but a former name of two or more, Harnessforce links the issue in every candidate repository with a confidence of 0.6 and waits for someone to confirm the right one.

## How links appear in the app

* On an issue, sessions with confirmed links appear under "Sessions" and "History."
* Links that aren't confirmed are labeled "Inferred" and left out of confirmed totals.
* Sessions with no confirmed link to any issue are listed as "Not linked," and you can link them to an issue right there.
* Members and above can link and unlink manually. A link you remove by hand never comes back through later syncs or reprocessing.

The share of sessions received in a period that have a confirmed link to an issue is called the correlation rate.

## Read next

* [Sessions](/en/docs/concepts/session): What a session is and what it contains
* [Fidelity](/en/docs/concepts/fidelity): The "Inferred" and "Not linked" labels
* [Configure Claude Code](/en/docs/claude-code): What the hooks and `harnessforce run` do
