diff --git a/packages/plugins/agent-claude-code/src/index.ts b/packages/plugins/agent-claude-code/src/index.ts index ff1903370..6e09a6026 100644 --- a/packages/plugins/agent-claude-code/src/index.ts +++ b/packages/plugins/agent-claude-code/src/index.ts @@ -128,8 +128,9 @@ update_metadata_key() { # Strip leading directory-change prefixes so that commands like # cd ~/.worktrees/project && gh pr create ... # are correctly detected. Agents frequently cd into a worktree first. -# Store the regex pattern in a variable for clarity (avoids shell quoting confusion) -cd_prefix_pattern='^[[:space:]]*cd[[:space:]]+[^&;]*[[:space:]]*(&&|;)[[:space:]]*(.*)' +# Store the regex pattern in a variable for clarity (avoids shell quoting confusion). +# Uses space-padded (&&|;) to avoid breaking on paths containing & or ; chars. +cd_prefix_pattern='^[[:space:]]*cd[[:space:]]+.*[[:space:]]+(&&|;)[[:space:]]+(.*)' clean_command="$command" while [[ "$clean_command" =~ ^[[:space:]]*cd[[:space:]] ]]; do if [[ "$clean_command" =~ $cd_prefix_pattern ]]; then