Summary
Terminal clear commands (/clear, /new, /reset, clear, cls) no longer clear the terminal screen. This is a regression caused by the InputTracker service being disconnected during architecture migration.
Current Behavior
When typing clear commands like /clear or clear in terminals (including Claude Code agent terminals):
- The command is entered and executed
- Terminal screen does not clear visually
- The
InputTracker class exists in src/services/clearCommandDetection.ts but is unused
- Current
TerminalPane uses naive commandBufferRef that only tracks last command for display
Expected Behavior
Clear commands should:
- Be detected before execution
- Trigger visual terminal clearing using VT100 escape sequences
- Clear both viewport and scrollback buffer
- Work consistently across all terminal types (interactive, Claude, Gemini, Codex)
Root Cause
The InputTracker class in src/services/clearCommandDetection.ts contains proper logic for:
- Detecting clear commands from the CLEAR_COMMANDS set
- Handling backspace, escape sequences, and bracketed paste
- Processing character-by-character input
However, TerminalPane.tsx (lines 162-193) implements a simplified buffer that:
- Only accumulates characters for last command display
- Does not check against CLEAR_COMMANDS
- Does not trigger terminal clearing action
Evidence
Affected Files:
Current Implementation (TerminalPane.tsx:164-193):
const handleInput = useCallback(
(data: string) => {
let buffer = commandBufferRef.current;
for (let i = 0; i < data.length; i++) {
const ch = data[i];
if (ch === "\r" || ch === "\n") {
const trimmed = buffer.trim();
if (trimmed) {
updateLastCommand(id, trimmed);
}
buffer = "";
continue;
}
if (ch === "\x7f" || ch === "\b") {
buffer = buffer.slice(0, -1);
continue;
}
if (ch >= " " && ch !== "\x7f") {
buffer += ch;
}
}
commandBufferRef.current = buffer;
},
[id, updateLastCommand]
);
Deliverables
Code Changes
1. Enhance InputTracker API (src/services/clearCommandDetection.ts)
- Modify
process() to return an InputResult object instead of boolean
- Add interface with
isClear and command properties
- Support both clear detection and command tracking in one service
- Add
reset() method for terminal restart cleanup
2. Wire InputTracker into TerminalPane (src/components/Terminal/TerminalPane.tsx)
- Replace
commandBufferRef with InputTracker instance (line 162)
- Update
handleInput to use tracker and handle clear commands
- When clear detected, call
terminalInstanceService.get(id).terminal.clear()
- Update last command from tracker result
- Call tracker reset on terminal restart (in
handleRestart)
Tests
- Verify
/clear, clear, cls trigger screen clear
- Test backspace handling doesn't break clear detection
- Verify paste and escape sequences work correctly
- Test last command display still functions
Documentation
- No documentation changes needed (internal fix)
Technical Specifications
Footprint: Terminal input handling layer
src/services/clearCommandDetection.ts - Enhance return type
src/components/Terminal/TerminalPane.tsx - Wire up tracker
Dependencies: Existing xterm.js terminal.clear() API
Dependencies
None - standalone fix
Tasks
Acceptance Criteria
Edge Cases & Risks
- Bracketed paste: InputTracker already handles ESC[200~/ESC[201~ sequences
- Arrow keys/navigation: Tracker resets buffer on escape sequences to avoid false positives
- Control characters: Ctrl+C, Ctrl+D properly reset buffer
- Terminal restart: Ensure tracker state is cleaned up
- Scrollback clearing: Verify VT100_FULL_CLEAR sequences are still available if needed beyond basic .clear()
Summary
Terminal clear commands (
/clear,/new,/reset,clear,cls) no longer clear the terminal screen. This is a regression caused by theInputTrackerservice being disconnected during architecture migration.Current Behavior
When typing clear commands like
/clearorclearin terminals (including Claude Code agent terminals):InputTrackerclass exists insrc/services/clearCommandDetection.tsbut is unusedTerminalPaneuses naivecommandBufferRefthat only tracks last command for displayExpected Behavior
Clear commands should:
Root Cause
The
InputTrackerclass insrc/services/clearCommandDetection.tscontains proper logic for:However,
TerminalPane.tsx(lines 162-193) implements a simplified buffer that:Evidence
Affected Files:
src/services/clearCommandDetection.ts- Unused InputTracker servicesrc/components/Terminal/TerminalPane.tsx- Current naive input handlerCurrent Implementation (TerminalPane.tsx:164-193):
Deliverables
Code Changes
1. Enhance InputTracker API (
src/services/clearCommandDetection.ts)process()to return anInputResultobject instead of booleanisClearandcommandpropertiesreset()method for terminal restart cleanup2. Wire InputTracker into TerminalPane (
src/components/Terminal/TerminalPane.tsx)commandBufferRefwithInputTrackerinstance (line 162)handleInputto use tracker and handle clear commandsterminalInstanceService.get(id).terminal.clear()handleRestart)Tests
/clear,clear,clstrigger screen clearDocumentation
Technical Specifications
Footprint: Terminal input handling layer
src/services/clearCommandDetection.ts- Enhance return typesrc/components/Terminal/TerminalPane.tsx- Wire up trackerDependencies: Existing xterm.js
terminal.clear()APIDependencies
None - standalone fix
Tasks
InputTracker.process()to returnInputResultobject withisClearandcommandpropertiesInputResultinterface to export in clearCommandDetection.tsreset()method to InputTracker for cleanupInputTrackerinTerminalPane.tsxcommandBufferRefwithinputTrackerRefusing InputTracker instance (line 162)handleInputto process with tracker and handle clear commandsterminal.clear()via terminalInstanceService when clear detectedupdateLastCommandfrom tracker resultinputTrackerRef.current?.reset()inhandleRestartAcceptance Criteria
/clearin Claude Code terminal clears screenclearandclscommands work in interactive terminalsEdge Cases & Risks