Skip to content

feat(v3.2.31): Watch-ClaudeLog 起動時セッション検出 + cron-launcher tmux -e 修正 (Issue #185 + #186) - #187

Merged
Kensan196948G merged 2 commits into
mainfrom
fix/issue-185-watch-log-detect-running-session
Apr 18, 2026
Merged

Kensan196948G merged 2 commits into
mainfrom
fix/issue-185-watch-log-detect-running-session

Conversation

@Kensan196948G

@Kensan196948G Kensan196948G commented Apr 18, 2026 •

Copy link
Copy Markdown
Owner

変更内容

Issue #185: Watch-ClaudeLog.ps1 — 起動時セッション検出漏れ修正

  • 起動時に最新ログのタイムスタンプが15分以内であれば $knownLog = '' にリセット
  • 次のポーリングループで「新規ログ」として検出 → 即 tail -F 開始
  • try/catch の代わりに [datetime]::TryParseExact を使用(PSAvoidUsingEmptyCatchBlock 警告を回避)

Issue #186: cron-launcher.sh — tmux env var 継承バグ修正

  • tmux new-session -e KEY=VALUE で env var を明示渡し(tmux サーバーのグローバル環境に依存しない)
  • PROMPT_ARG をサイドカーファイル (.prompt) に書き出し(大容量引数 + tmux 環境サイズ制限を回避)
  • wrapper.sh がサイドカーファイルから _prompt_content を読み込むように変更
  • finalize() トラップで .prompt ファイルも削除
  • サーバー /home/kensan/.claudeos/cron-launcher.sh に反映済み(12:00 cron 発火から有効)

テスト結果

  • Watch-ClaudeLog.ps1: 本番サーバー (192.168.0.185) で監視画面動作確認済み
  • cron-launcher.sh: サーバーに scp で反映済み、構文確認済み
  • 12:00 (JST) の ServiceHub-Construction-Platform cron 発火で動作を最終確認予定

影響範囲

  • scripts/tools/Watch-ClaudeLog.ps1 — 起動時の検出ロジック変更
  • Claude/templates/linux/cron-launcher.sh — tmux 起動方法変更(env var 渡し方式)
  • Linux サーバー側の実行ファイル (/home/kensan/.claudeos/cron-launcher.sh) も更新済み

残課題

なし

Summary by CodeRabbit

バージョン v3.2.31 リリースノート

  • バグ修正

    • ログ監視の起動時セッション検出を改善し、最近のログが自動的に監視される問題を修正
  • 改善

    • プロンプトファイルの処理方法を最適化
    • 環境変数の伝播メカニズムを強化
    • システムの初期化および終了処理の信頼性を向上

…(Issue #185 + #186)

- Watch-ClaudeLog.ps1: 起動時に15分以内のログを新規扱いにして即監視開始(待機中のまま残る問題解消)
- cron-launcher.sh: tmux new-session -e で env var を明示渡し(サーバーグローバル環境依存バグ解消)
- cron-launcher.sh: PROMPT_ARG をサイドカーファイル (.prompt) に書き出し(大容量引数 + 継承問題を回避)
- サーバー /home/kensan/.claudeos/cron-launcher.sh に反映済み(12:00 cron 発火から有効)
- ClaudeOS v3.2.31

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings April 18, 2026 02:37
@coderabbitai

coderabbitai Bot commented Apr 18, 2026 •

Copy link
Copy Markdown

Warning

Rate limit exceeded

@Kensan196948G has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 0 minutes and 24 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 0 minutes and 24 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 70d1543b-f575-4e16-8cd8-7acb01b2bcd8

📥 Commits

Reviewing files that changed from the base of the PR and between ca66e7c and 0718b26.

📒 Files selected for processing (2)
  • CHANGELOG.md
  • README.md
📝 Walkthrough

Walkthrough

ClaudeOS のバージョンを v3.2.31 に更新し、プロンプト処理の仕組みをシェル変数から外部ファイルベースに変更。Tmux 環境変数の伝播方式を、エクスポート変数から明示的な -e オプション割り当てに改更。Watch-ClaudeLog の起動ロジックを、15分以内の新規ログを検出して即座にテール監視を開始するように拡張。

Changes

Cohort / File(s) Summary
プロンプト・Tmux環境伝播の再構築
Claude/templates/linux/cron-launcher.sh
プロンプトを親スクリプトから外部ファイル(${CLAUDE_WRAPPER%.sh}.prompt)に書き込み、ラッパーに経由。_CLAUDEOS_PROMPT_ARG 依存を廃止し、ファイルから読み込む _CLAUDEOS_PROMPT_FILE ベースに変更。Tmux 環境変数伝播を new-session -e 明示割り当てに統一。同期トークン(_CLAUDEOS_TMUX_DONE)の親スクリプトエクスポートを廃止し、_TMUX_DONE への変更。バージョン更新(v3.2.16 → v3.2.31)。
バージョン履歴追加
TASKS.md
v3.2.31 の完了項目「Watch-ClaudeLog 起動時セッション検出修正」を版履歴に追加。
起動時ログ検出ロジック追加
scripts/tools/Watch-ClaudeLog.ps1
最新クロンログ取得後、ファイル名パターン(cron-YYYYMMDD-HHMMSS.log)と15分以内の タイムスタンプを検出し、条件合致時に $knownLog をクリアして即座なテール監視開始を実現。バージョン更新(v3.2.16 → v3.2.31)。

Sequence Diagram(s)

sequenceDiagram
    participant Parent as Parent Script
    participant Filesystem as File System
    participant Tmux as Tmux Session
    participant Wrapper as Wrapper Script
    participant Claude as Claude CLI

    Parent->>Filesystem: Write START_PROMPT.md to<br/>.prompt file
    Parent->>Tmux: new-session -e<br/>_CLAUDEOS_PROMPT_FILE=path<br/>_CLAUDEOS_DURATION_SEC=<br/>_CLAUDEOS_EXIT_FILE=<br/>_CLAUDEOS_TMUX_DONE=
    Tmux->>Wrapper: Execute wrapper with env
    Wrapper->>Filesystem: Read _CLAUDEOS_PROMPT_FILE
    Filesystem-->>Wrapper: Prompt content
    Wrapper->>Claude: claude --dangerously-skip-permissions<br/>(with loaded prompt)
    Claude-->>Wrapper: Response
    Wrapper->>Tmux: wait-for _TMUX_DONE
    Parent->>Filesystem: Delete .prompt file<br/>(finalize)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related issues

Possibly related PRs

Poem

🐰✨
プロンプトファイルに思いを込めて
Tmux の環境で運ぶ新しき道
15分の中で目覚める検知
ラッパーとクローンの調和が生まれ
v3.2.31 の春、ここに開く 🌱

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed PR タイトルは v3.2.31 バージョンアップと Issue #185・#186 の 2 つの主要な修正内容(Watch-ClaudeLog の起動時セッション検出と cron-launcher の tmux 環境変数渡し方式改善)を正確に反映しており、実際の変更内容と完全に一致している。
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/issue-185-watch-log-detect-running-session

Comment @coderabbitai help to get the list of available commands and usage tips.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR updates ClaudeOS v3.2.31 tooling to improve (1) Windows-side log watcher behavior when a cron session is already running at startup and (2) Linux cron launcher reliability when invoked from inside an existing tmux server (env inheritance issue), plus a TASKS.md entry update.

Changes:

  • Watch-ClaudeLog.ps1: Treats a “recent” (≤15 min) cron log as “new” on startup so monitoring begins immediately.
  • cron-launcher.sh: Writes PROMPT_ARG to a sidecar .prompt file and passes required runtime variables into tmux via new-session -e ...; cleans up the prompt file on exit.
  • TASKS.md: Adds a v3.2.31 DONE entry (and additional blank lines).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
scripts/tools/Watch-ClaudeLog.ps1 Adds startup logic to immediately detect and follow an already-running cron session log.
Claude/templates/linux/cron-launcher.sh Fixes tmux env inheritance by explicitly passing env vars and moving prompt content to a sidecar file.
TASKS.md Records completion of Issues #185/#186 work (plus whitespace changes).

# 起動時に15分以内のログがある場合は実行中と見なして即監視
if ($knownLog -match 'cron-(\d{8}-\d{6})\.log$') {
$logTime = [datetime]::MinValue
$parsed = [datetime]::TryParseExact($Matches[1], 'yyyyMMdd-HHmmss', $null,
Comment on lines +172 to +177
tmux new-session -d -s "$TMUX_SESSION" -x 220 -y 50 \
-e "_CLAUDEOS_DURATION_SEC=$DURATION_SEC" \
-e "_CLAUDEOS_EXIT_FILE=$CLAUDE_EXIT_FILE" \
-e "_CLAUDEOS_TMUX_DONE=$_TMUX_DONE" \
-e "_CLAUDEOS_PROMPT_FILE=$PROMPT_FILE" \
"$CLAUDE_WRAPPER"
Comment thread TASKS.md
Comment on lines +105 to +110






@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@Claude/templates/linux/cron-launcher.sh`:
- Around line 153-157: The current code reads the whole prompt into
_prompt_content and passes it as a single argv to claude (variables:
_prompt_file, _prompt_content, the timeout --foreground ... claude invocation),
which still hits system ARG_MAX; change the invocation to stream the prompt via
stdin instead of building _prompt_content: read/verify _prompt_file exists and
is non-empty, then pipe its contents into timeout --foreground
"${_CLAUDEOS_DURATION_SEC}s" claude -p --dangerously-skip-permissions (capture
exit status into claude_exit as before) and remove the direct use of
_prompt_content so large prompt files bypass argv length limits.

In `@scripts/tools/Watch-ClaudeLog.ps1`:
- Around line 185-193: The current 15-minute check compares the parsed timestamp
from the log filename (via $Matches) against the local Get-Date which can be
wrong across timezones; instead retrieve the file's modification time (e.g.,
using Get-Item/Get-ChildItem and LastWriteTimeUtc or LastWriteTime converted to
UTC) and compare epoch/UTC times to Get-Date.ToUniversalTime() so the logic in
the block that inspects $knownLog (the regex match 'cron-(\d{8}-\d{6})\.log$'
and variables $Matches, $logTime, $parsed) becomes timezone-independent: locate
the code that sets $logTime/$parsed and replace the filename-based local-time
comparison with a file-based UTC mtime comparison and keep the original behavior
of clearing $knownLog when the file mtime is within 15 minutes.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c0cb0ec8-5a87-4896-b09e-beda909f61bd

📥 Commits

Reviewing files that changed from the base of the PR and between 56db989 and ca66e7c.

📒 Files selected for processing (3)
  • Claude/templates/linux/cron-launcher.sh
  • TASKS.md
  • scripts/tools/Watch-ClaudeLog.ps1
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Agent
  • GitHub Check: test-and-validate
  • GitHub Check: PSScriptAnalyzer
🧰 Additional context used
📓 Path-based instructions (1)
{**/.github/workflows/*.{yml,yaml},**/ci.{yml,yaml},**/*.sh,**/.gitlab-ci.yml,.circleci/**/*.yml}

📄 CodeRabbit inference engine (AGENTS.md)

CI failures must always be treated as failures; success faking (e.g., || true) is prohibited

Files:

  • Claude/templates/linux/cron-launcher.sh
🔇 Additional comments (1)
Claude/templates/linux/cron-launcher.sh (1)

172-177: tmux new-session -e での明示 env 渡しは良い変更です。

tmux サーバーのグローバル環境依存を減らせており、再現性・可搬性の改善に寄与しています。

Comment on lines +153 to 157
_prompt_file="${_CLAUDEOS_PROMPT_FILE:-}"
if [[ -f "$_prompt_file" ]] && [[ -s "$_prompt_file" ]]; then
_prompt_content="$(cat "$_prompt_file")"
timeout --foreground "${_CLAUDEOS_DURATION_SEC}s" claude --dangerously-skip-permissions "$_prompt_content" || claude_exit=$?
else

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🌐 Web query:

Claude Code CLI の最新公式ドキュメントで、claude --dangerously-skip-permissionsに対してプロンプトを argv ではなく「標準入力」または「ファイル」から渡す方法(例: --prompt-file,@file, stdin)がサポートされているか確認してください。

💡 Result:

Claude Code CLIの最新公式ドキュメント(https://code.claude.com/docs/en/cli-referenceなど)では、claude --dangerously-skip-permissionsに対して、プロンプトをargv(コマンドライン引数)ではなく標準入力(stdin)やファイル(--prompt-file, @fileなど)から渡す専用のオプション(例: --prompt-fileや@file)は明示的にリストされていません。 ただし、-p(printモード、非インタラクティブ)を使用する場合、stdinからの入力がサポートされており、例としてcat file | claude -p "query"が公式ドキュメントで示されています。この場合、--dangerously-skip-permissionsを組み合わせることが可能で、cat prompt.txt | claude -p --dangerously-skip-permissions "追加のクエリ"のようにstdinでプロンプト部分を渡せます。argvの"query"がstdinの内容に置き換わるかは文脈からstdinがコンテキストとして追加される形です。 @fileのようなファイル指定オプションや--prompt-fileはflagsリストに存在せず、サポートされていないと判断されます。システムプロンプト用には--system-prompt-fileがありますが、ユーザープロンプト用ではありません。

Citations:


大容量プロンプト対策が未完了です(argv へ直接渡すことによる引数長上限の制約が残ります)。

Line 155-157 で .prompt ファイルの内容全体を _prompt_content に読み込み、その後 claude --dangerously-skip-permissions "$_prompt_content" として単一の引数に渡しているため、システムの引数長上限に依存する制約が残ります。

公式ドキュメント確認により、--prompt-file や @file のような専用オプションは現在サポートされていませんが、標準入力(stdin)を経由する方法が利用可能です。以下の形式でプロンプトをファイルから読み込むことで、引数長の制限を回避できます:

cat "$_prompt_file" | timeout --foreground "${_CLAUDEOS_DURATION_SEC}s" claude -p --dangerously-skip-permissions

現在の実装を stdin ベースに変更することで、Issue #186 の「大容量引数対策」に対応してください。

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@Claude/templates/linux/cron-launcher.sh` around lines 153 - 157, The current
code reads the whole prompt into _prompt_content and passes it as a single argv
to claude (variables: _prompt_file, _prompt_content, the timeout --foreground
... claude invocation), which still hits system ARG_MAX; change the invocation
to stream the prompt via stdin instead of building _prompt_content: read/verify
_prompt_file exists and is non-empty, then pipe its contents into timeout
--foreground "${_CLAUDEOS_DURATION_SEC}s" claude -p
--dangerously-skip-permissions (capture exit status into claude_exit as before)
and remove the direct use of _prompt_content so large prompt files bypass argv
length limits.

Comment on lines +185 to +193
# 起動時に15分以内のログがある場合は実行中と見なして即監視
if ($knownLog -match 'cron-(\d{8}-\d{6})\.log$') {
$logTime = [datetime]::MinValue
$parsed = [datetime]::TryParseExact($Matches[1], 'yyyyMMdd-HHmmss', $null,
[System.Globalization.DateTimeStyles]::None, [ref]$logTime)
if ($parsed -and ((Get-Date) - $logTime -lt [timespan]::FromMinutes(15))) {
$knownLog = '' # 新規扱いにして直後のループで検出させる
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

# First, let's examine the PowerShell script to see the actual code at lines 185-193
cat -n scripts/tools/Watch-ClaudeLog.ps1 | sed -n '180,200p'

Repository: Kensan196948G/ClaudeCode-StartUpTools-New

Length of output: 873


🏁 Script executed:

# Let's also check the Linux side to see how timestamps are generated
cat -n Claude/templates/linux/cron-launcher.sh | head -60

Repository: Kensan196948G/ClaudeCode-StartUpTools-New

Length of output: 2299


🏁 Script executed:

# Look for SSH-related variables and usage patterns in the PowerShell script
rg -n 'SshTarget|SshUser|ssh ' scripts/tools/Watch-ClaudeLog.ps1 | head -40

Repository: Kensan196948G/ClaudeCode-StartUpTools-New

Length of output: 454


🏁 Script executed:

# Check the beginning of the file to understand SSH setup
head -100 scripts/tools/Watch-ClaudeLog.ps1 | tail -80

Repository: Kensan196948G/ClaudeCode-StartUpTools-New

Length of output: 3218


タイムゾーン差で起動時の「15分以内」判定が誤る可能性があります。

Line 188-190 は監視端末側時刻 (Get-Date) で比較していますが、ログ名タイムスタンプは Linux 側で生成されています(cron-launcher.sh 44行目の date +'%Y%m%d-%H%M%S')。端末とサーバーのタイムゾーンが異なると、起動直後検出の取りこぼし/誤検出が起きます。比較はログのファイルmtimeをepoch秒で取得して行う方が安全です。

🔧 例: タイムゾーン非依存の比較に寄せる差分案
-$knownLog = Get-LatestLog
-# 起動時に15分以内のログがある場合は実行中と見なして即監視
-if ($knownLog -match 'cron-(\d{8}-\d{6})\.log$') {
-    $logTime = [datetime]::MinValue
-    $parsed  = [datetime]::TryParseExact($Matches[1], 'yyyyMMdd-HHmmss', $null,
-        [System.Globalization.DateTimeStyles]::None, [ref]$logTime)
-    if ($parsed -and ((Get-Date) - $logTime -lt [timespan]::FromMinutes(15))) {
-        $knownLog = ''  # 新規扱いにして直後のループで検出させる
-    }
-}
+$knownLog = Get-LatestLog
+# 起動時に15分以内のログがある場合は実行中と見なして即監視(タイムゾーン非依存)
+if ($knownLog) {
+    $latestEpochRaw = ssh $SshTarget "stat -c %Y '$knownLog' 2>/dev/null" 2>$null
+    if ($latestEpochRaw -match '^\d+$') {
+        $ageSec = [DateTimeOffset]::UtcNow.ToUnixTimeSeconds() - [int64]$latestEpochRaw
+        if ($ageSec -ge 0 -and $ageSec -lt 900) {
+            $knownLog = ''  # 新規扱いにして直後のループで検出させる
+        }
+    }
+}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@scripts/tools/Watch-ClaudeLog.ps1` around lines 185 - 193, The current
15-minute check compares the parsed timestamp from the log filename (via
$Matches) against the local Get-Date which can be wrong across timezones;
instead retrieve the file's modification time (e.g., using
Get-Item/Get-ChildItem and LastWriteTimeUtc or LastWriteTime converted to UTC)
and compare epoch/UTC times to Get-Date.ToUniversalTime() so the logic in the
block that inspects $knownLog (the regex match 'cron-(\d{8}-\d{6})\.log$' and
variables $Matches, $logTime, $parsed) becomes timezone-independent: locate the
code that sets $logTime/$parsed and replace the filename-based local-time
comparison with a file-based UTC mtime comparison and keep the original behavior
of clearing $knownLog when the file mtime is within 15 minutes.

- CHANGELOG に v3.2.31 (Watch-ClaudeLog 起動時検出修正 + tmux -e 修正) を追加
- README バージョンを v3.2.27 → v3.2.31、テスト数を 477 → 569 に更新
- CI check-doc-versions PASSED

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.

2 participants