Expand description
Segment trait and layout-intent types. Full contract lives in
docs/specs/segment-system.md; this module carries the subset the
layout engine uses today: visibility, cell width, priority,
separator preference, and theme role.
Modules§
- agent
- Agent segment: renders Claude Code’s active sub-agent name from
agent.name. Hidden when the payload doesn’t carry it. Opt-in: not in the default segment list. - builder
Config→Vec<Box<dyn Segment>>with validation. Hides built-in registry lookup, duplicate handling, unknown-ID warnings, per-segment override merging, and plugin-registry consultation.- context_
bar context_barsegment: visual bar for context-window fill.- context_
window - Context window segment: renders
{used}% · {size}where size is formatted in thousands (200k,1M). Hidden when the payload doesn’t carry context-window data. - cost
- Cost segment: renders session cost in USD. Hidden when the payload doesn’t carry cost metrics (currently always present in Claude Code).
- effort
- Effort segment: renders the current
/effortlevel. Hidden when the payload doesn’t carry it. - extra_
usage extra_usagesegment: monthly overage credits. Auto-hides when the account has not enabled overage (is_enabled = false); surfaces error strings for fetch failures per spec §Render semantics.- extras
- Workspace-level helpers for reading
[segments.<id>]TOML extras. - git_
branch git_branchsegment: branch name + dirty indicator.- model
- Model segment: renders the current model’s display name.
- output_
style - Output style segment: renders Claude Code’s active
output_style.name(e.g. “default”, “concise”, “explanatory”). Hidden when the payload doesn’t carry it. Opt-in: not in the default segment list. - rate_
limit - Rate-limit segment family. Renders the 5-hour and 7-day usage
windows from
ctx.usage()perdocs/specs/rate-limit-segments.md. - session_
duration - Session duration segment: renders elapsed session time in compact
Nh Nm/Nm Ns/Nsform. Thetotal_duration_msfield lives inside the input schema’scostblock, so the segment hides whenevercostis absent. - tokens
- Per-turn token segments:
tokens_input,tokens_output,tokens_cached,tokens_total. Each reads the corresponding field fromctx.status.context_window.current_usage(the per-turn breakdown from the most recent API call, seeTurnUsage). All hide whencurrent_usageis None — either before the first API call in a session, or when the schema didn’t supply the key. - version
- Version segment: renders Claude Code’s CLI version from the
top-level stdin
versionfield. Hidden when the payload doesn’t carry it. Opt-in: not in the default segment list. - vim
- Vim segment: renders Claude Code’s active vim mode (normal, insert,
visual, command, replace). Hidden when the payload doesn’t carry
vim. Opt-in: not in the default segment list. - workspace
- Directory / worktree hybrid segment.
Structs§
- Overridden
Segment - Wraps a
Segmentto override itsdefaults()output while delegatingrenderunchanged. Applying[segments.<id>]overrides without touching the inner segment. - Render
Context - Per-render layout state the engine builds once per call and threads
into every
Segment::render. Distinct fromDataContext, which is the data layer (one instance per process invocation, shared across segments).RenderContextis the layout layer: terminal width today, room for line index / capability / neighbor info as dynamic-segment work lands. - Rendered
Segment - Output of a successful segment render.
- Segment
Defaults - Layout intent declared by a segment; user config may override each field.
- Segment
Error - Runtime failure from a segment’s
Segment::render. Built-in segments returnOk(...)today; this surface is primarily for plugin-authored segments (rhai script errors, unexpected input, propagated I/O). - Width
Bounds - Width bounds in cells with
min <= maxenforced at construction.
Enums§
- Line
Item - One slot in a line layout: a configured segment or an inline
separator between segments. The builder (
build_segments/build_lines) interleaves separators between adjacent segments from[layout_options].separator; the renderer walks this list directly. Seedocs/specs/segment-system.md§Data model. - Powerline
Width - Cell-count for the Nerd Font powerline chevron (U+E0B0). Most modern fonts at standard sizes render the chevron as a single cell; some larger sizes / older Nerd Font builds render it as two. The type makes any other value unrepresentable so layout-width math can’t drift into invalid territory.
- Separator
- Separator between adjacent segments. Chosen by the segment to its left; themes and user config can override.
Constants§
- BUILT_
IN_ SEGMENT_ IDS - Every built-in segment id. Used by
PluginRegistryto reject plugins whoseconst IDshadows a built-in. Add new built-ins here AND tobuilt_in_by_id. - DEFAULT_
SEGMENT_ IDS - Default segment order when no config supplies one. No rate-limit
segments are in the default line: a first-run user without any
config shouldn’t trigger a macOS Keychain prompt or a network
request just to render the statusline. Users opt in by listing
the rate-limit segments explicitly in
[line.segments].
Traits§
Functions§
- built_
in_ by_ id - Construct a built-in segment by its config id. Unknown ids return
Noneso config loaders can warn and skip.extrascarries the[segments.<id>]TOML bag; rate-limit segments parse their knobs from it (format,invert,compact,use_days,icon,label,stale_marker,progress_width). Other built-ins currently ignoreextras.
Type Aliases§
- Render
Result - Shorthand for
Segment::render’s return type.