Skip to content

fix(openspec): openspec new names a branch it does not use #4593

Description

@dan-petty

Problem Description

devops openspec new <issue> prints "Created openspec/changes/ on branch ." The branch in this sentence is the branch name that the command computes from the issue title with branch_name. The command does not create, switch to or read that branch. When the checkout is on another branch, the output states a false fact.

Source: scaffold in src/devops_cli/openspec/scaffold.py computes branch = branch_name(issue, type_, slug) and returns it. new_next_steps in src/devops_cli/lang/en/messages.py formats it as "Created {folder} on branch {branch}." and again as "Branch: {branch}".

Reproduction Steps

  1. git worktree add <path> -b fix/4498-same-name-test-path origin/main
  2. In that worktree: uv run devops openspec new 4498
  3. git branch --show-current

Expected vs Actual Behavior

Expected: the output names the current branch, or states that the computed name is a suggestion and that the current branch has another name.

Actual: the output says "Created openspec/changes/4498-name-the-same-name-file-of on branch fix/4498-name-the-same-name-file-of." git branch --show-current gives fix/4498-same-name-test-path, and no branch fix/4498-name-the-same-name-file-of exists.

Environment Diagnostics

  • DevOps CLI: main at 5f75d25
  • Execution environment: devcontainer, git worktree

Logs, Traces, or Terminal Output

✓ Created openspec/changes/4498-name-the-same-name-file-of on branch fix/4498-name-the-same-name-file-of.

Branch:  fix/4498-name-the-same-name-file-of

Pre-Submission Checklist

  • I have verified that no sensitive credentials, private keys, or internal tokens are contained in this issue report.
  • I have checked existing issues and pull requests to ensure this is not a duplicate.

Alternatives check of 2026-11-13: none.
Tool: none found.

Proposed design

Problem statement

devops openspec new <issue> prints that it created the change folder on a branch, and the branch name in that sentence is computed from the issue title. The command never creates, switches to or reads that branch, so a checkout on another branch reads a false fact, and the change folder can hold a slug that differs from the slug of the worktree branch. The command must name the branch of the checkout and take the change folder slug from that branch when the branch names the same issue.

Acceptance criteria

Requirement: The output names the branch of the checkout

devops openspec new SHALL name the branch that the checkout is on in its output.

Scenario: Checkout on the default branch

  • WHEN The checkout is on main and the user runs devops openspec new 4593 --title "fix(openspec): alpha".
  • THEN The output holds Created openspec/changes/4593-alpha on branch main. and Branch: main.

Requirement: The change folder takes its slug from the branch of the issue

The command SHALL take the slug of the change folder from the branch of the checkout when that branch is <type>/<issue>-<slug> for the same issue.

Scenario: The branch slug differs from the title slug

  • WHEN The worktree is on fix/4593-alpha and the user runs devops openspec new 4593 --title "fix(openspec): beta".
  • THEN The command creates openspec/changes/4593-alpha/ and creates no folder openspec/changes/4593-beta/.

Requirement: The output marks the computed name as a suggestion

The command SHALL state that the computed branch name is a suggestion and that the checkout is not on it, when the branch of the checkout does not name the same issue.

Scenario: Checkout on a branch of another issue

  • WHEN The checkout is on docs/5225-adr-front-matter-and-rules and the user runs devops openspec new 4593 --title "fix(openspec): alpha".
  • THEN The output holds Branch: docs/5225-adr-front-matter-and-rules and The branch fix/4593-alpha is a suggestion for this change. This checkout is not on it.

Requirement: A checkout with no branch names no branch

The command SHALL state that the checkout is on no branch when HEAD is detached.

Scenario: Detached HEAD

  • WHEN The checkout has a detached HEAD and the user runs devops openspec new 4593 --title "fix(openspec): alpha".
  • THEN The output holds Branch: HEAD detached and no on branch, and the command creates openspec/changes/4593-alpha/.

Requirement: The dry run names the folder and the branch of a real run

The dry run SHALL name the folder and the branch that a real run creates in the same checkout.

Scenario: Dry run in a worktree on the branch of the issue

  • WHEN The worktree is on fix/4593-alpha and the user runs devops openspec new 4593 --dry-run --title "fix(openspec): beta".
  • THEN The output holds Would create openspec/changes/4593-alpha on branch fix/4593-alpha. and Branch: fix/4593-alpha, and the command creates no folder.

Existing Tool Considered

No open tool covers the need: the alternatives check of 2026-11-13 found none. GitPython (https://pypi.org/project/GitPython) can report the active branch, but it formats no message and reconciles no slug, and the project removed it for one git seam (docs/TESTING.md:80). The project builds the change itself, on helpers that already exist: current_branch reads the branch and parse_branch parses it. Written cost: about 5k tokens to build, keep and fix the code, and about 2 hours of elapsed time.

Key questions

  • Which git command reports the branch of the checkout?: git branch --show-current reports it, and it prints nothing when HEAD is detached. The project already wraps it as current_branch(repo_dir), which returns an empty string on a detached HEAD, and commands/repos.py renders that as HEAD detached. [sources: src/devops_cli/git/operations.py:278, src/devops_cli/git/operations.py:280, src/devops_cli/commands/repos.py:92]
  • Which branch name does devops openspec new report?: The branch of the checkout, read with current_branch. The folder is written into the working tree of that branch, so the sentence is true in every checkout. (best practice) [sources: src/devops_cli/openspec/scaffold.py:172, src/devops_cli/commands/openspec.py:126, src/devops_cli/git/operations.py:278]
    • Chosen: The branch of the checkout. The command writes the folder into the working tree of that branch, so the name is true.
    • Rejected: The computed <type>/<issue>-<slug> name. The command creates no branch and switches to none, so the output states a false fact, which is the defect.
    • Rejected: No branch name at all. The user then loses the name of the branch that the change belongs to, and the next steps name no branch.
  • Where does the slug of the change folder come from?: From the branch of the checkout when parse_branch reads that branch as <type>/<issue>-<slug> for the same issue; otherwise from the issue title, as today. CONTRIBUTING.md makes the branch slug the slug of the change folder, and the implement job makes the branch with the slug of the folder. (best practice) [sources: CONTRIBUTING.md:216, CONTEXT.md:122, src/devops_cli/git/branch_form.py:59]
    • Chosen: The slug of the branch of the checkout. The folder and the branch then hold the same slug, and the implement job derives the branch <type>/<issue>-<slug> from the folder.
    • Rejected: The slug of the issue title always. The folder and the worktree branch hold different slugs, and the implement job derives a branch name that no worktree has.
  • What does the command print when the checkout is on another branch or on no branch?: It names the branch of the checkout, or HEAD detached when HEAD is detached, which is the wording commands/repos.py already uses. It then states that the computed <type>/<issue>-<slug> is a suggestion and that the checkout is not on it. (best practice) [sources: src/devops_cli/commands/openspec.py:126, src/devops_cli/commands/repos.py:92, src/devops_cli/git/branch_form.py:59]
    • Chosen: State the computed name as a suggestion. The user learns the branch name that the roadmap jobs use, and no sentence claims that the command made that branch.
    • Rejected: Print the computed name with no note. It repeats the false fact of the defect.
    • Rejected: Create the branch and switch to it. The command writes files only, and the roadmap jobs own the branch of an item; a switch would move the working tree of the user.
  • How does ScaffoldResult carry the two names?: It keeps branch as the computed <type>/<issue>-<slug> and adds current_branch, which is None on a detached HEAD (from current_branch(root) or None). The command reads both. (best practice) [sources: src/devops_cli/openspec/scaffold.py:25, tests/openspec/test_openspec_new.py:368]
    • Chosen: Add current_branch and keep branch. The callers and the tests that read branch keep their meaning.
    • Rejected: Change branch to the branch of the checkout. It silently changes the meaning of the field for every caller and for the tests that read it.
  • Which code reads the branch of the checkout and which code parses it?: The helpers that already exist: current_branch in git/operations.py reads the branch through the one git seam, and parse_branch in git/branch_form.py returns its type, issue and slug. scaffold.py calls both and starts no git command of its own. (best practice) [sources: src/devops_cli/git/operations.py:278, src/devops_cli/git/branch_form.py:59, docs/TESTING.md:80]
    • Chosen: Reuse current_branch and parse_branch. Both exist, and the read goes through the one git seam that the invariant test enforces.
    • Rejected: A new subprocess call in scaffold.py. It repeats the branch types and the slug rule in a second place and starts git outside the seam.
  • Where does the command build its output text?: Inline in new_cmd, at commands/openspec.py:120 for the dry run and :126 for the real run. MESSAGES.openspec.new_dry_run_output and new_next_steps hold the same text, and nothing reads them. [sources: src/devops_cli/commands/openspec.py:120, src/devops_cli/commands/openspec.py:126, src/devops_cli/lang/en/messages.py:553, src/devops_cli/lang/en/messages.py:554]
  • Where does the new wording live?: In MESSAGES.openspec.new_dry_run_output and new_next_steps, formatted from new_cmd. The other openspec commands already print their text from that catalog, and the catalog already holds both messages. (best practice) [sources: src/devops_cli/commands/openspec.py:75, src/devops_cli/lang/en/messages.py:553, src/devops_cli/lang/en/messages.py:554]
    • Chosen: The message catalog. The other openspec commands print from MESSAGES.openspec, and the two messages are already defined there, so the text has one home.
    • Rejected: The inline strings of new_cmd only. It leaves two copies of the same text, and the catalog entry that the issue names keeps the old wording.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    source/agent
    type/bug
    scope/openspec
    status/new
    value/medium
    effort/low
    on Nov 11, 2026
  2. dan-petty commented on Nov 11, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.

    • Type: type/bug. The fix prefix of the title gives the type.
    • Scope: scope/openspec. The (openspec) scope of the title gives the scope.
    • Priority: P2-Medium. The output misleads users about the active branch but does not break the command or data.
    • Value: Medium. Users see a false branch name and may act on it, but the tool still functions correctly.
    • Effort: Low. The fix changes a message string or swaps the reported branch for the current one in one file.
    • Related: feat(openspec): scaffold the change folder of an issue to project form #3203, which asks for a different change. Both concern the openspec new scaffold command, but 3203 adds project-form content to the scaffold while this candidate fixes a misleading branch name in the output message.
  3. added
    priority/p2-medium
    on Nov 11, 2026
  4. dan-petty commented on Nov 12, 2026

    @dan-petty
    OwnerAuthor

    Seen again on 2026-11-12. In a worktree on the branch fix/4836-intake-comment-new-facts, devops openspec new 4836 printed Created openspec/changes/4836-the-intake-reason-comment-states-only on branch fix/4836-the-intake-reason-comment-states-only. The command made no branch with that name, and the worktree stayed on its branch.

  5. dan-petty commented on Nov 12, 2026

    @dan-petty
    OwnerAuthor

    Seen again on 2026-11-12 (devops-cli 0.115.0): uv run devops openspec new 4845, run in a worktree on the branch feat/4845-roadmap-job-result-line, printed Created openspec/changes/4845-log-one-result-line-for-each on branch feat/4845-log-one-result-line-for-each. The checkout stayed on the first branch, and no branch with the printed name existed. I renamed the branch by hand to match the printed name.

  6. dan-petty commented on Nov 12, 2026

    @dan-petty
    OwnerAuthor

    Seen again on 2026-11-12 with #5185. devops repos worktrees add 5185 --type feat --slug grafana-image-renderer made the worktree on branch feat/5185-grafana-image-renderer. In that worktree, uv run devops openspec new 5185 printed:

    ✓ Created openspec/changes/5185-enable-the-image-renderer-for-panel on branch feat/5185-enable-the-image-renderer-for-panel.
    Branch:  feat/5185-enable-the-image-renderer-for-panel
    

    git status --short --branch showed feat/5185-grafana-image-renderer, and no branch feat/5185-enable-the-image-renderer-for-panel exists. The folder slug also differs from the slug of the worktree branch.

  7. dan-petty commented on Nov 12, 2026

    @dan-petty
    OwnerAuthor

    Occurrence on 2026-11-12, during #5163: in a worktree on the branch docs/5163-cli-reference-index, uv run devops openspec new 5163 --title "docs(cli): turn CLI_REFERENCE into an index of the command group pages" printed "Created openspec/changes/5163-turn-cli-reference-into-an-index on branch docs/5163-turn-cli-reference-into-an-index." The checkout stayed on docs/5163-cli-reference-index, and no branch of that name existed. I renamed my branch by hand to match the name.

  8. dan-petty commented on Nov 12, 2026

    @dan-petty
    OwnerAuthor

    The defect occurred again on 2026-11-12 (main at 0a14161, worktree .data/agent/worktrees/w-5225).

    1. uv run devops repos worktrees add 5225 --type docs --slug adr-front-matter-and-rules made the branch docs/5225-adr-front-matter-and-rules.
    2. In that worktree, uv run devops openspec new 5225 printed "Created openspec/changes/5225-add-madr-front-matter-a-status on branch docs/5225-add-madr-front-matter-a-status."
    3. git branch --show-current gave docs/5225-adr-front-matter-and-rules. No branch docs/5225-add-madr-front-matter-a-status exists.

    One more effect: the folder slug also comes from the issue title, so it differs from the slug of the current branch. CONTRIBUTING.md section 5 says that the <slug> of a branch is the slug of the change folder. I renamed the folder by hand to 5225-adr-front-matter-and-rules. A fix can take the slug from the current branch when the branch is <type>/<issue>-<slug> for the same issue, and name that branch in the output.

  9. devops-cli-service commented on Nov 13, 2026

    @devops-cli-service
    Contributor

    Alternatives check: none

    Reason: The searches found only general Git/Python references and GitPython, which can report the active branch but does not format or correct the CLI's message and does not reconcile the change slug. The issue needs a small in-repo change to scaffold.py and messages.py, not an external tool.

    Tool: none found

    Lacks:

    • No tool fixes the openspec new output so that it names the branch that is actually checked out.
    • No tool reconciles the change-folder slug with the slug of an existing <type>/<issue>-<slug> worktree branch.
    • GitPython only exposes the active branch name; the message wording and branch/slug handling remain in the project's own code.

    Tools considered:

    Searches run:

    • python library get current git branch name, results: 5
    • CLI print current git branch instead of computed branch name, results: 5
    • git branch --show-current python subprocess current branch name, results: 5
    • GitPython active_branch get current branch, results: 5
    • GitPython documentation Repo active_branch, results: 5

    Sources:

    Checked on 2026-11-13. A person decides what this means for the item. The check changes no label and closes no issue.

  10. dan-petty commented on Nov 13, 2026

    @dan-petty
    OwnerAuthor

    Seen again on 2026-11-13 at release 0.125.0. devops repos worktrees add 5293 --type docs --slug k8s-product-docs made the branch docs/5293-k8s-product-docs. In that worktree, devops openspec new 5293 printed Created openspec/changes/5293-move-the-product-readme-sections-to on branch docs/5293-move-the-product-readme-sections-to. No branch of that name exists, and the worktree stayed on docs/5293-k8s-product-docs.

  11. dan-petty commented on Nov 13, 2026

    @dan-petty
    OwnerAuthor

    The problem occurred again on 2026-11-13 for #5419. The worktree was on docs/5419-bottom-line-first-line. uv run devops openspec new 5419 printed Created openspec/changes/5419-replies-give-the-bottom-line-in on branch docs/5419-replies-give-the-bottom-line-in. The command did not create that branch and did not switch to it. The folder was on the current branch. An agent that reads the output can think that the branch changed.

  12. dan-petty commented on Nov 13, 2026

    @dan-petty
    OwnerAuthor

    The defect occurred again on 2026-11-13 for #5421. In the worktree on branch docs/5421-route-task-rules-out-of-agents-md, uv run devops openspec new 5421 printed "on branch docs/5421-route-task-rules-out-of-agents". That name comes from the change slug, which is shorter than the branch slug. The command did not create or use that branch.

  13. added
    status/ready
    and removed
    status/new
    on Nov 14, 2026
  14. devops-cli-service commented on Nov 14, 2026

    @devops-cli-service
    Contributor

    Status set to Ready at b15faab (see proposed design in issue body).

  15. added
    status/in-review
    and removed
    status/ready
    on Nov 14, 2026
  16. removed
    status/in-review
    on Nov 14, 2026
  17. added a commit that references this issue on Nov 14, 2026
  18. devops-cli-service commented on Nov 14, 2026

    @devops-cli-service
    Contributor
  19. devops-cli-service commented on Nov 14, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-14 15:02 UTC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/lowpriority/p2-mediumscope/openspecsource/agenttype/bugvalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions