Skip to content

Conversation

@malhashemi
Copy link
Contributor

Summary

Adds the ability to reload themes without restarting opencode. Provides multiple reload triggers to support different workflows:

Trigger Use Case
/reload-theme command Manual reload when needed
File watchers Auto-reload on config/theme file edits
Window resize Re-detect terminal colors for "system" theme
SIGUSR1/SIGUSR2 Integration point for external automation

Also makes "system" theme background transparent to support terminal opacity.

Changes

 theme.tsx        | +178  Core: reloadTheme(), file watchers, signal handlers
 app.tsx          | -66/+9  Moved getTerminalBackgroundColor, added command
 autocomplete.tsx | +5     Added /reload-theme slash command

Architecture

flowchart LR
    subgraph Triggers
        A[Command]
        B[File change]
        C[Resize]
        D[Signal]
    end

    A & B & C & D --> E[reloadTheme]
    E --> F[Re-query colors]
    F --> G[Update store]
    G --> H[UI re-renders]
Loading

Key Decisions

Why move getTerminalBackgroundColor to theme.tsx?
Needed by both initial detection (app.tsx) and reload (theme.tsx). Moving it eliminates duplication.

Why fs.watch() instead of @parcel/watcher?
Simpler API, no extra dependencies, sufficient for watching 2 files.

Why transparent background for "system" theme?
Allows terminal opacity/blur to show through while keeping panel/menu backgrounds solid.

Why SIGWINCH handler?
Event-driven color re-detection without polling. Only active for "system" theme.

Testing

# Command
/reload-theme

# File watcher
echo '{"theme":"dracula"}' > ~/.config/opencode/opencode.json

# Signal (Unix)
kill -USR1 $(pgrep opencode)

# Resize (system theme)
# Change terminal colors, then resize window

Checklist

  • Commands work (palette + slash)
  • File watchers trigger reload
  • Signal handlers work (Unix)
  • Proper cleanup on unmount
  • TypeScript passes
  • Follows AGENTS.md style

Fixes #815

@arthur404dev
Copy link

Is this feature still being worked on? Hot reloading the theme would be a really nice functionality for theme switching!

@malhashemi malhashemi force-pushed the feature/theme-hot-reload branch from 653a64b to 6216894 Compare December 18, 2025 22:49
@malhashemi
Copy link
Contributor Author

@rekram1-node would you please review this PR and let me know if you have any changes.

Comment on lines +332 to +335
{
display: "/reload-theme",
description: "reload theme from config",
onSelect: () => command.trigger("theme.reload"),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of slash command can we do command panel?

Like reload themes or something?

Also you are using a watcher is it possible to 'hot reload' them since you are filewatching?

@rekram1-node
Copy link
Collaborator

/review

@rekram1-node
Copy link
Collaborator

rekram1-node commented Dec 21, 2025

If im not looking at something that u need, feel free to dm on discord or x

I get like 200 github notifications a day so Im doing my best to go through them but stuff will always sneak through

@github-actions
Copy link
Contributor

lgtm

@malhashemi malhashemi force-pushed the feature/theme-hot-reload branch from ddd6482 to 2c96b0c Compare December 22, 2025 02:28
- Add /reload-theme command for manual theme reloading
- Add file watchers for config and theme file changes
- Add SIGWINCH handler to re-query terminal colors on resize
- Add SIGUSR1/SIGUSR2 signal handlers for external automation
- Make system theme background transparent for terminal opacity
- Move getTerminalBackgroundColor to theme context

Fixes anomalyco#815
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Ask] Hot reload or add keymap to reload the theme

3 participants