Skip to content

fix(claude-code): allow fork after EnterWorktree - #629

Merged
BytePioneer-AI merged 1 commit into
mainfrom
codex/fix-claude-worktree-fork
Oct 28, 2026
Merged

BytePioneer-AI merged 1 commit into
mainfrom
codex/fix-claude-worktree-fork

Conversation

@BytePioneer-AI

Copy link
Copy Markdown
Owner

Summary

Claude Code 会话通过 EnterWorktree 进入工作树后,原生 Session 的 cwd 可以与 Desktop 记录的项目根目录不同。Adapter 将这一差异判为不支持跨目录 Fork,导致同工作区创建聊天分支及多轮编辑恢复失败。

移除 Adapter 的目录相等校验,交给原生 Agent SDK 按项目及工作树查找源 Session。保留 Session/Checkpoint 身份、精确历史前缀和源历史完整性校验;Host 的 forkAcrossCwd: false 能力限制仍约束显式目标目录变更。同步调整 Fork、回退回归场景及现有文档。

Related issues

无。

Test plan

  • 原生实测(macOS,Claude Agent SDK 0.3.273):源 Session 已进入工作树,传入 Desktop 项目根目录直接调用原生 forkSession(),成功生成目标检查点对应的 283 轮历史,内容与源历史前缀完全一致,源历史字节保持不变。
  • 使用修复后构建的完整 ClaudeCodeAdapter.open({ kind: "fork" }) 对同一检查点再次实测,Fork 成功并通过相同历史校验;两次诊断 Session 均已删除,未发起模型 Turn。
  • 回归场景先在旧实现下确认因目录限制失败,修复后通过。
  • npx vitest run --config tests/vitest.config.js packages/adapters/claude-code/test/claude-code-adapter.test.ts packages/adapters/claude-code/test/claude-rollback.test.ts:174 项通过。
  • npm run gate:claude:hermetic:33 项通过;8 项因未设置原生 CLI 测试配置而跳过。
  • npm run build:typescript、npm run typecheck:通过。
  • 修改文件的 ESLint、Prettier 和 git diff --check:通过。

未在 Windows/Linux 本地验证;未重启当前 Desktop 做 UI 复测。

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review 🔄 Running since 2026-10-27T07:16:53.815089Z f9bff8e PR opened
🔒 Security Review ✅ Completed 2026-10-27T07:20:35.645082Z f9bff8e PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 5eca2ea and f9bff8e.

Files selected for processing: 4
  • docs/harnesses/claude-code/claude-code-edit-recovery.md
  • packages/adapters/claude-code/src/claude-fork.ts
  • packages/adapters/claude-code/test/claude-code-adapter.test.ts
  • packages/adapters/claude-code/test/claude-rollback.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

Recent review details
Context from checks skipped due to timeout: 4
  • GitHub Check: Check windows-latest
  • GitHub Check: Check macos-14
  • GitHub Check: Check ubuntu-22.04
  • GitHub Check: Check Linux ARM64
Additional context used
Code guidelines: 1
AGENTS.md — auto-discovered
Path-based instructions: 1
Source excerpt: `codexhost` runs external Agent Harnesses as independent Threads inside Codex Desktop, preserving the official shell and native Codex path.

CodeRabbit inference engine (AGENTS.md)

Files:

  • packages/adapters/claude-code/test/claude-rollback.test.ts
  • packages/adapters/claude-code/src/claude-fork.ts
  • packages/adapters/claude-code/test/claude-code-adapter.test.ts
  • docs/harnesses/claude-code/claude-code-edit-recovery.md
Learnings: 1
Common learnings
Learnt from: CR
Repo: BytePioneer-AI/codex-host PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-10-23T15:37:32.051Z
Learning: Applies to ** : Source excerpt:
# Repository Guidelines

## Testing & Completion

- A change is complete only when implementation, contracts, tests, and affected documentation agree.
📝 Summary

Summary by CodeRabbit

  • 修复
    • 改进 Claude Code 在 worktree 中的多轮编辑恢复与 Fork 行为;即使会话位于 worktree,仍可按请求保留检查点之前的历史。
    • 保留跨工作目录 Fork 的现有限制。

Claude Code 适配器不再因源会话的工作目录与请求工作目录不同而拒绝 Fork。测试和文档更新,覆盖源会话位于 worktree、请求仍使用 Desktop workspace 的场景。

Changes: Claude Code worktree Fork

Layer / File(s) Summary
Worktree 中的 Fork 行为与验证
packages/adapters/claude-code/src/claude-fork.ts, packages/adapters/claude-code/test/claude-code-adapter.test.ts, packages/adapters/claude-code/test/claude-rollback.test.ts, docs/harnesses/claude-code/claude-code-edit-recovery.md
适配器移除源会话 cwd 与请求 cwd 不同时返回 unsupported 的检查,后续仍使用请求 cwd 读取快照并执行 Fork。测试覆盖源会话位于 worktree、请求 cwd 为 /synthetic 的场景。文档说明 Session 查找目录、历史前缀校验及 forkAcrossCwd: false 能力约束。

Priority: Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Possibly related PRs

Suggested labels: 范围:适配器, 适配器:Claude Code

Suggested reviewers: omsd512-w

Merge Risk: Minimal · up to f9bff

No actionable merge-blocking risk is established; normal checks can proceed, with platform-specific native validation as follow-up.

Pre-merge checks: Passed 4
Check name Status Explanation
Title check Passed 标题“fix(claude-code): allow fork after EnterWorktree”准确概括主要变更:移除 Adapter 的目录相等校验,使 EnterWorktree 之后的会话可以 Fork。标题具体、简洁,并与 raw_summary 及 PR 目标一致。
Description check Passed 描述与变更集直接相关。描述说明 EnterWorktree 后 cwd 与 Desktop 项目根目录不同的问题,说明移除目录相等校验,并列出保留的身份、前缀与完整性校验,以及测试计划。
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@BytePioneer-AI
BytePioneer-AI merged commit f147d2e into main Oct 28, 2026
4 of 5 checks passed
zxd-666 added a commit to zxd-666/codex-host that referenced this pull request Oct 29, 2026
codexhost v0.15.0

## What's New

Import native Sessions from a selected Host, answer multi-select questions, and use Grok's native questions. This release also adds Antigravity usage statistics and improves conversation reliability across Claude Code, Pi, Windows, and Codex Desktop.
支持从所选 Host 导入原生 Session、回答多选问题,并接入 Grok 原生提问。本版还新增 Antigravity 用量统计,改进 Claude Code、Pi、Windows 和 Codex Desktop 的会话可靠性。

### Features

- Select a local or remote Host for Session import, keeping import and opening on the selected machine; support macOS Broker-backed imports for Claude Code, Cursor CLI, CodeBuddy, and WorkBuddy (BytePioneer-AI#207)
- Answer external Harness multi-select questions in a shared card, with accompanying single-choice and text fields and drafts retained while switching chats (BytePioneer-AI#625)
- Answer Grok's native single-choice, multi-select, and text questions, with cancellation and native withdrawal support (BytePioneer-AI#625)
- Read Antigravity's native historical request and Token usage, including Sessions created outside codexhost; model and cost information remain unavailable when absent from native records (BytePioneer-AI#588)

### Fixes

- Steer Claude Code continuations within the same Turn without stopping background Subagents, and keep accepted instructions attached to that Turn (BytePioneer-AI#617)
- Release Claude Code Turns after refused Subagent messages, and allow Fork and message-edit recovery after entering a native worktree (BytePioneer-AI#626, BytePioneer-AI#629)
- Improve Pi's large-history RPC performance and ignore late replies to expired read-only queries without faulting the Session (BytePioneer-AI#607)
- Recover stale Windows Mapping Store locks when a PID has been reused by another process (BytePioneer-AI#627)
- Keep Antigravity questions working across Turns, preserve the project working directory, and bound process cleanup waits (BytePioneer-AI#586)
- Keep Antigravity Conversation totals separate from current context usage (BytePioneer-AI#587)
- Disable background self-update by default for Host-started Antigravity processes on Windows and macOS, while retaining explicit updates (BytePioneer-AI#585)
- Explain unavailable ZCode plans or quotas without asking an already signed-in account to log in again (BytePioneer-AI#621)
- Compact Composer controls in narrow layouts and keep native question and approval inputs separate from chat controls (BytePioneer-AI#624, BytePioneer-AI#625)
- Support Codex Desktop 26.1023 native language settings (BytePioneer-AI#636)
- Fix availability checks routed through the Harness Broker

### 新功能

- 会话导入支持选择本地或远程 Host,导入和打开始终使用所选机器;macOS 上通过 Broker 托管的 Claude Code、Cursor CLI、CodeBuddy 和 WorkBuddy 支持导入 (BytePioneer-AI#207)
- 外部 Harness 多选问题使用公共卡片,可与单选、文本字段一起回答,切换聊天时保留未提交草稿 (BytePioneer-AI#625)
- 接入 Grok 原生单选、多选和文本提问,支持取消及原生问题撤回 (BytePioneer-AI#625)
- 从 Antigravity 原生历史记录统计请求和 Token,包括未经 codexhost 创建的 Session;原生记录缺少模型信息时显示为未知模型且不计价 (BytePioneer-AI#588)

### 修复

- Claude Code 后台 Subagent 运行期间支持同一 Turn 内继续插入指令,不必停止后台任务;已接受的指令保持归属当前 Turn (BytePioneer-AI#617)
- Claude Code 子 Agent 消息被拒绝后正确释放 Turn;进入原生 worktree 后仍可 Fork 和进行消息编辑恢复 (BytePioneer-AI#626, BytePioneer-AI#629)
- 改善 Pi 大历史 RPC 处理性能;只读查询超时后的迟到回复不再导致 Session 故障 (BytePioneer-AI#607)
- Windows 上 PID 被其他进程复用时,可以回收残留的 Mapping Store 锁 (BytePioneer-AI#627)
- 修复 Antigravity 多轮提问失效,明确项目工作目录,并限制进程清理等待时间 (BytePioneer-AI#586)
- 避免把 Antigravity 整段 Conversation 的累计用量误当作当前上下文占用 (BytePioneer-AI#587)
- Windows 和 macOS 上由 Host 启动的 Antigravity 进程默认关闭后台自更新,保留显式更新操作 (BytePioneer-AI#585)
- ZCode 已登录但套餐或额度不可用时显示正确原因,不再要求重复登录 (BytePioneer-AI#621)
- 窄布局下压缩 Composer 控件,并避免聊天控件干扰原生提问与审批输入 (BytePioneer-AI#624, BytePioneer-AI#625)
- 适配 Codex Desktop 26.1023 的原生语言设置 (BytePioneer-AI#636)
- 修复通过 Harness Broker 路由的可用性检查

### Breaking Changes

- Language overrides require Codex Desktop's native settings service. Desktops exposing only the legacy locale RPC are no longer supported for language overrides; reading can fall back to the browser language, but changing the override requires the native service (BytePioneer-AI#636)

### 破坏性变更

- 语言覆盖设置需要 Codex Desktop 原生 settings 服务。仅提供旧 locale RPC 的 Desktop 不再支持语言覆盖;读取时可以降级使用浏览器语言,但修改覆盖值需要原生服务 (BytePioneer-AI#636)

## Installation

### npm

```bash
npm install -g @codexhost/cli
codexhost
```

For remote Session import and multi-select questions, update the Desktop installation and the relevant remote Hosts and Brokers together.

### Installer

Download the installer matching your OS and CPU architecture from this release's assets.

### macOS Gatekeeper

After installing on macOS, if codexhost shows "Apple cannot verify this app" when you open it for the first time, run the following command in Terminal and reopen codexhost:

```bash
xattr -dr com.apple.quarantine /Applications/codexhost.app
```

## Contributors

Thanks to everyone who contributed to this release:

- @BeiLuoqu (BytePioneer-AI#585, BytePioneer-AI#586, BytePioneer-AI#587, BytePioneer-AI#588)
- @bwndlct (BytePioneer-AI#617)
- @BytePioneer-AI (BytePioneer-AI#207, BytePioneer-AI#625, BytePioneer-AI#626, BytePioneer-AI#627, BytePioneer-AI#629, BytePioneer-AI#636)
- @cy2s (BytePioneer-AI#624)
- @karlorz (BytePioneer-AI#625)
- @kunkun9527 (BytePioneer-AI#607)
- @SuperGoodGame (BytePioneer-AI#207)
- @ump45nose (BytePioneer-AI#621)

# Conflicts:
#	Cargo.lock
#	Cargo.toml
#	package-lock.json
#	package.json
#	packages/renderer-extension/src/renderer-binding-probe.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant