Skip to content

fix(command): handle spaces in ClaudeCodeAdd file paths - #315

Draft
7A1T wants to merge 1 commit into
coder:mainfrom
7A1T:fix/claudecode-add-path-spaces-314
Draft

fix(command): handle spaces in ClaudeCodeAdd file paths#315
7A1T wants to merge 1 commit into
coder:mainfrom
7A1T:fix/claudecode-add-path-spaces-314

Conversation

@7A1T

@7A1T 7A1T commented Aug 21, 2026

Copy link
Copy Markdown

Summary

  • :ClaudeCodeAdd % (the README-documented keybinding) broke for buffers whose path contains a space, because Vim expands %/#/etc. in the Ex command line before the user-command callback runs, so the naive vim.split(opts.args, "%s+") split the already-expanded path on its embedded spaces — producing "Too many arguments" or "Invalid start line number" errors.
  • Replaced the parser with parse_add_command_args, which treats trailing numeric tokens (up to two) as line numbers and rejoins the rest as the path, so unquoted spaced paths resolve correctly. A quoted path ("my file.lua" 10 20) is also supported for when a line range follows.
  • Updated the README to document quoting behavior for :ClaudeCodeAdd.

Fixes #314

Test plan

  • Added unit tests in tests/unit/claudecode_add_command_spec.lua covering unquoted spaced paths (with/without a line range), quoted paths, and unterminated-quote errors — 35/35 passing via busted.
  • Added a vim.trim mock to tests/mocks/vim.lua (was missing, needed by the new parser).
  • mise run all not run locally (mise/luajit unavailable in this environment) — pre-existing unrelated test failures (e.g. terminal_spec.lua, unpack global) were confirmed present on a clean main checkout too, so they're an environment gap, not introduced by this change. Please run the full mise run all in CI/a provisioned shell before merging.

Marked as draft pending that full validation.

Vim expands `%`/`#`/etc. in the Ex command line before the user-command
callback runs, so `:ClaudeCodeAdd %` on a buffer whose path contains a
space arrived as an already-expanded path string. The naive whitespace
split then broke it into bogus path/line-number tokens, producing
"Too many arguments" or "Invalid start line number" errors.

Replace the split with a parser that treats trailing numeric tokens as
line numbers and rejoins the rest as the path, and additionally
supports a quoted path when a line range follows.

Fixes coder#314
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.

[BUG] ClaudeCodeAdd fails on paths with spaces

1 participant