[BUG] Leading whitespace stops a slash command being dispatched — the line is sent to the model instead, while trailing whitespace is tolerated
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
_Claude-prepared, human-hand-verified report on bug encountered in the wild: I typed " /rename …" and got the surprising response "● Session renamed. All wrapped up — merged, worktree and databases gone." rather than " ⎿ Session renamed to: …". The leading space caused the command to be received by the model, not the CLI, and the model can't rename its session, so "Session renamed" was simply untrue. Effectively a re-file of #52903, which was bot-expired for lack of human response._
---
A line whose only content is whitespace followed by a slash command — /help — is not dispatched. It is sent to the model as an ordinary chat message, which then answers in prose about the command instead of the command running.
Trailing whitespace on the same line is tolerated: /help dispatches normally. So the input is normalised at one end and not the other.
This was reported before, as #52903 (2026-04-24, v2.1.119), and triaged bug / regression / has repro. It was then closed NOT_PLANNED by the stale bot with no maintainer response, and has since been locked, so it cannot be reopened or commented on. I am refiling with a smaller repro rather than duplicating a live discussion.
The practical cost is that commands pasted from anywhere indented — a run book, a nested markdown bullet, a previous transcript — silently become chat messages. Copying from Claude Code's own terminal output drags the visual indentation along with it (#18170), so the product supplies its own worst input for this.
What Should Happen?
Leading whitespace is stripped before the input is tested for a leading /, so /help dispatches exactly as /help does.
To be clear about scope: this is not a request to dispatch commands mid-message. remember to run /usage later should keep going to the model, and the ambiguity there is real — that is #77868 and #70656, and I am not asking for it. A line containing nothing but whitespace and a command has no second reading.
Error Messages/Logs
$ mkdir /tmp/cc-repro && cd /tmp/cc-repro
### A — no leading whitespace: dispatched by the CLI
$ claude -p "/help"
/help isn't available in this environment.
### B — one leading space: falls through to the model
$ claude -p " /help"
**Claude Code** — an interactive CLI/agent for software engineering tasks. Here's the quick orientation:
[... model prose continues; wording varies run to run ...]
### C — one trailing space (control): dispatched by the CLI
$ claude -p "/help "
/help isn't available in this environment.
# Two leading spaces and a leading tab behave as B. In one run of the
# tab variant the model itself noted the problem: "`/help` is a built-in
# Claude Code command — normally the CLI renders it directly rather than
# passing it to me. Since it reached me, here's the short version."
Steps to Reproduce
mkdir /tmp/cc-repro && cd /tmp/cc-repro— an empty directory, so no project config is involved.- Run
claude -p "/help". The CLI intercepts it and prints/help isn't available in this environment. - Run
claude -p " /help"— the same line with one leading space. It is not intercepted; it reaches the model, which replies in prose. This is the bug. - Run
claude -p "/help "— one trailing space. Intercepted again, exactly as in step 2.
The same thing happens interactively in the TUI: a pasted /rename foo is delivered to the model as text, and the model has to explain that it cannot invoke commands. -p is used above only because it makes the difference between the two outcomes unambiguous in a transcript.
/help is just a convenient probe — any command behaves the same way. Headless dispatch is a supported path, not an accident of -p: v2.1.147 has "Fixed unknown slash commands silently doing nothing in headless/SDK mode — they now show an error message".
Claude Model
Not sure / Multiple models
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
2.1.220 (Claude Code)
Platform
Anthropic API
Operating System
Ubuntu/Debian Linux
Terminal/Shell
Xterm
Additional Information
Analysis — offered as a hypothesis, not a diagnosis. From the outside it looks like the dispatch predicate is anchored at index 0 of the raw input rather than of the trimmed input. The reason I think the trim is nearly there already is the v2.1.147 changelog entry "Fixed slash commands followed by a tab or newline being treated as an unknown command" — the trailing end of the same surface was fixed deliberately, and control C confirms it still holds today. I have not seen the source and may be wrong about the mechanism; the observable asymmetry in the repro is the part I stand over.
Prior and related issues:
- #52903 — the same bug, closed stale and now locked. The duplicate detector will likely surface it; that is expected and this is a deliberate refile, not an oversight.
- #18170 — copy/paste from the terminal includes the leading indentation. The most common way a user ends up with an indented command line in the first place.
- #77868, #70656 — mid-sentence commands are highlighted but not dispatched. Different question, deliberately out of scope here.
- #56002, #56846, #44447 — the autocomplete picker mid-input. UI discoverability, also not this.
Regression detail: #52903 reported this as a regression observed at v2.1.119 on 2026-04-24, and its author said indented pastes had worked routinely before that. I have not tested an older version myself, which is why the dropdown above says "I don't know" rather than "Yes" — flagging it here so the version-bisect lead is not lost.
---
Prepared with Claude Code's assistance: it ran the searches, found the changelog and prior issues, and drafted this text. I reproduced the bug myself on the stated version, checked the citations, edited the wording, and will handle any follow-up questions here personally.
This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗