chenhg5/cc-connect · error
tmux: invalid prompt_pattern %q: %w
Error message
tmux: invalid prompt_pattern %q: %w
What it means
newTmuxSession compiles the configured prompt_pattern as a regular expression. If regexp.Compile fails, the constructor cancels its context and returns 'tmux: invalid prompt_pattern %q: %w'. This is a fail-fast config validation error for the tmux agent's prompt-detection regex.
Source
Thrown at agent/tmux/session.go:45
cancel context.CancelFunc
alive atomic.Bool
closeOnce sync.Once
mu sync.Mutex
pollCancel context.CancelFunc
baselineCapture string // full captureScrollback output at the time of the last Send()
}
func newTmuxSession(ctx context.Context, target, sessionID, promptPattern string, pollInt time.Duration, stripInputBlock bool, stripPatternStrs []string, workDir string) (*tmuxSession, error) {
sessCtx, cancel := context.WithCancel(ctx)
var pat *regexp.Regexp
if promptPattern != "" {
var err error
pat, err = regexp.Compile(promptPattern)
if err != nil {
cancel()
return nil, fmt.Errorf("tmux: invalid prompt_pattern %q: %w", promptPattern, err)
}
}
var stripPats []*regexp.Regexp
for _, s := range stripPatternStrs {
re, err := regexp.Compile(s)
if err != nil {
cancel()
return nil, fmt.Errorf("tmux: invalid strip_pattern %q: %w", s, err)
}
stripPats = append(stripPats, re)
}
s := &tmuxSession{
target: target,
sessionID: sessionID,
workDir: workDir,
promptPat: pat,View on GitHub (pinned to 4000b2338a)
Solutions
- Read the wrapped error for the exact character offset of the syntax problem
- Test the pattern in Go RE2 (all Go regexp is RE2: no backreferences, no lookaround)
- Fix prompt_pattern in config.toml — simplify or rewrite using RE2-compatible syntax
Example fix
// before (config.toml): lookbehind not supported by RE2 prompt_pattern = "(?<=\$ )$" // after prompt_pattern = "^\$ $"
Defensive patterns
Strategy: validation
Validate before calling
// validate before constructing the session
if _, err := regexp.Compile(cfg.PromptPattern); err != nil {
return fmt.Errorf("bad prompt_pattern: %w", err)
} Try / catch
// Go
sess, err := agent.StartSession(ctx, opts)
if err != nil && strings.Contains(err.Error(), "invalid prompt_pattern") {
slog.Error("fix prompt_pattern in config.toml (RE2 syntax)", "err", err)
} Prevention
- Write tmux patterns in Go RE2 syntax only (no lookaround/backreferences)
- Validate all regex config fields at startup with a config lint
- Test patterns in a scratch Go program or regex101 with the Golang flavor before committing them to config
When it happens
Trigger: Starting a tmux agent session (StartSession) with a prompt_pattern option that is not a valid RE2 expression — e.g. unbalanced parentheses, invalid escape like '\d' with a typo, or a trailing operator like 'a+'.*','+a'.
Common situations: User copies a PCRE-only pattern (lookbehind/lookahead, \d in wrong context) into config.toml; hand-edited regex with a missing bracket; pattern written for grep -P syntax rather than Go RE2.
Related errors
- tmux: invalid strip_pattern %q: %w
- tmux: 'session' option is required (name of the tmux session
- tmux: session %q does not exist and auto_create is disabled
- tmux: create session %q: %w
- cron project not found
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/a10df623f7b2b103.
Report an issue: GitHub.