Documentation
¶
Index ¶
- func BuildCommand(uuid, mode string, resume bool, overlayPath, envFilePath string) string
- func ClaudeJSONPath() (string, error)
- func EnsureRemoteControlAtStartup(path string) error
- func EnsureTUIFullscreen(path string) error
- func EnsureViewModeFocus(path string) error
- func EnvFilePathIfExists(envFilePath string) string
- func FindClaudeChild(panePID string) string
- func IsClaudeAlive(pid string) (bool, error)
- func OverlayPathIfExists(overlayPath string) string
- func ReadEffortLevel(path string) string
- func SessionExists(uuid string) bool
- func SettingsJSONPath() (string, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildCommand ¶
BuildCommand builds the claude CLI command string. If resume is true, tries --resume first, falls back to --session-id if the session no longer exists. Claude is the pane process — when it exits, the tmux session dies.
If envFilePath is non-empty, it is sourced via `. 'path'` at exec time, BEFORE claude runs. This lets ctm set real shell env vars (e.g. CLAUDE_CODE_NO_FLICKER) that claude reads during early startup, which is too early for settings.json's `env` key to take effect.
If overlayPath is non-empty, it is passed via --settings to layer ctm-only claude customizations (statusline, theme, etc.) on top of the user's global settings without modifying ~/.claude/settings.json. Both the env file check and the overlay check are TOCTOU-safe shell guards — `[ -r path ]` re- evaluates at exec time and falls back gracefully if the file vanished.
NOTE: The || fallback fires on ANY non-zero exit from `claude --resume`, not just "session not found". A crash, auth error, or Ctrl-C will also trigger a fresh session with the same UUID. This is intentional — it's better to recover into a usable state than to leave the user stranded.
func ClaudeJSONPath ¶
ClaudeJSONPath returns the canonical path to Claude Code's per-user config file (~/.claude.json). This file is owned by the Claude Code CLI — ctm only reads it, and writes only via EnsureRemoteControlAtStartup.
func EnsureRemoteControlAtStartup ¶
EnsureRemoteControlAtStartup sets "remoteControlAtStartup": true in ~/.claude.json so Claude Code's Remote Control feature is on by default for any new Claude session — including those spawned by ctm on a freshly- bootstrapped machine.
Semantics (strictly conservative — the file is Claude Code's state, not ours):
- If the file does not exist, do nothing. Never create it.
- If the key is already present (true, false, or JSON null) we treat that as a deliberate user choice and leave it alone. Only an absent key triggers the write.
- Only when the key is absent do we write it true, preserving all other keys via json.RawMessage round-trip (values byte-exact; top-level key order becomes alphabetical — see patchJSONFile).
The key `remoteControlAtStartup` was discovered empirically by toggling "Enable Remote Control for all sessions" in `/config` and diffing the resulting JSON. It is not a documented/stable API; if Claude Code renames it, future runs silently no-op (harmless).
Errors are returned so callers can log; callers in ctm's boot path should swallow — remote-control defaults are convenience, not correctness, and must never block claude launch.
func EnsureTUIFullscreen ¶
EnsureTUIFullscreen pins "tui": "fullscreen" in Claude Code's settings.json when the key is absent OR explicitly set to "default". Any other value is treated as an intentional user choice and left untouched.
Rationale: at the time of writing, Claude Code's "default" renderer IS the fullscreen renderer — `/tui fullscreen` reports "Already using the fullscreen renderer" when the setting is "default". Pinning to "fullscreen" is a forward-looking hedge so new machines keep the fullscreen UI even if Claude Code later redefines what "default" means.
Semantics:
- Missing settings.json → no-op. Never create it.
- Invalid JSON → return error; never clobber the user's file.
- Absent key OR value == "default" → write "fullscreen".
- Any other value (including JSON null, "compact", or a custom mode) is respected as an explicit user choice and left alone.
- Atomic write via temp + rename; preserves original file mode.
Errors are returned so callers can log; ctm's boot path swallows them.
func EnsureViewModeFocus ¶
EnsureViewModeFocus pins "viewMode": "focus" in Claude Code's settings.json when the key is absent OR explicitly set to "default". Any other value ("verbose", or a future mode) is treated as an intentional user choice and left alone.
Context: `viewMode` is the documented startup default for the transcript view (default | verbose | focus). Setting it to "focus" yields the streamlined "last prompt + tool-call summaries + final response" layout that is otherwise toggled at runtime via `/focus`. This pairs with EnsureTUIFullscreen — the focus view only renders under the fullscreen TUI, so pinning both makes the intended mobile-first view the default.
Semantics mirror EnsureTUIFullscreen:
- Missing settings.json → no-op. Never create it.
- Invalid JSON → return error.
- Absent key OR value == "default" → write "focus".
- Any other value is respected as an explicit user choice.
- Atomic write; preserves file mode.
Reference: https://code.claude.com/docs/en/settings (viewMode).
func EnvFilePathIfExists ¶
EnvFilePathIfExists returns envFilePath if the file exists and is readable, otherwise returns empty string. Used to gate env file sourcing.
func FindClaudeChild ¶
FindClaudeChild finds a claude process among children of the given PID by walking /proc/*/status. Pure Go — no pgrep dependency.
For each PID directory under /proc, it reads /proc/<pid>/status and checks the PPid and Name fields. Returns the first PID whose PPid == panePID and Name == "claude", or empty string if none found.
func IsClaudeAlive ¶
IsClaudeAlive checks if a PID exists and is not a zombie.
func OverlayPathIfExists ¶
OverlayPathIfExists returns overlayPath if the file exists and is readable, otherwise returns empty string. Used to gate the --settings flag.
func ReadEffortLevel ¶
ReadEffortLevel returns the current effort level stored under the "effortLevel" key in path (typically ~/.claude/settings.json). Values in the wild: "min" / "low" / "medium" / "high" / "xhigh" / "max".
Returns "" when the file is missing, unreadable, unparseable, the key is absent, or the value is not a string — intentionally silent so callers (the statusline renderer) can display nothing on missing data without a noisy error path.
func SessionExists ¶
SessionExists checks if a Claude session UUID has data in ~/.claude/. It checks ~/.claude/projects/ and ~/.claude/conversations/, returning false (not an error) if neither directory exists.
func SettingsJSONPath ¶
SettingsJSONPath returns the canonical path to Claude Code's user-level settings file (~/.claude/settings.json). Unlike ~/.claude.json (which stores per-user runtime state), this file holds the documented user-overridable configuration.
Types ¶
This section is empty.