Skip to content

Commit c46f923

Browse files
author
Nick Sullivan
committed
📋 Use timestamped filenames for context handoff to prevent collisions
Multiple handoff commands in quick succession could overwrite the same temp file. Timestamped filenames ensure each session gets a unique file, preventing data loss and improving reliability.
1 parent ac51905 commit c46f923

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

.claude/commands/handoff-context.md

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@ cleanly copied and pasted to continue work in a new session.
1212

1313
1. **Generate the handoff** - Create a complete context handoff following the
1414
XML-structured format
15-
2. **Save to temp file** - Use Write tool to save to `/tmp/context_handoff.md`
16-
3. **Copy to clipboard automatically** - Use `pbcopy < /tmp/context_handoff.md` without
17-
asking
15+
2. **Save to temp file** - Use Write tool to save to a unique timestamped file
16+
3. **Copy to clipboard automatically** - Use pbcopy without asking
1817
4. **Show brief confirmation** - Just `📋 Copied to clipboard`
1918

2019
## Process
@@ -56,15 +55,19 @@ numbers] </work_completed>
5655

5756
**DO NOT ASK** - Just do it:
5857

59-
1. Use **Write tool** to save the handoff content to `/tmp/context_handoff.md`
60-
2. Use **Bash** to copy: `pbcopy < /tmp/context_handoff.md`
61-
3. Confirm: `📋 Copied to clipboard`
58+
1. Generate a unique filename: `/tmp/context_handoff_TIMESTAMP.md` where TIMESTAMP is the current Unix timestamp
59+
2. Use **Write tool** to save the handoff content to that unique filename
60+
3. Use **Bash** to copy the file you just created: `pbcopy < /tmp/context_handoff_TIMESTAMP.md`
61+
4. Confirm: `📋 Copied to clipboard`
62+
63+
**Implementation:** First run `date +%s` to get the timestamp, then use that value in both the Write and Bash commands.
6264

6365
**Why Write tool instead of heredoc?**
6466

6567
- Avoids triggering git hooks (heredoc with `<<` can trigger branch protection)
6668
- Cleaner, no escaping issues
6769
- Faster execution
70+
- Timestamp-based filename prevents collisions between sessions
6871

6972
## Important Guidelines
7073

@@ -87,9 +90,10 @@ numbers] </work_completed>
8790

8891
**For Clipboard Operation:**
8992

90-
1. Use Write tool to save to `/tmp/context_handoff.md` (avoids heredoc hook triggers)
91-
2. Run: `pbcopy < /tmp/context_handoff.md` (single fast command)
92-
3. Show: `📋 Copied to clipboard` (brief confirmation)
93+
1. First run `date +%s` to get current Unix timestamp
94+
2. Use Write tool to save to `/tmp/context_handoff_[timestamp].md`
95+
3. Run: `pbcopy < /tmp/context_handoff_[timestamp].md`
96+
4. Show: `📋 Copied to clipboard` (brief confirmation)
9397

9498
## Example Usage Flow
9599

@@ -98,9 +102,10 @@ User: `/handoff-context`
98102
Assistant immediately:
99103

100104
1. Generates the handoff content
101-
2. Uses Write tool to save to `/tmp/context_handoff.md`
102-
3. Runs `pbcopy < /tmp/context_handoff.md`
103-
4. Shows `📋 Copied to clipboard`
105+
2. Gets timestamp with `date +%s`
106+
3. Uses Write tool to save to `/tmp/context_handoff_[timestamp].md`
107+
4. Runs `pbcopy < /tmp/context_handoff_[timestamp].md`
108+
5. Shows `📋 Copied to clipboard`
104109

105110
**Total time: ~2 seconds**
106111

0 commit comments

Comments
 (0)