Skip to content

Commit 14e73cd

Browse files
feat(claude): add repo, PR, and prompt statusline fields
1 parent 6cbf37c commit 14e73cd

3 files changed

Lines changed: 80 additions & 11 deletions

File tree

src/segments/claude.go

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package segments
22

33
import (
4+
"encoding/json"
45
"fmt"
56
"time"
67

@@ -29,9 +30,11 @@ type ClaudeData struct {
2930
CWD string `json:"cwd"`
3031
Version string `json:"version"`
3132
SessionID string `json:"session_id"`
33+
PromptID string `json:"prompt_id"`
3234
Effort ClaudeEffort `json:"effort"`
3335
SessionName string `json:"session_name"`
3436
Agent ClaudeAgent `json:"agent"`
37+
PR ClaudePR `json:"pr"`
3538
Workspace ClaudeWorkspace `json:"workspace"`
3639
ContextWindow ClaudeContextWindow `json:"context_window"`
3740
Cost ClaudeCost `json:"cost"`
@@ -48,10 +51,18 @@ type AIModel struct {
4851

4952
// ClaudeWorkspace represents workspace directory information
5053
type ClaudeWorkspace struct {
51-
CurrentDir string `json:"current_dir"`
52-
ProjectDir string `json:"project_dir"`
53-
GitWorktree string `json:"git_worktree"`
54-
AddedDirs []string `json:"added_dirs"`
54+
CurrentDir string `json:"current_dir"`
55+
ProjectDir string `json:"project_dir"`
56+
GitWorktree string `json:"git_worktree"`
57+
AddedDirs []string `json:"added_dirs"`
58+
Repo ClaudeRepo `json:"repo"`
59+
}
60+
61+
// ClaudeRepo represents the repository identity parsed from the origin remote.
62+
type ClaudeRepo struct {
63+
Host string `json:"host"`
64+
Owner string `json:"owner"`
65+
Name string `json:"name"`
5566
}
5667

5768
// ClaudeOutputStyle represents the current output style.
@@ -80,6 +91,13 @@ type ClaudeAgent struct {
8091
Name string `json:"name"`
8192
}
8293

94+
// ClaudePR represents the open pull request for the current branch.
95+
type ClaudePR struct {
96+
Number json.Number `json:"number"`
97+
URL string `json:"url"`
98+
ReviewState string `json:"review_state"`
99+
}
100+
83101
// ClaudeWorktree represents Claude Code --worktree session information.
84102
type ClaudeWorktree struct {
85103
Name string `json:"name"`

src/segments/claude_test.go

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -274,13 +274,19 @@ func TestClaudeAdditionalStatusLineFieldsJSONShape(t *testing.T) {
274274
JSON: `{
275275
"cwd": "/repo/project",
276276
"session_name": "release-check",
277+
"prompt_id": "prompt-456",
277278
"transcript_path": "/repo/project/.claude/transcript.jsonl",
278279
"version": "2.1.123",
279280
"output_style": {
280281
"name": "default"
281282
},
282283
"workspace": {
283-
"added_dirs": ["/repo/shared", "/repo/docs"]
284+
"added_dirs": ["/repo/shared", "/repo/docs"],
285+
"repo": {
286+
"host": "github.com",
287+
"owner": "anthropics",
288+
"name": "claude-code"
289+
}
284290
},
285291
"exceeds_200k_tokens": true,
286292
"vim": {
@@ -289,6 +295,11 @@ func TestClaudeAdditionalStatusLineFieldsJSONShape(t *testing.T) {
289295
"agent": {
290296
"name": "security-reviewer"
291297
},
298+
"pr": {
299+
"number": 1234,
300+
"url": "https://github.com/anthropics/claude-code/pull/1234",
301+
"review_state": "pending"
302+
},
292303
"worktree": {
293304
"name": "my-feature",
294305
"path": "/repo/project/.claude/worktrees/my-feature",
@@ -299,15 +310,28 @@ func TestClaudeAdditionalStatusLineFieldsJSONShape(t *testing.T) {
299310
"fast_mode": true
300311
}`,
301312
Expected: ClaudeData{
302-
CWD: "/repo/project",
303-
SessionName: "release-check",
304-
TranscriptPath: "/repo/project/.claude/transcript.jsonl",
305-
Version: "2.1.123",
306-
OutputStyle: ClaudeOutputStyle{Name: defaultStr},
307-
Workspace: ClaudeWorkspace{AddedDirs: []string{"/repo/shared", "/repo/docs"}},
313+
CWD: "/repo/project",
314+
SessionName: "release-check",
315+
PromptID: "prompt-456",
316+
TranscriptPath: "/repo/project/.claude/transcript.jsonl",
317+
Version: "2.1.123",
318+
OutputStyle: ClaudeOutputStyle{Name: defaultStr},
319+
Workspace: ClaudeWorkspace{
320+
AddedDirs: []string{"/repo/shared", "/repo/docs"},
321+
Repo: ClaudeRepo{
322+
Host: "github.com",
323+
Owner: "anthropics",
324+
Name: "claude-code",
325+
},
326+
},
308327
Exceeds200KTokens: true,
309328
Vim: ClaudeVim{Mode: "NORMAL"},
310329
Agent: ClaudeAgent{Name: "security-reviewer"},
330+
PR: ClaudePR{
331+
Number: json.Number("1234"),
332+
URL: "https://github.com/anthropics/claude-code/pull/1234",
333+
ReviewState: "pending",
334+
},
311335
Worktree: ClaudeWorktree{
312336
Name: "my-feature",
313337
Path: "/repo/project/.claude/worktrees/my-feature",
@@ -331,6 +355,7 @@ func TestClaudeAdditionalStatusLineFieldsJSONShape(t *testing.T) {
331355
"workspace": {},
332356
"vim": {},
333357
"agent": {},
358+
"pr": {},
334359
"worktree": {}
335360
}`,
336361
Expected: ClaudeData{},
@@ -377,6 +402,7 @@ func TestClaudeAdditionalStatusLineFieldsJSONShape(t *testing.T) {
377402
assert.NoError(t, err, tc.Case)
378403
assert.Equal(t, tc.Expected.CWD, data.CWD, tc.Case)
379404
assert.Equal(t, tc.Expected.SessionName, data.SessionName, tc.Case)
405+
assert.Equal(t, tc.Expected.PromptID, data.PromptID, tc.Case)
380406
assert.Equal(t, tc.Expected.TranscriptPath, data.TranscriptPath, tc.Case)
381407
assert.Equal(t, tc.Expected.Version, data.Version, tc.Case)
382408
assert.Equal(t, tc.Expected.OutputStyle.Name, data.OutputStyle.Name, tc.Case)
@@ -388,6 +414,12 @@ func TestClaudeAdditionalStatusLineFieldsJSONShape(t *testing.T) {
388414
assert.Equal(t, tc.Expected.Exceeds200KTokens, data.Exceeds200KTokens, tc.Case)
389415
assert.Equal(t, tc.Expected.Vim.Mode, data.Vim.Mode, tc.Case)
390416
assert.Equal(t, tc.Expected.Agent.Name, data.Agent.Name, tc.Case)
417+
assert.Equal(t, tc.Expected.Workspace.Repo.Host, data.Workspace.Repo.Host, tc.Case)
418+
assert.Equal(t, tc.Expected.Workspace.Repo.Owner, data.Workspace.Repo.Owner, tc.Case)
419+
assert.Equal(t, tc.Expected.Workspace.Repo.Name, data.Workspace.Repo.Name, tc.Case)
420+
assert.Equal(t, tc.Expected.PR.Number, data.PR.Number, tc.Case)
421+
assert.Equal(t, tc.Expected.PR.URL, data.PR.URL, tc.Case)
422+
assert.Equal(t, tc.Expected.PR.ReviewState, data.PR.ReviewState, tc.Case)
391423
assert.Equal(t, tc.Expected.Worktree.Name, data.Worktree.Name, tc.Case)
392424
assert.Equal(t, tc.Expected.Worktree.Path, data.Worktree.Path, tc.Case)
393425
assert.Equal(t, tc.Expected.Worktree.Branch, data.Worktree.Branch, tc.Case)

website/docs/segments/cli/claude.mdx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import Config from "@site/src/components/Config.js";
5353
| `.CWD` | `string` | Current working directory; same value as `.Workspace.CurrentDir` |
5454
| `.SessionID` | `string` | Unique identifier for the Claude session |
5555
| `.SessionName` | `string` | Custom session name; empty when absent |
56+
| `.PromptID` | `string` | User prompt identifier for event correlation; empty when absent |
5657
| `.TranscriptPath` | `string` | Path to the conversation transcript file |
5758
| `.Model` | `Model` | AI model information |
5859
| `.Workspace` | `Workspace` | Workspace directory information |
@@ -65,6 +66,7 @@ import Config from "@site/src/components/Config.js";
6566
| `.Exceeds200KTokens` | `bool` | Whether the most recent API response exceeded 200K total tokens |
6667
| `.Vim` | `Vim` | Vim mode information; empty when absent |
6768
| `.Agent` | `Agent` | Agent information; empty when absent |
69+
| `.PR` | `PR` | Pull request information for the current branch; empty when absent |
6870
| `.Worktree` | `Worktree` | Claude Code worktree information; empty when absent |
6971
| `.FastMode` | `bool` | Whether fast mode is enabled; `false` when absent or unsupported |
7072
| `.TokenUsagePercent` | `Percentage` | Percentage of context window used (0-100) |
@@ -98,6 +100,15 @@ import Config from "@site/src/components/Config.js";
98100
| `.ProjectDir` | `string` | Directory where Claude Code was launched; may differ from `.CurrentDir` |
99101
| `.AddedDirs` | `[]string` | Additional directories added via `/add-dir` or `--add-dir` |
100102
| `.GitWorktree` | `string` | Path to the linked git worktree, empty when not inside a linked git worktree |
103+
| `.Repo` | `Repo` | Repository identity parsed from the `origin` remote; empty when absent |
104+
105+
#### Repo Properties
106+
107+
| Name | Type | Description |
108+
| -------- | -------- | ------------------------------------------------------------ |
109+
| `.Host` | `string` | Repository host, for example `github.com`; empty when absent |
110+
| `.Owner` | `string` | Repository owner or organization; empty when absent |
111+
| `.Name` | `string` | Repository name; empty when absent |
101112

102113
#### OutputStyle Properties
103114

@@ -129,6 +140,14 @@ import Config from "@site/src/components/Config.js";
129140
| ------- | -------- | ----------------------------------------- |
130141
| `.Name` | `string` | Agent name; empty when no agent is active |
131142

143+
#### PR Properties
144+
145+
| Name | Type | Description |
146+
| -------------- | ------------- | --------------------------------------------------------------------------------------------- |
147+
| `.Number` | `json.Number` | Open pull request number for the current branch; empty when absent |
148+
| `.URL` | `string` | Open pull request URL for the current branch; empty when absent |
149+
| `.ReviewState` | `string` | Review status (`approved`, `pending`, `changes_requested`, or `draft`); empty when unavailable |
150+
132151
#### Worktree Properties
133152

134153
| Name | Type | Description |

0 commit comments

Comments
 (0)