11import { useState , useEffect , useRef } from 'react' ;
2- import { Terminal , Cpu , Shield , Zap , Users , Database , FileCode , BookOpen } from 'lucide-react' ;
2+ import { Terminal , Cpu , Shield , Zap , Users , Database , FileCode , BookOpen , Clock , CheckCircle } from 'lucide-react' ;
33import { CodeBlock } from '../components/CodeBlock' ;
44import clsx from 'clsx' ;
55
@@ -13,7 +13,9 @@ const sections = [
1313 { id : 'permission-system' , title : 'Permission System' , icon : Shield } ,
1414 { id : 'hooks' , title : 'Hooks System' , icon : Zap } ,
1515 { id : 'subagents' , title : 'Subagents' , icon : Users } ,
16+ { id : 'background-tasks' , title : 'Background Tasks' , icon : Clock } ,
1617 { id : 'context-compaction' , title : 'Context Compaction' , icon : Database } ,
18+ { id : 'conclusion' , title : 'Conclusion' , icon : CheckCircle } ,
1719] ;
1820
1921// Simple diagram component
@@ -60,9 +62,12 @@ export function LearnPage() {
6062
6163 // Track which section is currently visible using Intersection Observer
6264 useEffect ( ( ) => {
65+ const mainElement = mainRef . current ;
66+ if ( ! mainElement ) return ;
67+
6368 const observerOptions = {
64- root : mainRef . current ,
65- rootMargin : '-20 % 0px -70 % 0px' , // Trigger when section is in upper portion of viewport
69+ root : mainElement ,
70+ rootMargin : '-10 % 0px -60 % 0px' , // Trigger when section is in upper portion of viewport
6671 threshold : 0 ,
6772 } ;
6873
@@ -84,7 +89,35 @@ export function LearnPage() {
8489 }
8590 } ) ;
8691
87- return ( ) => observer . disconnect ( ) ;
92+ // Also handle scroll to bottom case for last sections
93+ const handleScroll = ( ) => {
94+ const { scrollTop, scrollHeight, clientHeight } = mainElement ;
95+ const isNearBottom = scrollTop + clientHeight >= scrollHeight - 150 ;
96+
97+ if ( isNearBottom ) {
98+ // When near bottom, find which section is most visible
99+ const mainRect = mainElement . getBoundingClientRect ( ) ;
100+ const targetY = mainRect . top + mainRect . height * 0.3 ; // Check 30% from top
101+
102+ for ( let i = sections . length - 1 ; i >= 0 ; i -- ) {
103+ const element = document . getElementById ( sections [ i ] . id ) ;
104+ if ( element ) {
105+ const rect = element . getBoundingClientRect ( ) ;
106+ if ( rect . top <= targetY ) {
107+ setActiveSection ( sections [ i ] . id ) ;
108+ break ;
109+ }
110+ }
111+ }
112+ }
113+ } ;
114+
115+ mainElement . addEventListener ( 'scroll' , handleScroll ) ;
116+
117+ return ( ) => {
118+ observer . disconnect ( ) ;
119+ mainElement . removeEventListener ( 'scroll' , handleScroll ) ;
120+ } ;
88121 } , [ ] ) ;
89122
90123 const scrollToSection = ( id : string ) => {
@@ -884,6 +917,111 @@ const continued = await tools.Task({
884917 </ Callout >
885918 </ section >
886919
920+ { /* Background Tasks */ }
921+ < section id = "background-tasks" className = "mb-20" >
922+ < h2 className = "text-3xl font-bold mb-8 flex items-center gap-3 text-[#e6edf3]" >
923+ < Clock size = { 24 } className = "text-indigo-500" />
924+ Background Tasks
925+ </ h2 >
926+
927+ < p className = "text-[#8b949e] leading-relaxed mb-6" >
928+ Claude Code can run long-running operations in the background, allowing you to continue
929+ working while tasks complete. This includes shell commands, subagents, and other async operations.
930+ </ p >
931+
932+ < h3 className = "text-xl font-semibold mt-10 mb-4 text-[#e6edf3]" > Background Shell Commands</ h3 >
933+
934+ < p className = "text-[#8b949e] leading-relaxed mb-6" >
935+ When Claude runs a Bash command with < code className = "bg-[#30363d] px-1.5 py-0.5 rounded text-sm" > run_in_background: true</ code > ,
936+ the command executes asynchronously. Claude can continue working and check on the task later.
937+ </ p >
938+
939+ < CodeBlock
940+ language = "typescript"
941+ code = { `// Running a command in the background
942+ const result = await tools.Bash({
943+ command: "npm run build",
944+ run_in_background: true
945+ });
946+
947+ // Returns immediately with a task ID
948+ {
949+ taskId: "bbc9855",
950+ status: "running"
951+ }
952+
953+ // Later, check on the task
954+ const output = await tools.TaskOutput({
955+ task_id: "bbc9855",
956+ block: false // Don't wait, just check status
957+ });
958+
959+ // Or wait for completion
960+ const finalOutput = await tools.TaskOutput({
961+ task_id: "bbc9855",
962+ block: true,
963+ timeout: 60000 // Wait up to 60 seconds
964+ });` }
965+ />
966+
967+ < h3 className = "text-xl font-semibold mt-10 mb-4 text-[#e6edf3]" > Background Subagents</ h3 >
968+
969+ < p className = "text-[#8b949e] leading-relaxed mb-6" >
970+ Subagents can also run in the background, enabling parallel work streams:
971+ </ p >
972+
973+ < CodeBlock
974+ language = "typescript"
975+ code = { `// Launch multiple agents in parallel
976+ const agent1 = await tools.Task({
977+ subagent_type: 'Explore',
978+ prompt: 'Find all API endpoints',
979+ run_in_background: true
980+ });
981+
982+ const agent2 = await tools.Task({
983+ subagent_type: 'Explore',
984+ prompt: 'Find all database models',
985+ run_in_background: true
986+ });
987+
988+ // Continue with other work...
989+
990+ // Later, collect results
991+ const results1 = await tools.TaskOutput({ task_id: agent1.taskId });
992+ const results2 = await tools.TaskOutput({ task_id: agent2.taskId });` }
993+ />
994+
995+ < h3 className = "text-xl font-semibold mt-10 mb-4 text-[#e6edf3]" > Task Management</ h3 >
996+
997+ < p className = "text-[#8b949e] leading-relaxed mb-6" >
998+ You can manage background tasks using the < code className = "bg-[#30363d] px-1.5 py-0.5 rounded text-sm" > /tasks</ code > command
999+ to see running tasks, or use the < code className = "bg-[#30363d] px-1.5 py-0.5 rounded text-sm" > KillShell</ code > tool
1000+ to terminate a background shell:
1001+ </ p >
1002+
1003+ < CodeBlock
1004+ language = "typescript"
1005+ code = { `// Kill a background shell
1006+ await tools.KillShell({
1007+ shell_id: "bbc9855"
1008+ });
1009+
1010+ // TaskOutput tool parameters
1011+ interface TaskOutputParams {
1012+ task_id: string; // The task ID to check
1013+ block?: boolean; // Wait for completion (default: true)
1014+ timeout?: number; // Max wait time in ms (default: 30000)
1015+ }` }
1016+ />
1017+
1018+ < Callout type = "tip" title = "Parallel Execution" >
1019+ Running tasks in the background is especially useful for long-running operations like
1020+ builds, tests, or comprehensive codebase searches. Claude can work on other things
1021+ while waiting for results.
1022+ </ Callout >
1023+ </ section >
1024+
8871025 { /* Context Compaction */ }
8881026 < section id = "context-compaction" className = "mb-20" >
8891027 < h2 className = "text-3xl font-bold mb-8 flex items-center gap-3 text-[#e6edf3]" >
@@ -1030,7 +1168,7 @@ async function handleUserMessage(message: string) {
10301168 </ section >
10311169
10321170 { /* Conclusion */ }
1033- < section className = "mb-20" >
1171+ < section id = "conclusion" className = "mb-20" >
10341172 < h2 className = "text-3xl font-bold mb-8 text-[#e6edf3]" > Conclusion</ h2 >
10351173
10361174 < p className = "text-[#8b949e] leading-relaxed mb-6" >
0 commit comments