# Link sessions to issues

Get a session onto an issue's history in one of three ways. Name the issue, put its number in the branch name, or pick it afterwards.

A session appears on an issue's history once it has a confirmed link (confidence 0.8 or higher) to that issue. There are three ways to get one. Name the issue when you hand over the work, put the issue's number in the branch name, or pick the issue after the session ends. However the link is made, the session shows up on the issue screen the same way.

## Name the issue when you start

### Claude Code

1. In Claude Code with the Harnessforce plugin installed, include the issue key in your request, for example "Fix HF-123".
2. The agent checks the issue with `get_issue` and registers the session for it with `start_session`. If you name the issue partway through, the work before that point is included too.
3. If you start work that will commit changes without naming an issue, the agent offers up to five existing issues and asks once whether to pick one. If you don't, it carries on without a link. The agent never creates issues.

Registering a session needs the Member role or higher. For viewers, or while the workspace is read-only, the agent tells you why it can't link the session and keeps working.

### Codex, or deciding at launch

Start the agent through `harnessforce run` with the issue, and the session is linked from the moment it starts.

```sh
harnessforce run --issue HF-123 -- codex
```

If the issue can't be found, `harnessforce run` doesn't start the agent.

> **Note:** **On machines set up with your organization's managed settings**
>
> Registrations that arrive with a workspace ingest key get confidence 0.6, even when the issue was named or passed to `harnessforce run --issue`, so they don't become confirmed links. To get these sessions onto the history, use the branch name or pick the issue afterwards.

## Put the issue number in the branch name

1. Create a branch whose name includes the issue identifier, such as `hf-123-retry` or `gh-45-fix`.
2. Work on that branch and open a pull request.
3. The GitHub App links the pull request to the issue from the branch name, and sessions that ran on that branch are linked to the issue through the pull request. The session must have started before the pull request was merged or closed.

These forms are detected, ignoring case. Identifiers in pull request titles, descriptions and commit messages are detected too.

| Form                      | Example                         | Resolves to                                           |
| ------------------------- | ------------------------------- | ----------------------------------------------------- |
| `KEY-<number>`            | `HF-123`, branch `hf-123-retry` | An issue in the pull request's project                |
| `<owner>/<repo>#<number>` | `acme/api#45`                   | An issue in the pull request's project                |
| `#<number>`               | `Fixes #45`                     | The repository of that branch, pull request or commit |
| `gh-<number>`             | branch `gh-45-fix`              | Branch names only, in that branch's repository        |

* `KEY` is a project key. Identifiers that point to an issue in another project don't create a link.
* Sessions that stay on the default branch, and pull requests whose head is the default branch, aren't linked by branch match.
* If a session moves to another branch or worktree partway through, that work still links to the pull request on the branch it moved to.

How confidence is decided: [Linking sessions to issues](/en/docs/concepts/issue-linking)

## Pick the issue afterwards

A session with no confirmed link to any issue stays in Sessions as unlinked.

1. Open Sessions in the sidebar and, under Work, set Issue to "Not linked".
2. Click the session to open it, then click "Link to issue".
3. Search issues by identifier or title, pick one and click Link.

You can also link from a trace.

1. In the span details of a trace, click "Link to issue".
2. "Link this trace to an Issue" opens. If the session is already linked, you'll see why (for example "It is linked to HF-123 automatically, through the branch `fix/ingest-retry`.") and a "Linked now" row.
3. Before you type, up to five open issues from the same repository are listed as "Same repository". You can also search by key or title.
4. Pick an issue and click Link to relink the session to that issue only. Pick "No Issue" and click Link to remove every confirmed link.

The Link to issue button in the span details header links this trace's session to an issue.

*Trace (sample data)*

Linking and unlinking by hand need the Member role or higher. Only issues in the session's own project are offered.

## Check that it's linked

1. Open the issue and confirm the session appears on the Sessions tab.
2. The session also appears on the Timeline at the time it ran.

Linked sessions appear alongside the sessions on branches and pull requests linked to the issue.

*Issue screen (Sessions tab) (sample data)*

How to read it: [Read an issue's history](/en/docs/usage/issue-timeline)

## FAQ

**If I unlink a session by hand, does a resync bring the link back?**

No. Once you unlink a pair by hand, branch names and syncs no longer link it automatically. Only linking it again by hand restores it.

**Do sessions marked as inferred appear on the history?**

No. Links inferred from the repository and overlapping time get confidence 0.6 or less and don't count as confirmed.

**Can I open the pull request before the issue exists?**

Yes. An identifier that doesn't resolve to an issue yet is kept, and if the issue is created on GitHub within 90 days of detection, the link is made then.

## Read next

- [Read an issue's history](/en/docs/usage/issue-timeline): Follow the AI's work to the merge on the Timeline and Sessions tabs.
- [Configure Claude Code](/en/docs/claude-code): What the plugin, its hooks and harnessforce run do.
- [Read the history](/en/product/execution): One issue holds the AI's work, all the way to the merge.
