Git Awareness, Diffs & Everyday Operations

In modern software development, coding agents, background formatters, and compilers continuously modify files on disk. Developers spend a significant portion of their time auditing what changed and committing verified edits.

px0 serves as an ultra-fast, zero-overhead review cockpit and day-to-day Git controller. It keeps your workspace in continuous synchronization with your working tree through real-time Server-Sent Events (SSE) streaming and sub-millisecond Git CLI detection, while providing a streamlined sidebar panel for staging, committing, pushing, and pulling without leaving the browser.

Real-Time Git Status Streaming

px0 connects to a lightweight Server-Sent Events stream (/api/stream or /api/git/stream) running on the Go backend. When files are modified, staged, or removed:

  • Automatic Badge Updates: File explorer status badges (M, A, D, U, R) update in place immediately.
  • Dirty Folder Propagation: Collapsed parent directories display dirty indicator dots as soon as a nested descendant changes.
  • Zero Full-Tree Re-indexing: Updates patch existing DOM elements without re-walking directories on disk, preserving your expanded folders and scroll position.
  • Live Gutter Synchronization: Active editor line gutters and diff views refresh instantly without requiring manual page reloads.
Working Tree Event -> Go GitWatcher -> SSE Stream (/api/stream) -> In-Place DOM Patch

Sub-Millisecond Terminal Awareness

When you run Git commands in your terminal (git checkout, git reset, git add, git commit, git restore, git stash), px0 detects the change in sub-milliseconds:

  1. Every terminal Git operation updates Git internal control files (.git/index, .git/HEAD, or .git/packed-refs) via an atomic rename.
  2. px0’s fast-path watcher checks the metadata timestamps of these control files once per second.
  3. Because this check only inspects metadata without scanning repository files, px0 detects CLI branch switches and checkouts instantaneously, even in repositories containing over 100,000 files.

To remove visual noise and focus exclusively on pending edits:

  1. Click the Changes segment in the sidebar header switch.
  2. The tree collapses untouched folders, displaying only files that contain uncommitted modifications, additions, or deletions.
  3. Click Files to return to the full project hierarchy.

Automatic Explorer Fallback

If you discard or commit all changes while viewing the Changes filter, px0 automatically switches back to the standard file explorer mode. You will never be left stranded on an empty tree view when your working copy becomes clean.

Auto-Closing Discarded Diff Tabs

When reviewing code generated by AI agents or git branches, you often keep several modified files open in diff view (Cmd/Ctrl+D).

If you discard changes to a file from your terminal:

git checkout -- src/core/auth.go

px0 detects that src/core/auth.go is now clean and automatically closes its open diff tab. It reconciles tabs in reverse order and maintains your active tab index so the editor does not jump unexpectedly.

Live File Status Badges

Changed files display color-coded status badges in the file tree:

Badge Status Description
M (Yellow) Modified Existing tracked file modified in the working tree.
A (Green) Added New file staged in the Git index.
D (Red) Deleted File removed from the working tree.
U (Cyan) Untracked New file not yet tracked by Git.
R (Purple) Renamed File renamed or moved.

Ancestor Dirty Propagation

When a deeply nested file is modified (for example src/api/v2/auth/handler.go), every parent directory node (src/, api/, v2/, auth/) automatically displays a dirty dot marker. This ensures modifications are instantly visible even when directory branches are collapsed.

Toggling Diff View (Ctrl+D or Cmd+D)

Open any modified file and press:

Ctrl+D    (or Cmd+D on macOS)

This toggles the active editor between standard code view and the interactive Diff Viewer against HEAD.

Split vs Unified Diffs

  • Split View (Side-by-Side): Displays original HEAD content on the left and modified working tree content on the right, pairing replacement blocks side by side.
  • Unified View (Inline): Displays changes sequentially with green additions (+) and red deletions (-).
  • Clean Hunk Headers: Diffs feature clean hunk boundaries without distracting metadata.
  • Persistent Preferences: Use the toggle in the editor toolbar to switch between Split and Unified modes. px0 stores your layout preference in localStorage.

Syntax-Highlighted Diffs (Powered by Chroma)

Diff code lines feature server-side syntax highlighting powered by Chroma:

  • Language Token Preservation: Keywords, function signatures, types, comments, and strings retain full theme token colors across both split and unified views.
  • Diff Contrast: Subtle green (--gi-bg) and red (--gd-bg) background tinting highlights additions and deletions while keeping syntax colors sharp and legible.
  • Zero Client Overhead: Highlighting is executed during server-side hunk parsing and delivered via /api/diff, avoiding heavy client-side tokenizers.

Intra-Line Character Highlighting & Insertion Carets

When reviewing modified lines, px0 computes exact token- and character-level differences using a refined Myers diff algorithm:

  • Sub-Character Refinement: Highlights precisely which characters, arguments, or variable names changed within an altered line, rather than forcing you to eyeball differences across entire lines.
  • Insertion Carets: Unmodified counterpart lines display subtle insertion caret indicators showing exactly where new tokens were introduced.
  • Theme Integration: Character highlight backgrounds respect your active syntax theme, using calibrated opacity levels that preserve syntax token readability across both Split and Unified diff modes.

Single-Hunk Actions: Stage, Unstage & Discard

Starting in version 0.1.20, px0 supports granular hunk-level staging directly inside the visual diff viewer (/api/git/hunk), available in both Split and Unified modes:

  • Stage Hunk: Stage only the selected hunk to the Git index (git apply --cached --unidiff-zero -). This lets you craft focused commits without staging entire files or dropping to a terminal patch session.
  • Unstage Hunk: Remove an individual staged hunk from the Git index while keeping your working tree edits intact (git apply --reverse --cached --unidiff-zero -).
  • Discard Hunk: Immediately revert changes within an isolated hunk back to HEAD (git apply --reverse --unidiff-zero -), discarding unwanted edits with 1 click.
  • Context Line Expansion: Expand surrounding lines above or below diff hunks to verify enclosing functions, loops, or scope before deciding whether to stage or discard.

Safe Repositories & Unborn HEAD Handling

px0 includes built-in safeguards when inspecting and operating on Git repositories:

  • Safe Directory Validation: The backend git probe validates repository access and respects git safe.directory rules, preventing unexpected permission errors in multi-user or containerized environments.
  • Unborn HEAD Resilience: When opening newly initialized repositories that have no commits yet (an unborn HEAD), px0 cleanly reads the target branch from .git/HEAD, displays working tree files without failing, and allows staging and initial commits seamlessly.

Selecting, Editing & Starting Threads from Diff Views

You can interact directly with code lines inside both split and unified diffs:

  1. Selection Anchoring: Drag across lines or use keyboard navigation inside the diff viewport. px0 maps diff lines to working tree coordinates (data-l and data-at line anchors).
  2. Start a Thread (Alt+T): Press Alt+T (Option+T on macOS) to open a multi-turn conversation with your agent anchored to those diff lines.
  3. Inline Agent Edits (Alt+E): Press Alt+E to open the comment box and stage an edit instruction for your coding harness.
  4. Live Reload: When the harness completes writing, px0 reloads the file while maintaining your diff view mode and exact scroll position.

Gutter Diff Markers in Normal View

Even when viewing standard code without full diff mode enabled, the editor line number gutter indicates modifications in real time:

  • Green bar: Added line.
  • Blue bar: Modified line.
  • Red triangle: Deleted line marker positioned where deleted lines originally sat.
  • Thread Icon: Hovering any line number displays a thread icon to start a thread or stage an inline edit.

px0 includes a dedicated Git panel at the base of the left sidebar, providing complete control over everyday Git actions without opening a terminal:

1. Per-File Staging Ticks, Partial Staging Indicators & Stage All

  • Every changed row in the file tree features a stage tick next to its status badge. Clicking it stages or unstages that specific file (git add or git reset).
  • Partial Staging Indicators: Starting in version 0.1.21, px0 detects when a staged file has been modified again in the working tree. Instead of displaying a normal staged checkmark, the stage tick transforms into a distinct red ! indicator. Clicking the partial tick immediately stages the subsequent modifications and restores the staged checkmark.
  • Click Stage All in the Git panel to stage every modified and untracked file at once.
  • The panel displays live counts: X staged / Y changed.

2. Manual Commit & Commit with AI

  • Auto-Staging on Commit: If you click Commit or Commit with AI when no files are explicitly staged, px0 automatically stages all modified and untracked files before committing. If the working tree is completely clean, px0 notifies you that there are no changes to commit.
  • Collapsible Monospace Input: The commit message textarea is hidden by default to keep the sidebar compact. Click the toggle link to reveal it for manual typing, or let it auto-expand when generating a message.
  • Standalone AI Generation & Pre-Commit Review: Click Generate to draft a commit message with your configured AI harness (Claude Code, Cursor Agent, Antigravity, or OpenCode) without committing immediately. This lets you review and tweak the text before clicking Commit. AI commit message parsing automatically strips enclosing quotes.
  • 1-Click Commit with AI: Alternatively, click Commit with AI to generate a message and commit changes in a single action.
  • Static Button Labels & State Preservation: Commit button labels remain stable without staged counts, and panel refreshes are prevented from clobbering commit success flashes or in-flight error states.
  • Data-Loss Protection: If a commit fails (for instance due to pre-commit hooks or git conflicts), the generated message remains in the textarea so you never lose your draft.
  • Curated Diff Context: px0 supplies the agent with the list of staged file paths, a diffstat summary, and the staged diff capped at 32 KB while excluding lockfiles and minified assets.
  • Custom Commit Instructions: Set git.commitMessageInstruction in Settings (Cmd+, or Ctrl+,) to enforce custom team guidelines (such as Conventional Commits format, ticket prefixes, or emoji rules).

3. Safe Fast-Forward Pull & AI-Assisted Sync

  • Clicking Pull invokes git merge --ff-only FETCH_HEAD.
  • If your branch can fast-forward cleanly, px0 updates the checkout immediately and diff views refresh in place.
  • Divergence Handling: If your branch has diverged (local unpushed commits exist or the upstream branch was rewritten), px0 refuses to start an unmonitored merge. Instead, the Git panel displays a Can’t fast-forward card with commit counts and options:
    • Rebase with AI: Replays your local commits cleanly on top of the incoming remote branch, directing your harness to resolve conflicts.
    • Merge with AI: Joins the divergent histories using a merge commit resolved by your harness.
    • Dismiss: Cancel the prompt and resolve the divergence manually in your terminal if preferred.
  • In-Panel Error Cards: All Git failures (staging errors, merge conflicts, push rejections, hook failures) are presented inside a notice card at the top of the Git panel rather than fleeting global toasts. The notice persists until dismissed or until the next Git action succeeds.

4. Direct Push

  • Clicking Push uploads committed changes to your configured upstream branch.
  • If no upstream tracking branch is set yet, px0 automatically offers to configure it on the first push (git push -u origin <branch>).

5. Reviewing Unpushed Commits

  • In the Changes view beneath the file tree, px0 lists all local commits ahead of your tracking branch (@{u}..HEAD), labelled with the upstream ref they precede (such as origin/main).
  • Interactive Commit Hover Cards: Hover over any commit in the unpushed list to view its author, full commit message, colored diffstat (+green / -red), and a Copy SHA button.
  • Commit-Scoped Diffs: Click any commit row to expand the files it touched, badged identically to working-tree modifications. Clicking a file opens that commit’s isolated diff directly in the diff viewer, unaffected by subsequent edits.

6. Browsing Recent Commits & File Diff Stepping

  • Expandable Recent Commits List: In addition to unpushed commits, the Git panel provides an expandable list of recent repository commits. Click any commit to view its author, commit date, full message, and list of modified files with A/M/D/R status badges and +/- line counts.
  • Commit-Pinned Diffs: Click any file to view that commit’s diff in an isolated tab pinned to the commit (e.g., @03beaf0).
  • Diff Strip Stepping (‹ / ›): A compact navigation strip positioned above the diff shows the file position within the commit (e.g., 3 / 17). Click ‹ or › to step to neighboring files in place, swapping the tab content without creating tab proliferation.
  • Merge Commit Filtering: Merge commits are parsed against their first parent using accelerated backend diffstat parsing (git show numstat).
  • Paging Support: Large commits display 100 files at a time with a Show 100 more button to preserve UI responsiveness.
  • Keyboard Navigation: Use Up/Down arrow keys to move through commits, Right/Left to expand or collapse files, and Enter to open the first changed file immediately.

7. Throttled Status Refresh & Flicker-Free Tabs

  • Background git status syncs are throttled with an adaptive cooldown window and deduplication to avoid eating CPU during rapid disk operations.
  • Open tabs apply an onlyIfChanged guard during background synchronizations: untouched files are never repainted, eliminating cursor jumps or visual tab flickering.

Tab Context Menu & Batch Closing

Managing many open diffs and files is simplified with the tab context menu:

  • Right-click any tab in the tab bar to access Close, Close Others, Close to the Right, Close to the Left, or Close All.
  • Actions without matching tabs are automatically disabled.
  • Closing tabs in bulk triggers batched backend cache evictions (Promise.allSettled) to keep memory minimal.

File Tree Context Menu

Right-click any folder or file row in the explorer (or click the three-dots action button) to:

  • Copy Relative Path: Copies the project-relative path (e.g. src/internal/diff.go).
  • Copy File Name / Folder Name: Copies just the filename or directory name.
  • Copy Absolute Path: Copies the full filesystem path on the host machine.

GitHub Pull Request Review

In addition to local repository operations, px0 features native GitHub pull request reviews. By passing any PR URL directly to the CLI (px0 https://github.com/owner/repo/pull/123), you can inspect merge-base diffs, draft inline line comments, run Batch Apply with local AI harnesses, submit reviews, and push commits straight back to the PR’s head branch.

For full details, see the GitHub Pull Request Review Guide.

Battery and Focus Awareness

To conserve laptop battery and CPU cycles:

  • Background Pause: When the browser tab is hidden (document.visibilityState === 'hidden'), px0 disconnects the SSE stream. The backend detects zero active listeners and pauses background worktree polling completely.
  • Instant Focus Wakeup: When you switch back to px0, the client reconnects and immediately dispatches a request to /api/git/refresh to catch any changes made while you were working in another window.
  • Manual Shortcut: You can also force a complete refresh at any time using Mod+Shift+R.